From cd981dd601c2533851c1d05b70a4cf402f4179ef Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Tue, 17 Sep 2024 13:38:49 -0500 Subject: [PATCH] fix: Pathing issue when using external content --- package-lock.json | 21 +++++++++++++++++++++ src/content/archives.md | 4 ++++ src/routes/+page.svelte | 9 ++++++--- src/routes/archives/+page.md | 1 - src/routes/archives/+page.svelte | 16 ++++++++++++++++ src/routes/archives/+page.ts | 15 +++++++++++++++ src/routes/post/+page.svelte | 6 ++++++ src/routes/post/+page.ts | 16 ++++++++++++---- src/routes/post/Heading.svelte | 5 +++-- src/routes/post/[slug]/+page.ts | 5 ++++- svelte.config.js | 2 +- 11 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 src/content/archives.md delete mode 100644 src/routes/archives/+page.md create mode 100644 src/routes/archives/+page.svelte create mode 100644 src/routes/archives/+page.ts diff --git a/package-lock.json b/package-lock.json index a1df8d5..2c9a717 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1146,6 +1146,18 @@ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true }, + "node_modules/@types/node": { + "version": "22.5.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.5.tgz", + "integrity": "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "undici-types": "~6.19.2" + } + }, "node_modules/@types/ungap__structured-clone": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@types/ungap__structured-clone/-/ungap__structured-clone-1.2.0.tgz", @@ -4623,6 +4635,15 @@ } } }, + "node_modules/undici-types": { + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true + }, "node_modules/unist-util-is": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", diff --git a/src/content/archives.md b/src/content/archives.md new file mode 100644 index 0000000..4fe3b2f --- /dev/null +++ b/src/content/archives.md @@ -0,0 +1,4 @@ +# Archives + +Archives live here + diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 5b7ca7b..791c97b 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -16,6 +16,8 @@ const { name, Content } = data; import metadata from '$content/metadata.json'; + const pathFrontCover = metadata.frontCover; + const pathAvatar = metadata.avatar; const iconMap: Map = { "bitbucket": "fa-brands fa-bitbucket", "discord": "fa-brands fa-discord", @@ -37,7 +39,7 @@
@@ -78,7 +80,8 @@
- {metadata.name} + + {metadata.name}
@@ -154,7 +157,7 @@ margin-right: auto; @apply ml-auto mr-0; } - #avatar img { + #avatar-img { width: 20vh; height: 20vh; border-radius: 50%; diff --git a/src/routes/archives/+page.md b/src/routes/archives/+page.md deleted file mode 100644 index c364256..0000000 --- a/src/routes/archives/+page.md +++ /dev/null @@ -1 +0,0 @@ -# Archives diff --git a/src/routes/archives/+page.svelte b/src/routes/archives/+page.svelte new file mode 100644 index 0000000..8b15211 --- /dev/null +++ b/src/routes/archives/+page.svelte @@ -0,0 +1,16 @@ + + + + Archives | {siteMetadata.blogName} + + +
+
+ +
+
diff --git a/src/routes/archives/+page.ts b/src/routes/archives/+page.ts new file mode 100644 index 0000000..adcf3a6 --- /dev/null +++ b/src/routes/archives/+page.ts @@ -0,0 +1,15 @@ +import { error } from '@sveltejs/kit'; +import type { PageLoad } from './$types'; + +export const load: PageLoad = async ({ params }) => { + const post = await import("$content/archives.md"); + const Content = post.default; + + return { + metadata: { + ...post.metadata, + date: new Date(post.metadata.date), + }, + Content, + }; +} diff --git a/src/routes/post/+page.svelte b/src/routes/post/+page.svelte index 91237c2..f5925fd 100644 --- a/src/routes/post/+page.svelte +++ b/src/routes/post/+page.svelte @@ -19,3 +19,9 @@ {/each}
+ + diff --git a/src/routes/post/+page.ts b/src/routes/post/+page.ts index 7e91566..088d555 100644 --- a/src/routes/post/+page.ts +++ b/src/routes/post/+page.ts @@ -5,17 +5,25 @@ export const load: PageLoad = async ({ params }) => { const iterablePostFiles = Object.entries(allPostFiles); const allPosts = await Promise.all( - iterablePostFiles.map(async ([path, resolver]) => { + iterablePostFiles.map(async ([pathMarkdown, resolver]) => { const { metadata } = await resolver(); - const postPath = path.slice("/src/content/".length, -".md".length); + const pathPost = "post/" + pathMarkdown.slice(pathMarkdown.lastIndexOf("/") + 1, -".md".length); return { - meta: metadata, - path: postPath + meta: { + ...metadata, + date: new Date(metadata.date), + }, + path: pathPost }; }) ); + allPosts.sort((post1, post2) => { + const date1: Date = post1.meta.date; + const date2: Date = post2.meta.date; + return date2.getTime() - date1.getTime(); + }); return { allPosts }; diff --git a/src/routes/post/Heading.svelte b/src/routes/post/Heading.svelte index af47b5c..24f8a96 100644 --- a/src/routes/post/Heading.svelte +++ b/src/routes/post/Heading.svelte @@ -3,6 +3,7 @@ export let metadata : { title: string, description: string, tags: [string], date: Date }; export let link: Option = null; + const date = metadata.date.toLocaleDateString();
@@ -14,7 +15,7 @@ {/if}
-

{metadata.description}

+

{metadata.description}

@@ -27,7 +28,7 @@ {tag} {/each}

-

{metadata.date}

+

{date}

diff --git a/src/routes/post/[slug]/+page.ts b/src/routes/post/[slug]/+page.ts index 228c903..de6d407 100644 --- a/src/routes/post/[slug]/+page.ts +++ b/src/routes/post/[slug]/+page.ts @@ -8,7 +8,10 @@ export const load: PageLoad = async ({ params }) => { const Content = post.default; return { - metadata: post.metadata, + metadata: { + ...post.metadata, + date: new Date(post.metadata.date), + }, Content, }; } diff --git a/svelte.config.js b/svelte.config.js index 475f8e9..ac4c55d 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -5,7 +5,7 @@ import { remarkAlert } from 'remark-github-blockquote-alert' import remarkToc from 'remark-toc' import rehypeSlug from 'rehype-slug' -const contentDir = import.meta.env?.CHRYSOBLOG_CONTENT ?? "src/content"; +const contentDir = process.env?.CHRYSOBLOG_CONTENT ?? "src/content"; /** @type {import('@sveltejs/kit').Config} */ const config = {