From c75c8ca5145f87663933b77be0289499e8f5f260 Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Fri, 13 Sep 2024 23:20:07 -0700 Subject: [PATCH] feat: Blog catalog --- src/routes/+page.svelte | 2 +- src/routes/post/+page.svelte | 25 ++++++++++++++++++++++++- src/routes/post/+page.ts | 22 ++++++++++++++++++++++ tsconfig.json | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/routes/post/+page.ts diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index cdb9d2b..bbf3df3 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -5,7 +5,7 @@ let scrollHeight: number = 1; let progress: number = 0; - function onScroll(p) { + function onScroll(_p) { if (scrollHeight > 1) { progress = Math.min(1, scrollPosition / scrollHeight); } diff --git a/src/routes/post/+page.svelte b/src/routes/post/+page.svelte index c49f953..8160011 100644 --- a/src/routes/post/+page.svelte +++ b/src/routes/post/+page.svelte @@ -1 +1,24 @@ -

Blog root

+ + + + + diff --git a/src/routes/post/+page.ts b/src/routes/post/+page.ts new file mode 100644 index 0000000..7e91566 --- /dev/null +++ b/src/routes/post/+page.ts @@ -0,0 +1,22 @@ +import type { PageLoad } from './$types'; + +export const load: PageLoad = async ({ params }) => { + const allPostFiles = import.meta.glob('$content/post/*.md'); + const iterablePostFiles = Object.entries(allPostFiles); + + const allPosts = await Promise.all( + iterablePostFiles.map(async ([path, resolver]) => { + const { metadata } = await resolver(); + const postPath = path.slice("/src/content/".length, -".md".length); + + return { + meta: metadata, + path: postPath + }; + }) + ); + + return { + allPosts + }; +}; diff --git a/tsconfig.json b/tsconfig.json index a79e924..7cc0b45 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ "sourceMap": true, "strict": true, "moduleResolution": "bundler", - "lib": ["es2015"] + "lib": ["es2020"] } // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias // except $lib which is handled by https://kit.svelte.dev/docs/configuration#files