moved blog over to BlogPostLink data type to fix error 500 on page refresh

This commit is contained in:
2026-01-31 16:35:17 +01:00
parent 06b4d9c318
commit 6c8d0aae08
5 changed files with 30 additions and 22 deletions

View File

@@ -2,17 +2,17 @@
import Banner2 from "$lib/banner2.svelte";
import Content from "$lib/viewport/content.svelte";
import Gallery, { type GalleryEntry } from "$lib/lists/gallery.svelte";
import { posts, type BlogPostDetails } from "./posts";
import { posts, type BlogPostLink } from "./posts";
let entries: GalleryEntry[] = posts.entries().map(mapEntries).toArray();
let entries: GalleryEntry[] = posts.map(mapEntries);
function mapEntries(m: [String, BlogPostDetails], index: number): GalleryEntry {
function mapEntries(entry: BlogPostLink, index: number): GalleryEntry {
return {
title: `${m[1].title}`,
subtitle: `#${posts.size - index} // ${m[1].date}, ${m[1].time}`,
img: `/blog/${m[0]}/${m[1].banner}`,
link: `/blog/${m[0]}/`,
imgAlt: `Preview image for ${m[1].title}`,
title: `${entry.post.title}`,
subtitle: `#${posts.length - index} // ${entry.post.date}, ${entry.post.time}`,
img: `/blog/${entry.key}/${entry.post.banner}`,
link: `/blog/${entry.key}/`,
imgAlt: `Preview image for ${entry.post.title}`,
};
}
</script>

View File

@@ -1,10 +1,10 @@
import { posts, type BlogPostDetails } from '../../posts';
import { posts, type BlogPostLink } from '../../posts';
export async function load({ params }) {
const post = await import(`../../${params.year}/${params.date}.md`);
const tag: string = `${params.year}/${params.date}`;
const postValues = posts.get(tag);
const postValues = posts.find((v: BlogPostLink) => v.key == tag)?.post;
const content = post.default;
const title: string = postValues?.title ?? "";
const date: string = postValues?.date ?? "";

View File

@@ -15,7 +15,13 @@ export interface BlogPostDetails {
description: string;
}
export const posts = new Map<string, BlogPostDetails>([
export interface BlogPostLink {
key: string;
post: BlogPostDetails;
}
export const posts: BlogPostLink[] = [
// ["2026/0128", {
// date: "2026-01-05",
// time: "13:00",
@@ -23,14 +29,17 @@ export const posts = new Map<string, BlogPostDetails>([
// title: "Portsmouth Postmortem",
// description: "",
// }],
["2026/0129", {
date: "2026-01-29",
time: "16:42",
banner: "girl.webp",
title: "Limitations",
description: "Something about how boundaries can foster creativity.",
}],
]);
{
key: "2026/0129",
post: {
date: "2026-01-29",
time: "16:42",
banner: "girl.webp",
title: "Limitations",
description: "Something about how boundaries can foster creativity.",
}
},
];
// export function getDate(post: BlogPostDetails): string {
// var s = [post.year, post.date.split()].join("");

View File

@@ -1,10 +1,10 @@
<script lang="ts">
import Banner2 from "$lib/banner2.svelte";
import Content from "$lib/viewport/content.svelte";
import { posts, type DevlogPost, type DevlogPostLink } from "./devlog/posts";
import { posts, type DevlogPostLink } from "./devlog/posts";
import Gallery, { type GalleryEntry } from "$lib/lists/gallery.svelte";
let entries = posts.map(mapEntries);
let entries: GalleryEntry[] = posts.map(mapEntries);
function mapEntries(entry: DevlogPostLink, index: number): GalleryEntry {
return {

View File

@@ -4,7 +4,6 @@ export async function load({ params }) {
const post = await import(`../../${params.year}/${params.date}.md`);
const tag: string = `${params.year}/${params.date}`;
// const postValues = posts.get(tag);
const postValues = posts.find((v: DevlogPostLink) => v.key == tag)?.post;
const content = post.default;
const title: string = postValues?.title ?? "";