|
14 | 14 | class="cursor-pointer font-size-26px font-weight-bold"
|
15 | 15 | :class="{
|
16 | 16 | 'color-type': key !== activeIndex,
|
17 |
| - }"> |
| 17 | + }" |
| 18 | + > |
18 | 19 | <span>{{ String(key).trim() }}</span>
|
19 | 20 | <span class="mr-6 font-size-16px">({{ _.length }})</span>
|
20 | 21 | </span>
|
|
24 | 25 | <template v-for="it in posts[activeIndex]">
|
25 | 26 | <NuxtLink
|
26 | 27 | :to="'/' + it._file!.slice(0, -3)"
|
27 |
| - class="flex justify-between items-start my-2 py-2 cursor-pointer"> |
| 28 | + class="flex justify-between items-start my-2 py-2 cursor-pointer light:hover:bg-light dark:hover:bg-dark p-4 rounded" |
| 29 | + > |
28 | 30 | <span class="flex-1">{{ it.title }}</span>
|
29 | 31 | <span class="w-100px font-size-12px ml-5 color-#aaa">{{
|
30 |
| - Dayjs(it.date).format('YYYY-MM-DD') |
| 32 | + Dayjs(it.date).format("YYYY-MM-DD") |
31 | 33 | }}</span>
|
32 | 34 | </NuxtLink>
|
33 | 35 | </template>
|
|
36 | 38 | </template>
|
37 | 39 |
|
38 | 40 | <script setup lang="ts">
|
39 |
| -import { ref } from 'vue' |
40 |
| -import Dayjs from 'dayjs' |
41 |
| -import { getPosts } from '../../utils' |
42 |
| -import type { ParsedContent } from '@nuxt/content' |
| 41 | +import { ref } from "vue"; |
| 42 | +import Dayjs from "dayjs"; |
| 43 | +import { getPosts } from "../../utils"; |
| 44 | +import type { ParsedContent } from "@nuxt/content"; |
43 | 45 |
|
44 | 46 | // 当前激活的分类
|
45 |
| -const activeIndex = ref<string | number>('') |
| 47 | +const activeIndex = ref<string | number>(""); |
46 | 48 |
|
47 | 49 | // 所有文章
|
48 | 50 | const posts = ref<{
|
49 |
| - [key: string]: ParsedContent[] |
50 |
| -}>({}) |
| 51 | + [key: string]: ParsedContent[]; |
| 52 | +}>({}); |
51 | 53 |
|
52 | 54 | const typeCheck = (key: string | number) => {
|
53 |
| - activeIndex.value = key |
54 |
| - sessionStorage.setItem('activeIndex', String(key)) |
55 |
| -} |
| 55 | + activeIndex.value = key; |
| 56 | + sessionStorage.setItem("activeIndex", String(key)); |
| 57 | +}; |
56 | 58 |
|
57 | 59 | onMounted(() => {
|
58 | 60 | // 获取所有文章
|
59 |
| - getPosts('/').then((res) => { |
60 |
| - posts.value = res |
61 |
| - if (sessionStorage.getItem('activeIndex') === null) { |
62 |
| - activeIndex.value = Object.keys(res)[0] |
| 61 | + getPosts("/").then((res) => { |
| 62 | + posts.value = res; |
| 63 | + if (sessionStorage.getItem("activeIndex") === null) { |
| 64 | + activeIndex.value = Object.keys(res)[0]; |
63 | 65 | } else {
|
64 |
| - activeIndex.value = sessionStorage.getItem('activeIndex')! |
| 66 | + activeIndex.value = sessionStorage.getItem("activeIndex")!; |
65 | 67 | }
|
66 |
| - }) |
67 |
| -}) |
| 68 | + }); |
| 69 | +}); |
68 | 70 |
|
69 | 71 | useHead({
|
70 |
| - title: 'yosong - blog', |
| 72 | + title: "yosong - blog", |
71 | 73 | meta: [
|
72 |
| - { name: 'description', content: 'yosong blog list' }, |
73 |
| - { name: 'keywords', content: 'yosong blog' }, |
| 74 | + { name: "description", content: "yosong blog list" }, |
| 75 | + { name: "keywords", content: "yosong blog" }, |
74 | 76 | ],
|
75 |
| -}) |
| 77 | +}); |
76 | 78 | </script>
|
0 commit comments