|
| 1 | +<script setup lang="ts" name="ArchivesPage"> |
| 2 | +import { useDesign } from "../hooks"; |
| 3 | +import { useData } from "vitepress"; |
| 4 | +import { postsSymbol } from "../configProvider"; |
| 5 | +import { inject } from "vue"; |
| 6 | +import RouteLink from "./RouteLink.vue"; |
| 7 | +import { KtContentData } from "../data/post"; |
| 8 | +
|
| 9 | +const { getPrefixClass } = useDesign(); |
| 10 | +const prefixClass = getPrefixClass("archives"); |
| 11 | +
|
| 12 | +const { frontmatter } = useData(); |
| 13 | +
|
| 14 | +const posts = inject(postsSymbol); |
| 15 | +
|
| 16 | +const getDate = (item: KtContentData) => { |
| 17 | + const { |
| 18 | + frontmatter: { date }, |
| 19 | + } = item; |
| 20 | +
|
| 21 | + if (date) return date.slice(5, 10); |
| 22 | +}; |
| 23 | +</script> |
| 24 | + |
| 25 | +<template> |
| 26 | + <div :class="`${prefixClass} tk-page`"> |
| 27 | + <div :class="`${prefixClass}-header flx-justify-between`"> |
| 28 | + <div class="title">{{ frontmatter.title }}</div> |
| 29 | + <div class="count">总共 {{ posts.sortPostsByDate.length }} 篇文章</div> |
| 30 | + </div> |
| 31 | + |
| 32 | + <div :class="`${prefixClass}-timeline`"> |
| 33 | + <template v-for="(monthPosts, year) in posts.groupPostsByYearMonth" :key="year"> |
| 34 | + <div :class="`${prefixClass}-timeline__year flx-justify-between`"> |
| 35 | + <div class="year">{{ String(year) === "NaN" ? "未指定" : year }} 年</div> |
| 36 | + <div class="count">{{ posts.groupPostsByYear[year].length }}篇</div> |
| 37 | + </div> |
| 38 | + |
| 39 | + <div :class="`${prefixClass}-timeline-m`"> |
| 40 | + <template v-for="(posts, month) in monthPosts" :key="month"> |
| 41 | + <div :class="`${prefixClass}-timeline-m__month flx-justify-between`"> |
| 42 | + <div class="month">{{ String(month) === "NaN" ? "未指定" : month }} 月</div> |
| 43 | + <div class="count">{{ posts.length }}篇</div> |
| 44 | + </div> |
| 45 | + |
| 46 | + <ul> |
| 47 | + <li v-for="item in posts" :key="item.title"> |
| 48 | + <RouteLink :to="item.frontmatter.permalink || item.url"> |
| 49 | + <span class="date">{{ getDate(item) }}</span> |
| 50 | + <span>{{ item.title }}</span> |
| 51 | + </RouteLink> |
| 52 | + </li> |
| 53 | + </ul> |
| 54 | + </template> |
| 55 | + </div> |
| 56 | + </template> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | +</template> |
| 60 | + |
| 61 | +<style lang="scss" scoped> |
| 62 | +@use "../styles/components/archivesPage.scss"; |
| 63 | +</style> |
0 commit comments