public/pages/[...slug].vue

68 lines
1.6 KiB
Vue
Raw Normal View History

2022-08-09 15:37:32 -04:00
<script setup lang="ts">
import type { BlogParsedContent, StoryParsedContent } from "@/shared/types";
2022-08-10 17:22:08 -04:00
import { calcReadingTime, getPrettyDate } from "@/shared/metadata";
2022-08-09 15:37:32 -04:00
type GeneralParsedContent = BlogParsedContent | StoryParsedContent;
const route = useRoute();
2022-08-10 18:05:40 -04:00
definePageMeta({
layout: "withtop",
});
2022-08-09 15:37:32 -04:00
// we're not using ContentDoc because i need control
const doc = await queryContent<GeneralParsedContent>(route.path).findOne();
2022-08-10 17:22:08 -04:00
const type = route.path.startsWith("/stories")
? "stories"
: route.path.startsWith("/blog")
? "blog"
: "unknown";
const descText =
type === "stories"
? `${calcReadingTime(doc).words.total} words`
: `${calcReadingTime(doc).minutes} min read`;
2022-08-10 16:50:50 -04:00
useTitle(doc.title);
2022-08-10 17:22:08 -04:00
const captionText =
type === "stories" ? "Story" : type === "blog" ? "Blog post" : "";
2022-08-09 15:37:32 -04:00
</script>
2022-08-07 11:37:29 -04:00
2022-07-21 16:50:03 -04:00
<template>
2022-08-09 15:37:32 -04:00
<div class="container prose dark:prose-invert w-full">
2022-08-10 17:22:08 -04:00
<p class="m-0 uppercase font-mono text-sm" v-if="captionText !== ''">
{{ captionText }}
</p>
<h1 class="m-0">{{ doc.title }}</h1>
<p class="my-2">{{ getPrettyDate(doc) }} · {{ descText }}</p>
<div class="flex flex-wrap">
<Tag
v-for="(tag, index) in doc.tags"
:dest="`/tags/${type}/${tag}`"
:key="index"
>
{{ tag }}
</Tag>
</div>
<ContentDoc tag="article" class="pt-0 w-full">
2022-08-09 15:37:32 -04:00
<template #empty>
<p>No description found.</p>
</template>
<template #not-found>
2022-07-22 15:40:31 -04:00
<h1>404 - Not Found</h1>
2022-08-09 15:37:32 -04:00
</template>
2022-08-10 17:22:08 -04:00
</ContentDoc>
2022-08-09 15:37:32 -04:00
</div>
2022-07-21 16:50:03 -04:00
</template>
2022-07-22 15:36:37 -04:00
2022-08-09 15:37:32 -04:00
<style scoped>
.container {
2022-07-22 16:08:55 -04:00
width: 80%;
2022-08-09 15:37:32 -04:00
max-width: 72ch;
2022-07-22 15:40:31 -04:00
padding-top: 2rem;
2022-07-22 15:36:37 -04:00
}
* {
transition: color 0.2s ease;
}
2022-07-22 15:36:37 -04:00
</style>