feat: Blog catalog

This commit is contained in:
Leni Aniva 2024-09-13 23:20:07 -07:00
parent a232ce2361
commit c75c8ca514
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
4 changed files with 48 additions and 3 deletions

View File

@ -5,7 +5,7 @@
let scrollHeight: number = 1; let scrollHeight: number = 1;
let progress: number = 0; let progress: number = 0;
function onScroll(p) { function onScroll(_p) {
if (scrollHeight > 1) { if (scrollHeight > 1) {
progress = Math.min(1, scrollPosition / scrollHeight); progress = Math.min(1, scrollPosition / scrollHeight);
} }

View File

@ -1 +1,24 @@
<h1>Blog root</h1> <script lang="ts">
import type { PageData } from './$types';
export let data: PageData;
const { allPosts } = data;
</script>
<ul>
{#each allPosts as post}
<li>
<div>
<h2 style="display: flex">
<a id="post-title" href={post.path}>{post.meta.title}</a>
</h2>
Published {post.meta.date}
</div>
</li>
{/each}
</ul>
<style>
#post-title {
margin: auto;
}
</style>

22
src/routes/post/+page.ts Normal file
View File

@ -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
};
};

View File

@ -10,7 +10,7 @@
"sourceMap": true, "sourceMap": true,
"strict": true, "strict": true,
"moduleResolution": "bundler", "moduleResolution": "bundler",
"lib": ["es2015"] "lib": ["es2020"]
} }
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias // 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 // except $lib which is handled by https://kit.svelte.dev/docs/configuration#files