feat: add story stat box

This commit is contained in:
eggy 2022-08-08 18:41:29 -04:00
parent f469f86734
commit e802e3723c
5 changed files with 77 additions and 10 deletions

View File

@ -30,7 +30,13 @@ const prettyDate = latestDate.format("DD MMM YYYY");
{{ prettyDate }} · {{ latest.readingTime.text }} {{ prettyDate }} · {{ latest.readingTime.text }}
</p> </p>
<div class="tag-list mt-1"> <div class="tag-list mt-1">
<Tag v-for="(tag, index) in latest.tags" :key="index">{{ tag }}</Tag> <Tag
v-for="(tag, index) in latest.tags"
:key="index"
:dest="`/blog/tags/${tag}`"
>
{{ tag }}
</Tag>
</div> </div>
<!-- <!--
<ContentRenderer <ContentRenderer

View File

@ -12,7 +12,9 @@ const { href, color = "pink" } = defineProps<{
<a class="no-underline" :href="href"> <a class="no-underline" :href="href">
<div class="container box"> <div class="container box">
<p class="m-0 w-full title">{{ title }}</p> <p class="m-0 w-full title">{{ title }}</p>
<div class="main-content"><slot /></div> <div class="main-content">
<slot />
</div>
</div> </div>
</a> </a>
</template> </template>

View File

@ -1,7 +1,61 @@
<script setup lang="ts"> <script setup lang="ts">
//const latest = await queryContent("stories").findOne(); import dayjs from "dayjs";
import utc from "dayjs/plugin/utc.js";
import tz from "dayjs/plugin/timezone.js";
import type { BlogParsedContent } from "@/shared/types";
dayjs.extend(utc);
dayjs.extend(tz);
const docs = await queryContent<BlogParsedContent>("/stories")
.sort({ date: 1 })
.where({ _draft: false })
.find();
const latest = docs.at(-1);
const latestDate = dayjs(latest.date).utc();
const prettyDate = latestDate.format("DD MMM YYYY");
</script> </script>
<template> <template>
<HomeStatBox color="lightgreen" title="Latest story"> </HomeStatBox> <div class="prose dark:prose-invert">
<HomeStatBox :href="latest._path" color="lightgreen" title="Latest story">
<h2 class="m-0 mt-4 mb-1">{{ latest.title }}</h2>
<p class="text-sm text-gray-500 m-0">
{{ prettyDate }} · {{ latest.readingTime.text }}
</p>
<div class="tag-list mt-1">
<Tag
v-for="(tag, index) in latest.tags"
:key="index"
:dest="`/stories/tags/${tag}`"
>
{{ tag }}
</Tag>
</div>
<!--
<ContentRenderer
tag="article"
:value="latest"
:excerpt="true"
class="pt-0 w-full"
>
<ContentRendererMarkdown :value="latest" :excerpt="true" />
<template #empty>
<p>No description found.</p>
</template>
</ContentRenderer>
-->
<p class="excerpt text-gray-600 text-base m-0 mt-5">
{{ latest.description }}
</p>
</HomeStatBox>
</div>
</template> </template>
<style scoped>
article p {
color: gray;
}
</style>

View File

@ -1,7 +1,13 @@
<script setup lang="ts">
const { dest } = defineProps<{ dest: string }>();
</script>
<template> <template>
<div <a :href="dest">
class="inline-block text-xs rounded-full py-1 px-2 mt-1 mr-1 bg-gray-300 dark:bg-gray-500;" <div
> class="inline-block text-xs rounded-full py-1 px-2 mt-1 mr-1 bg-gray-300 dark:bg-gray-500;"
<slot /> >
</div> <slot />
</div>
</a>
</template> </template>

View File

@ -1 +0,0 @@
oy