From 110720ea591035dffcc74a2a8086f4f3511b8905 Mon Sep 17 00:00:00 2001 From: Sveske_Juice Date: Mon, 26 Feb 2024 20:06:38 +0100 Subject: [PATCH] Get post data associated with current blog post being read --- src/lib/posts/NewsVerticalCard.svelte | 2 +- src/routes/+layout.server.ts | 15 +++------------ src/routes/+layout.svelte | 6 +++--- src/routes/+page.svelte | 2 +- src/routes/post/+layout.svelte | 13 ++++++++++--- src/routes/post/+layout.ts | 17 +++++++++++++++++ src/routes/post/folder-icons/+page.svelte | 2 ++ src/routes/{post => posts}/+page.svelte | 2 +- src/routes/{post => posts}/posts_data.ts | 0 9 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 src/routes/post/+layout.ts rename src/routes/{post => posts}/+page.svelte (97%) rename src/routes/{post => posts}/posts_data.ts (100%) diff --git a/src/lib/posts/NewsVerticalCard.svelte b/src/lib/posts/NewsVerticalCard.svelte index 1b0e77e..b7e6acf 100644 --- a/src/lib/posts/NewsVerticalCard.svelte +++ b/src/lib/posts/NewsVerticalCard.svelte @@ -13,7 +13,7 @@
- +
{thumbnail_alt}/
diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index d8d824f..f30d800 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -3,25 +3,16 @@ * for all posts on the website. */ -import { posts } from './post/posts_data'; - -// Basically the same as Post but might contain less infomation - save storage -type Summary = { - url : string, - title : string, - summary : string, - creation_date : number, - modification_date: number, -}; +import { type Post, posts } from './posts/posts_data'; export function load() { - let summaries : Summary[] = []; + let summaries : Post[] = []; // Sort by newest news first posts.sort((a, b) => b.creation_date - a.creation_date); posts.map((post) => { - let summary : Summary = { + let summary : Post = { url: post.url, title : post.title, summary : post.summary, diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index bdf3082..2cb234c 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,5 +1,5 @@ + +{#if data} +

{data.post.title}

+{/if} + - - - diff --git a/src/routes/post/+layout.ts b/src/routes/post/+layout.ts new file mode 100644 index 0000000..cb8edfb --- /dev/null +++ b/src/routes/post/+layout.ts @@ -0,0 +1,17 @@ +import { posts, type Post } from '../posts/posts_data'; + +export interface BlogData { + summaries: Post[], + post: Post +} + +export async function load({ url, parent }) : Promise { + const { summaries } = await parent(); + const websiteUrl = url.pathname.split('/'); + const windowUrl = websiteUrl.pop() || websiteUrl.pop(); // Handle trailing / + + return { + summaries: summaries, + post: posts.filter((post) => post.url == windowUrl)[0], + }; +} diff --git a/src/routes/post/folder-icons/+page.svelte b/src/routes/post/folder-icons/+page.svelte index e69de29..4d08b3c 100644 --- a/src/routes/post/folder-icons/+page.svelte +++ b/src/routes/post/folder-icons/+page.svelte @@ -0,0 +1,2 @@ +Lorem ipsum dolor sit amet, officia excepteur ex fugiat reprehenderit enim labore culpa sint ad nisi Lorem pariatur mollit ex esse exercitation amet. Nisi anim cupidatat excepteur officia. Reprehenderit nostrud nostrud ipsum Lorem est aliquip amet voluptate voluptate dolor minim nulla est proident. Nostrud officia pariatur ut officia. Sit irure elit esse ea nulla sunt ex occaecat reprehenderit commodo officia dolor Lorem duis laboris cupidatat officia voluptate. Culpa proident adipisicing id nulla nisi laboris ex in Lorem sunt duis officia eiusmod. Aliqua reprehenderit commodo ex non excepteur duis sunt velit enim. Voluptate laboris sint cupidatat ullamco ut ea consectetur et est culpa et culpa duis. + diff --git a/src/routes/post/+page.svelte b/src/routes/posts/+page.svelte similarity index 97% rename from src/routes/post/+page.svelte rename to src/routes/posts/+page.svelte index 0508ba4..eccaa16 100644 --- a/src/routes/post/+page.svelte +++ b/src/routes/posts/+page.svelte @@ -24,7 +24,7 @@ {/if} {#each matched_posts as summary}