Repository navigation
Expand file tree
/
Copy pathcontent.config.ts
More file actions
74 lines (66 loc) · 1.95 KB
/
Copy pathcontent.config.ts
File metadata and controls
74 lines (66 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import type { ReadTimeResults } from 'reading-time'
import { defineCollection } from '@nuxt/content'
import { defineSitemapSchema } from '@nuxtjs/sitemap/content'
import { z } from 'zod'
import blogConfig from './blog.config'
type ArticleType = keyof typeof blogConfig.article.types
// 文章类型已在 blog.config 中定义,此处使用 any 类型绕过 zod 类型验证
const articleTypes = Object.keys(blogConfig.article.types) as any
export interface ArticleSchema {
title?: string
description?: string
date?: string
updated?: string
published?: string
categories?: string[]
tags?: string[]
type?: ArticleType
image?: string
recommend?: number
references?: { title?: string, link?: string }[]
/** TODO */
draft?: boolean
permalink?: string
readingTime?: ReadTimeResults
}
const articleSchema = z.object({
title: z.string().optional(),
description: z.string().optional(),
date: z.string().optional(),
updated: z.string().optional(),
published: z.string().optional(),
categories: z.array(z.string()).default([blogConfig.defaultCategory]),
tags: z.array(z.string()).default([]),
type: z.enum(articleTypes).optional().default(articleTypes[0]),
image: z.string().optional(),
recommend: z.number().optional(),
references: z.array(z.object({
title: z.string().optional(),
link: z.string().optional(),
})).optional(),
draft: z.boolean().default(false),
permalink: z.string().optional(),
readingTime: z.object({
text: z.string(),
minutes: z.number(),
time: z.number(),
words: z.number(),
}),
}) satisfies z.ZodType<ArticleSchema>
export const collections = {
content: defineCollection({
source: '**',
type: 'page',
schema: articleSchema.extend({
sitemap: defineSitemapSchema({
name: 'content',
onUrl: (url, entry) => {
const lastmod = (entry.updated || entry.published || entry.date) as string | undefined
if (lastmod)
url.lastmod = new Date(lastmod).toLocaleDateString('sv')
},
z,
}),
}),
}),
}