Skip to content

Commit

Permalink
feat(blog): generate full post links
Browse files Browse the repository at this point in the history
  • Loading branch information
cor committed Sep 27, 2023
1 parent 244d166 commit 997b6d6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion site/src/routes/blog/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<script lang="ts">
type PostMeta = { metadata: { title: string, date: string, author: string, preview: string }};
const posts: Record<string, PostMeta> = import.meta.globEager('../**/*.md');
const slugRegex = /\/([^/]+)\//;
function extractSlug(path: string): string {
const matches= slugRegex.exec(path)
if (matches === null) {
return '/404';
};
return `/blog/${matches[1]}`;
}
</script>


Expand All @@ -11,7 +20,7 @@
<h1 class="text-3xl sm:text-5xl font-bold mb-0">{metadata.title}</h1>
<div class="font-mono mb-2 mt-1 sm:text-lg">{metadata.date} - <a class="text-accent" href={`https://x.com/${metadata.author}`}>{metadata.author}</a></div>
<p class="sm:text-xl">{metadata.preview}</p>
<a class="block mt-2 font-mono text-lg" href="/blog/the-journey-so-far">READ FULL POST -&gt;</a>
<a class="block mt-2 font-mono text-lg" href={extractSlug(path)}>READ FULL POST -&gt;</a>
</section>
{/each}
</div>
Expand Down

0 comments on commit 997b6d6

Please sign in to comment.