feat: add filter to main page

This commit is contained in:
eggy 2022-10-31 14:18:14 -04:00
parent 49b772918b
commit 631416984c
2 changed files with 36 additions and 0 deletions

View File

@ -9,6 +9,14 @@ const docs = await queryContent<BlogParsedContent>("/blog")
.sort({ date: -1 }) .sort({ date: -1 })
.where({ _draft: false }) .where({ _draft: false })
.find(); .find();
const tags = new Set(
docs
.map((p) => p.tags)
.flat()
.filter((p) => !p.includes(" "))
.sort()
);
</script> </script>
<template> <template>
@ -16,6 +24,16 @@ const docs = await queryContent<BlogParsedContent>("/blog")
class="flex flex-col grow prose dark:prose-invert max-w-3xl gap-6 transition" class="flex flex-col grow prose dark:prose-invert max-w-3xl gap-6 transition"
> >
<h1 class="mb-0">Blog</h1> <h1 class="mb-0">Blog</h1>
<div class="m-0">
Filter:
<Tag
:dest="`/tags/blog/${tag}`"
v-for="(tag, index) in tags"
:key="index"
>
{{ tag }}
</Tag>
</div>
<PostPreviewCard <PostPreviewCard
v-for="(post, index) in docs" v-for="(post, index) in docs"
:key="index" :key="index"

View File

@ -9,6 +9,14 @@ const docs = await queryContent<StoryParsedContent>("/stories")
.sort({ date: -1 }) .sort({ date: -1 })
.where({ _draft: false }) .where({ _draft: false })
.find(); .find();
const tags = new Set(
docs
.map((p) => p.tags)
.flat()
.filter((p) => !p.includes(" ")) // do not include AO3-style tags
.sort()
);
</script> </script>
<template> <template>
@ -16,6 +24,16 @@ const docs = await queryContent<StoryParsedContent>("/stories")
class="flex flex-col grow prose dark:prose-invert max-w-3xl gap-6 transition" class="flex flex-col grow prose dark:prose-invert max-w-3xl gap-6 transition"
> >
<h1 class="mb-0">Stories</h1> <h1 class="mb-0">Stories</h1>
<div class="m-0">
Filter:
<Tag
:dest="`/tags/stories/${tag}`"
v-for="(tag, index) in tags"
:key="index"
>
{{ tag }}
</Tag>
</div>
<PostPreviewCard <PostPreviewCard
v-for="(story, index) in docs" v-for="(story, index) in docs"
:key="index" :key="index"