更新任务
This commit is contained in:
1 parent
120a57ad57
commit
6118a80ac4
279 files changed
+9682
-2362
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import { createContentLoader } from 'vitepress'
|
||||
|
||||
interface Post {
|
||||
title: string
|
||||
url: string
|
||||
date: {
|
||||
time: number
|
||||
string: string
|
||||
year: string
|
||||
monthDay: string
|
||||
}
|
||||
tags: string[]
|
||||
excerpt: string | undefined
|
||||
}
|
||||
|
||||
export declare const data: Post[]
|
||||
|
||||
export default createContentLoader('posts/**/*.md', {
|
||||
excerpt: excerptFn,
|
||||
transform (raw): Post[] {
|
||||
return raw.map(({ url, frontmatter, excerpt }) => ({
|
||||
title: frontmatter.title,
|
||||
url,
|
||||
excerpt,
|
||||
date: formatDate(frontmatter.date),
|
||||
tags: frontmatter.tags,
|
||||
})).sort((a, b) => b.date.time - a.date.time)
|
||||
},
|
||||
})
|
||||
|
||||
function excerptFn (file: {
|
||||
data: { [key: string]: any };
|
||||
content: string;
|
||||
excerpt?: string
|
||||
}, options?: any) {
|
||||
file.excerpt = file.content.split('<!-- DESC SEP -->')[1]
|
||||
}
|
||||
|
||||
function formatDate (raw: string): Post['date'] {
|
||||
const date = new Date(raw)
|
||||
date.setUTCHours(12)
|
||||
return {
|
||||
time: +date,
|
||||
string: date.toLocaleDateString('zh-Hans', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
}),
|
||||
year: date.toLocaleDateString('zh-Hans', {
|
||||
year: 'numeric',
|
||||
}),
|
||||
monthDay: date.toLocaleDateString('zh-Hans', {
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
}),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user