mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-25 11:28:13 +08:00
32 lines
954 B
TypeScript
32 lines
954 B
TypeScript
import { computed } from 'vue'
|
|
import type { PlumeThemeBlogPostItem } from '../../shared/index.js'
|
|
import { useLocalePostList } from './blog-post-list.js'
|
|
|
|
export type ShortPostItem = Pick<PlumeThemeBlogPostItem, 'title' | 'path' | 'createTime'>
|
|
|
|
export function useArchives() {
|
|
const list = useLocalePostList()
|
|
const archives = computed(() => {
|
|
const archives: { label: string, list: ShortPostItem[] }[] = []
|
|
|
|
list.value.forEach((item) => {
|
|
const createTime = item.createTime?.split(' ')[0] || ''
|
|
const year = createTime.split('/')[0]
|
|
let current = archives.find(archive => archive.label === year)
|
|
if (!current) {
|
|
current = { label: year, list: [] }
|
|
archives.push(current)
|
|
}
|
|
current.list.push({
|
|
title: item.title,
|
|
path: item.path,
|
|
createTime: createTime.slice(year.length + 1).replace(/\//g, '-'),
|
|
})
|
|
})
|
|
|
|
return archives
|
|
})
|
|
|
|
return { archives }
|
|
}
|