11<script setup lang="ts">
2- import { useRouter } from ' vue-router'
2+ // import { useRouter } from 'vue-router'
33import { computed } from ' vue'
44import { usePostList } from ' valaxy'
5+ import type { Post } from ' valaxy'
56import { englishOnly , formatDate } from ' ../logics'
6- import type { Post } from ' ../types'
77
88const props = defineProps <{
99 type? : string
1010 posts? : Post []
1111 extra? : Post []
1212}>()
1313
14- const router = useRouter ()
14+ // const router = useRouter()
1515// const routes: Post[] = router.getRoutes()
1616// .filter(i => i.path.startsWith('/posts') && i.meta.frontmatter.date && !i.meta.frontmatter.draft)
1717// .filter(i => !i.path.endsWith('.html') && (i.meta.frontmatter.type || 'blog').split('+').includes(props.type))
@@ -30,13 +30,17 @@ const router = useRouter()
3030// const routes = usePostList({ type: props.type || '' })
3131const routes = usePostList ({ type: props .type })
3232
33- const posts = computed (() => props .posts || routes .value )
33+ // const posts = computed(() => props.posts || routes.value)
3434
35- // const posts = computed(() =>
36- // [...(props.posts || routes), ...props.extra || []]
37- // .sort((a, b) => +new Date(b.date) - +new Date(a.date))
38- // .filter(i => !englishOnly.value || i.lang !== 'zh'),
39- // )
35+ const posts = computed (() =>
36+ [... (props .posts || routes .value ), ... props .extra || []]
37+ .sort ((a , b ) => {
38+ const dateA = typeof a .date === ' string' || typeof a .date === ' number' ? new Date (a .date ) : new Date ()
39+ const dateB = typeof b .date === ' string' || typeof b .date === ' number' ? new Date (b .date ) : new Date ()
40+ return + dateB - + dateA
41+ })
42+ .filter (i => ! englishOnly .value || i .lang !== ' zh' ),
43+ )
4044
4145const getYear = (a : Date | string | number ) => new Date (a ).getFullYear ()
4246const isFuture = (a ? : Date | string | number ) => a && new Date (a ) > new Date ()
@@ -48,28 +52,28 @@ function isSameGroup(a: Post, b?: Post) {
4852function getGroupName(p : Post ) {
4953 if (isFuture (p .date ))
5054 return ' Upcoming'
51- return getYear (p .date )
55+ return getYear (p .date ! )
5256}
5357 </script >
5458
5559<template >
5660 <ul >
5761 <template v-if =" ! posts .length " >
58- <div py2 op50 >
62+ <div op50 py2 >
5963 { nothing here yet }
6064 </div >
6165 </template >
6266
6367 <template v-for =" route , idx in posts " :key =" route .path " >
6468 <div
65- v-if =" !isSameGroup(route, posts[idx - 1])" select-none relative h20 pointer-events-none slide-enter :style =" {
69+ v-if =" !isSameGroup(route, posts[idx - 1])" slide-enter select-none pointer-events-none relative h20 :style =" {
6670 '--enter-stage': idx - 2,
6771 '--enter-step': '60ms',
6872 }"
6973 >
7074 <span
71- text-8em color-transparent absolute left--3rem top--2rem font-bold text-stroke-2 text-stroke-hex-aaa
72- op10
75+
76+ absolute font-bold color-transparent text-stroke-hex-aaa text-8em left--3rem top--2rem text-stroke-2 op10
7377 >{{ getGroupName(route) }}</span >
7478 </div >
7579 <div
@@ -79,19 +83,19 @@ function getGroupName(p: Post) {
7983 }"
8084 >
8185 <component
82- :is =" route.path.includes('://') ? 'a' : 'RouterLink'" v-bind =" route.path.includes('://') ? {
86+ :is =" route.path? .includes('://') ? 'a' : 'RouterLink'" v-bind =" route.path? .includes('://') ? {
8387 href: route.path,
8488 target: '_blank',
8589 rel: 'noopener noreferrer',
8690 } : {
8791 to: route.path,
8892 }
89- " class =" item block font-normal mb-6 mt-2 no-underline"
93+ " class =" mb-6 item block font-normal mt-2 no-underline"
9094 >
9195 <li class =" no-underline" flex =" ~ col md:row gap-2 md:items-center" >
92- <div class =" title text-lg leading-1.2em" flex =" ~ gap-2 wrap" >
96+ <div class =" text-lg title leading-1.2em" flex =" ~ gap-2 wrap" >
9397 <span
94- v-if =" route.lang === 'zh'" align-middle flex-none
98+ v-if =" route.lang === 'zh'" flex-none align-middle
9599 class =" text-xs bg-zinc:15 text-zinc5 rounded px-1 py-0.5 ml--12 mr2 my-auto hidden md:block"
96100 >中文</span >
97101 <span align-middle >{{ route.title }}</span >
@@ -112,7 +116,7 @@ function getGroupName(p: Post) {
112116 <span text-sm op50 ws-nowrap >
113117 {{ formatDate(route.date, true) }}
114118 </span >
115- <span v-if =" route.duration" text-sm op40 ws-nowrap >· {{ route.duration }}</span >
119+ <span v-if =" route.duration" text-sm ws-nowrap op40 >· {{ route.duration }}</span >
116120 <span v-if =" route.platform" text-sm op40 ws-nowrap >· {{ route.platform }}</span >
117121 <span v-if =" route.place" text-sm op40 ws-nowrap md:hidden >· {{ route.place }}</span >
118122 <span
@@ -121,7 +125,7 @@ function getGroupName(p: Post) {
121125 >中文</span >
122126 </div >
123127 </li >
124- <div v-if =" route.place" op50 text-sm hidden mt--2 md:block >
128+ <div v-if =" route.place" op50 text-sm hidden md:block mt--2 >
125129 {{ route.place }}
126130 </div >
127131 </component >
0 commit comments