fix: Pathing issue when using external content

This commit is contained in:
Leni Aniva 2024-09-17 13:38:49 -05:00
parent 7fabd50b3a
commit cd981dd601
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
11 changed files with 88 additions and 12 deletions

21
package-lock.json generated
View File

@ -1146,6 +1146,18 @@
"integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
"dev": true "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": { "node_modules/@types/ungap__structured-clone": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/@types/ungap__structured-clone/-/ungap__structured-clone-1.2.0.tgz", "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": { "node_modules/unist-util-is": {
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz",

4
src/content/archives.md Normal file
View File

@ -0,0 +1,4 @@
# Archives
Archives live here

View File

@ -16,6 +16,8 @@
const { name, Content } = data; const { name, Content } = data;
import metadata from '$content/metadata.json'; import metadata from '$content/metadata.json';
const pathFrontCover = metadata.frontCover;
const pathAvatar = metadata.avatar;
const iconMap: Map<string, string> = { const iconMap: Map<string, string> = {
"bitbucket": "fa-brands fa-bitbucket", "bitbucket": "fa-brands fa-bitbucket",
"discord": "fa-brands fa-discord", "discord": "fa-brands fa-discord",
@ -37,7 +39,7 @@
<div <div
id="background" id="background"
style="opacity: {1 - progress}; background-image: url('{metadata.frontCover}')" style="opacity: {1 - progress}; background-image: url('{pathFrontCover}')"
> >
</div> </div>
@ -78,7 +80,8 @@
</div> </div>
</div> </div>
<div id="avatar"> <div id="avatar">
<img src={metadata.avatar} alt={metadata.name} />
<img id="avatar-img" src={pathAvatar} alt={metadata.name} />
</div> </div>
</div> </div>
</div> </div>
@ -154,7 +157,7 @@
margin-right: auto; margin-right: auto;
@apply ml-auto mr-0; @apply ml-auto mr-0;
} }
#avatar img { #avatar-img {
width: 20vh; width: 20vh;
height: 20vh; height: 20vh;
border-radius: 50%; border-radius: 50%;

View File

@ -1 +0,0 @@
# Archives

View File

@ -0,0 +1,16 @@
<script lang="ts">
import type { PageData } from './$types';
export let data: PageData;
const { Content } = data;
import siteMetadata from '$content/metadata.json';
</script>
<svelte:head>
<title>Archives | {siteMetadata.blogName}</title>
</svelte:head>
<hr />
<article class="prose lg:prose-xl dark:prose-invert p-4">
<Content />
</article>
<hr />

View File

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

View File

@ -19,3 +19,9 @@
{/each} {/each}
</ul> </ul>
<hr class="separator" /> <hr class="separator" />
<style>
#catalog li {
margin-bottom: 10px;
}
</style>

View File

@ -5,17 +5,25 @@ export const load: PageLoad = async ({ params }) => {
const iterablePostFiles = Object.entries(allPostFiles); const iterablePostFiles = Object.entries(allPostFiles);
const allPosts = await Promise.all( const allPosts = await Promise.all(
iterablePostFiles.map(async ([path, resolver]) => { iterablePostFiles.map(async ([pathMarkdown, resolver]) => {
const { metadata } = await 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 { return {
meta: metadata, meta: {
path: postPath ...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 { return {
allPosts allPosts
}; };

View File

@ -3,6 +3,7 @@
export let metadata : { title: string, description: string, tags: [string], date: Date }; export let metadata : { title: string, description: string, tags: [string], date: Date };
export let link: Option<string> = null; export let link: Option<string> = null;
const date = metadata.date.toLocaleDateString();
</script> </script>
<div id="post-heading"> <div id="post-heading">
@ -14,7 +15,7 @@
{/if} {/if}
</h2> </h2>
<div> <div>
<p class="text-gray-500">{metadata.description}</p> <p class="text-gray-500 h-8">{metadata.description}</p>
</div> </div>
<div class="flex flex-row justify-between"> <div class="flex flex-row justify-between">
<p class="text-gray-200 flex justify-center"> <p class="text-gray-200 flex justify-center">
@ -27,7 +28,7 @@
<a href="/">{tag}</a> <a href="/">{tag}</a>
{/each} {/each}
</p> </p>
<p class="text-l text-gray-500">{metadata.date}</p> <p class="text-l text-gray-500">{date}</p>
</div> </div>
</div> </div>

View File

@ -8,7 +8,10 @@ export const load: PageLoad = async ({ params }) => {
const Content = post.default; const Content = post.default;
return { return {
metadata: post.metadata, metadata: {
...post.metadata,
date: new Date(post.metadata.date),
},
Content, Content,
}; };
} }

View File

@ -5,7 +5,7 @@ import { remarkAlert } from 'remark-github-blockquote-alert'
import remarkToc from 'remark-toc' import remarkToc from 'remark-toc'
import rehypeSlug from 'rehype-slug' 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} */ /** @type {import('@sveltejs/kit').Config} */
const config = { const config = {