feat: frontmatter typing

This commit is contained in:
xieve
2025-09-10 11:59:48 +02:00
parent 7b0dd84a25
commit 972c68bc9d
3 changed files with 17 additions and 3 deletions

6
src/lib/types.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
import type { SvelteComponent } from "svelte";
interface MDsveXComponent extends SvelteComponent {
metadata: Record<string, unknown>;
}

View File

@@ -1,11 +1,12 @@
<script lang="ts"> <script lang="ts">
import type { MDsveXComponent } from '$lib/types';
import type { SvelteComponent } from 'svelte'; import type { SvelteComponent } from 'svelte';
const blog_entries: [string, SvelteComponent][] = Object.entries( const blog_entries: [string, SvelteComponent][] = Object.entries(
import.meta.glob('/src/routes/blogs/**/+page.svx', { eager: true }) import.meta.glob('/src/routes/blogs/**/+page.svx', { eager: true })
).map(([key, value]) => [ ).map(([key, value]) => [
key.split('/src/routes').pop()?.split('/+page.svx').slice(0, -1).pop() as string, key.split('/src/routes').pop()?.split('/+page.svx').slice(0, -1).pop() as string,
value as SvelteComponent value as MDsveXComponent
]); ]);
console.log(blog_entries); console.log(blog_entries);
</script> </script>
@@ -13,5 +14,5 @@
<h1>Welcome to SvelteKit</h1> <h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://svelte.dev/docs/kit">svelte.dev/docs/kit</a> to read the documentation</p> <p>Visit <a href="https://svelte.dev/docs/kit">svelte.dev/docs/kit</a> to read the documentation</p>
{#each blog_entries as [href, page]} {#each blog_entries as [href, page]}
<a {href}>{href}</a><br /> <a {href}>{page.metadata?.title}</a><br />
{/each} {/each}

View File

@@ -1,5 +1,5 @@
--- ---
layout: blog title: "Blog Entry #1"
--- ---
# Title # Title
@@ -9,3 +9,10 @@ layout: blog
1. asd 1. asd
2. asd 2. asd
3. asd 3. asd
```js
{..., lib}:
{
"hello" = "world";
}
```