diff --git a/package-lock.json b/package-lock.json index 8e6e53f..9adb829 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.36.0", "globals": "^15.0.0", + "mdsvex": "^0.12.3", "prettier": "^3.1.1", "prettier-plugin-svelte": "^3.1.2", "prettier-plugin-tailwindcss": "^0.6.5", @@ -1120,6 +1121,13 @@ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true }, + "node_modules/@types/unist": { + "version": "2.0.11", + "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.11.tgz", + "integrity": "sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==", + "dev": true, + "license": "MIT" + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.5.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.5.0.tgz", @@ -2895,6 +2903,22 @@ "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.30.tgz", "integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==" }, + "node_modules/mdsvex": { + "version": "0.12.3", + "resolved": "https://registry.npmjs.org/mdsvex/-/mdsvex-0.12.3.tgz", + "integrity": "sha512-C/uIJamjNo5PHHnR3JHqsBPoLcfUBpzRmAEB6FLMXI/s7XHOceswjDMKqSPEW2WHmYpKm0taZ3U20GSyhMridA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "^2.0.3", + "prism-svelte": "^0.4.7", + "prismjs": "^1.17.1", + "vfile-message": "^2.0.4" + }, + "peerDependencies": { + "svelte": "^3.56.0 || ^4.0.0 || ^5.0.0-next.120" + } + }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -3592,6 +3616,23 @@ } } }, + "node_modules/prism-svelte": { + "version": "0.4.7", + "resolved": "https://registry.npmjs.org/prism-svelte/-/prism-svelte-0.4.7.tgz", + "integrity": "sha512-yABh19CYbM24V7aS7TuPYRNMqthxwbvx6FF/Rw920YbyBWO3tnyPIqRMgHuSVsLmuHkkBS1Akyof463FVdkeDQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/prismjs": { + "version": "1.29.0", + "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.29.0.tgz", + "integrity": "sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -4409,6 +4450,20 @@ } } }, + "node_modules/unist-util-stringify-position": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-2.0.3.tgz", + "integrity": "sha512-3faScn5I+hy9VleOq/qNbAd6pAx7iH5jYBMS9I1HgQVijz/4mv5Bvw5iw1sC/90CODiKo81G/ps8AJrISn687g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "^2.0.2" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/update-browserslist-db": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.0.tgz", @@ -4453,6 +4508,21 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, + "node_modules/vfile-message": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-2.0.4.tgz", + "integrity": "sha512-DjssxRGkMvifUOJre00juHoP9DPWuzjxKuMDrhNbk2TdaYYBNMStsNhEOt3idrtI12VQYM/1+iM0KOzXi4pxwQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "^2.0.0", + "unist-util-stringify-position": "^2.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/vite": { "version": "5.4.4", "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.4.tgz", diff --git a/package.json b/package.json index bae649e..ad647a4 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.36.0", "globals": "^15.0.0", + "mdsvex": "^0.12.3", "prettier": "^3.1.1", "prettier-plugin-svelte": "^3.1.2", "prettier-plugin-tailwindcss": "^0.6.5", diff --git a/src/content/home.md b/src/content/home.md new file mode 100644 index 0000000..01f12d5 --- /dev/null +++ b/src/content/home.md @@ -0,0 +1,7 @@ +--- +name: Cirno +--- +# Biography + +Strongest of Gensokyo + diff --git a/src/content/post/placeholder1.md b/src/content/post/placeholder1.md new file mode 100644 index 0000000..7521202 --- /dev/null +++ b/src/content/post/placeholder1.md @@ -0,0 +1,7 @@ +--- +title: Placeholder 1 +date: '2024-09-01' +--- +# Placeholder Post 1 + +Here is some placeholder text diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 30e00ad..cdb9d2b 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -10,6 +10,10 @@ progress = Math.min(1, scrollPosition / scrollHeight); } } + + import type { PageData } from './$types'; + export let data: PageData; + const { name, Content } = data;
-

Home Page

-

This is the home page. You have scrolled {scrollPosition} / {scrollHeight}, progress: {progress}

+

{name}

+
- { + const post = await import(`$content/home.md`); + if (!post) throw error(404); + const { name, date } = post.metadata; + const Content = post.default; + + return { + name, + Content, + }; +} diff --git a/src/routes/archives/+page.md b/src/routes/archives/+page.md new file mode 100644 index 0000000..c364256 --- /dev/null +++ b/src/routes/archives/+page.md @@ -0,0 +1 @@ +# Archives diff --git a/src/routes/post/[slug]/+page.server.ts b/src/routes/post/[slug]/+page.server.ts deleted file mode 100644 index 8a9e0c3..0000000 --- a/src/routes/post/[slug]/+page.server.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { error } from '@sveltejs/kit'; -import type { PageServerLoad } from './$types'; - -export const load: PageServerLoad = async ({ params }) => { - const post = params.slug; - - if (!post) throw error(404); - - return { - post - }; -} diff --git a/src/routes/post/[slug]/+page.svelte b/src/routes/post/[slug]/+page.svelte index 78e1150..0f74fc0 100644 --- a/src/routes/post/[slug]/+page.svelte +++ b/src/routes/post/[slug]/+page.svelte @@ -1,6 +1,11 @@ - -

Blog {data.post}

+
+

{title}

+

Published: {date}

+ +
diff --git a/src/routes/post/[slug]/+page.ts b/src/routes/post/[slug]/+page.ts new file mode 100644 index 0000000..e32a93a --- /dev/null +++ b/src/routes/post/[slug]/+page.ts @@ -0,0 +1,20 @@ +import { error } from '@sveltejs/kit'; +import type { PageLoad } from './$types'; + +export const load: PageLoad = async ({ params }) => { + try { + const post = await import(`$content/post/${params.slug}.md`); + if (!post) throw error(404); + const { title, date } = post.metadata; + const Content = post.default; + + return { + Content, + title, + date + }; + } + catch(_e) { + throw error(404) + } +} diff --git a/svelte.config.js b/svelte.config.js index 32f4adb..3049cd9 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,11 +1,16 @@ import adapter from '@sveltejs/adapter-auto'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; +import { mdsvex } from 'mdsvex'; /** @type {import('@sveltejs/kit').Config} */ const config = { // Consult https://kit.svelte.dev/docs/integrations#preprocessors // for more information about preprocessors - preprocess: vitePreprocess(), + preprocess: [ + vitePreprocess(), + mdsvex({ extensions: ['.md'] }) + ], + extensions: [".svelte", ".md"], kit: { // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. @@ -13,7 +18,8 @@ const config = { // See https://kit.svelte.dev/docs/adapters for more information about adapters. adapter: adapter(), alias: { - "@/*": "./path/to/lib/*", + $content: "src/content", + "@/*": "./*", }, } }; diff --git a/tsconfig.json b/tsconfig.json index fc93cbd..a79e924 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,8 @@ "skipLibCheck": true, "sourceMap": true, "strict": true, - "moduleResolution": "bundler" + "moduleResolution": "bundler", + "lib": ["es2015"] } // 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