From 8b533b296cfd97dd6f9d31025437e086028c5b8d Mon Sep 17 00:00:00 2001 From: Sveske_Juice Date: Tue, 20 Feb 2024 00:58:52 +0100 Subject: [PATCH] Global access to post summaries for all posts on site --- jsconfig.json | 3 ++- src/routes/+layout.server.ts | 32 +++++++++++++++++++++++ src/routes/{+layout.js => +layout.ts} | 0 src/routes/+page.svelte | 11 ++++++++ src/routes/post/+page.server.ts | 20 -------------- src/routes/post/+page.svelte | 4 +-- src/routes/post/folder-icons/+page.svelte | 0 src/routes/post/lorem/+page.svelte | 0 svelte.config.js | 2 ++ 9 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 src/routes/+layout.server.ts rename src/routes/{+layout.js => +layout.ts} (100%) delete mode 100644 src/routes/post/+page.server.ts create mode 100644 src/routes/post/folder-icons/+page.svelte create mode 100644 src/routes/post/lorem/+page.svelte diff --git a/jsconfig.json b/jsconfig.json index 81def15..73b46e8 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -9,7 +9,8 @@ "skipLibCheck": true, "sourceMap": true, "strict": true, - "moduleResolution": "bundler" + "moduleResolution": "bundler", + "allowImportingTsExtensions": true } // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias and https://kit.svelte.dev/docs/configuration#files // diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts new file mode 100644 index 0000000..f259a5e --- /dev/null +++ b/src/routes/+layout.server.ts @@ -0,0 +1,32 @@ +/* + * Provides post summaries to all pages. That means every page can access summaries + * for all posts on the website. +*/ + +import { posts } from './post/data.js'; + +// Basically the same as Post but might contain less infomation - save storage +type Summary = { + url : string, + title : string, + description : string, + creation_date : number, + modification_date: number, +}; + +export function load() { + let summaries : Summary[] = []; + + posts.map((post) => { + let summary : Summary = { + url: post.url, + title : post.title, + description : post.description, + creation_date : post.creation_date, + modification_date : post.modification_date + }; + summaries.push(summary); + }); + + return { summaries }; +} diff --git a/src/routes/+layout.js b/src/routes/+layout.ts similarity index 100% rename from src/routes/+layout.js rename to src/routes/+layout.ts diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 2fdf88b..08cce52 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,7 +1,18 @@ + +

The Deprived Devs

+

Recent posts on Deprived.dev

+