🛠️ Initial content-collections config + /docs/* route

This commit is contained in:
pheralb
2025-08-29 00:13:41 +01:00
parent 914ee8224f
commit 62a6dddc34
5 changed files with 88 additions and 5 deletions
+33
View File
@@ -0,0 +1,33 @@
import { z } from "zod";
// Content Collections:
import { compileMarkdown } from "@content-collections/markdown";
import { defineCollection, defineConfig } from "@content-collections/core";
// Shiki:
import rehypeShiki from "@shikijs/rehype/core";
import { shikiHighlighter, rehypeShikiOptions } from "./src/utils/shiki";
const docs = defineCollection({
name: "docs",
directory: "src/docs",
include: "**/*.md",
schema: z.object({
title: z.string(),
description: z.string(),
}),
transform: async (document, context) => {
const highlighter = await shikiHighlighter();
const html = await compileMarkdown(context, document, {
rehypePlugins: [[rehypeShiki, highlighter, rehypeShikiOptions]],
});
return {
...document,
html,
};
},
});
export default defineConfig({
collections: [docs],
});
+33
View File
@@ -0,0 +1,33 @@
<script lang="ts">
import type { PageProps } from "./$types";
import PageCard from "@/components/pageCard.svelte";
import PageHeader from "@/components/pageHeader.svelte";
import Container from "@/components/container.svelte";
import FileText from "@lucide/svelte/icons/file-text";
let { data }: PageProps = $props();
const document = $derived(data.document);
</script>
<svelte:head>
<title>{data.document.title} - Svgl</title>
<meta name="description" content={data.document.description} />
</svelte:head>
<PageCard>
<PageHeader>
<div
class="flex items-center space-x-2 font-medium text-neutral-950 dark:text-neutral-50"
>
<FileText size={18} strokeWidth={1.5} />
<p>
{document.title}
</p>
</div>
</PageHeader>
<Container className="my-6">
<article>{@html document.html}</article>
</Container>
</PageCard>
+14
View File
@@ -0,0 +1,14 @@
import type { PageLoad } from "./$types";
import { error } from "@sveltejs/kit";
import { allDocs } from "content-collections";
export const load: PageLoad = async ({ params }) => {
const document = allDocs.find((doc) => doc._meta.path == params.slug);
if (!document) {
error(404, `Could not find ${params.slug}`);
}
return {
document,
};
};
+2 -2
View File
@@ -1,16 +1,16 @@
import { mdsvex } from "mdsvex";
import adapter from "@sveltejs/adapter-auto";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
/** @type {import('@sveltejs/kit').Config} */
const config = {
extensions: [".svelte", ".svx"],
preprocess: [vitePreprocess(), mdsvex()],
preprocess: [vitePreprocess()],
kit: {
adapter: adapter(),
alias: {
"@/*": "./src/*",
"@/lib/*": "./src/lib/*",
"content-collections": "./.content-collections/generated",
},
},
};
+6 -3
View File
@@ -1,7 +1,10 @@
import tailwindcss from "@tailwindcss/vite";
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";
// Plugins:
import tailwindcss from "@tailwindcss/vite";
import { sveltekit } from "@sveltejs/kit/vite";
import contentCollections from "@content-collections/vite";
export default defineConfig({
plugins: [tailwindcss(), sveltekit()],
plugins: [tailwindcss(), sveltekit(), contentCollections()],
});