-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathcontent.config.ts
More file actions
94 lines (86 loc) · 2.18 KB
/
content.config.ts
File metadata and controls
94 lines (86 loc) · 2.18 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import {
defineContentConfig,
defineCollection,
defineCollectionSource
} from '@nuxt/content'
import { z } from 'zod'
const LANGUAGES = ['en', 'fr', 'ja']
const COLLECTIONS = [
{ key: 'pages' },
{ key: 'features' },
{ key: 'alternatives' },
{ key: 'audiences' }
]
const pageCache = new Map()
const loadPages = async lang => {
if (!pageCache.has(lang)) {
const data = await import(`./content/${lang}_pages.json`).then(
m => m.default ?? m
)
pageCache.set(lang, data)
}
return pageCache.get(lang)
}
const pagesSource = defineCollectionSource({
getKeys: async () => {
const items = []
for (const lang of LANGUAGES) {
const data = await loadPages(lang)
for (const { key } of COLLECTIONS) {
const entries = data[key] ?? []
for (const slug in entries) {
items.push(`${lang}/${key}/${slug}.json`)
}
}
}
return items
},
getItem: async key => {
const [lang, collection, filename] = key.split('/')
const slug = filename.replace('.json', '')
const data = await loadPages(lang)
const page = data[collection]?.[slug]
const res = {
...page,
localizedSlug: page.slug,
pageType: collection,
lang
}
return res ?? null
}
})
export default defineContentConfig({
collections: {
markdownPages: defineCollection({
type: 'page',
source: 'pages/**/*.md'
}),
jsonPages: defineCollection({
type: 'page',
source: pagesSource,
schema: z.object({
slug: z.string(),
localizedSlug: z.string(),
pageType: z.string(),
lang: z.string()
}),
indexes: [{ columns: ['slug', 'localizedSlug', 'pageType', 'lang'] }]
}),
faq: defineCollection({
type: 'page',
source: 'faq/**/*.md'
}),
studios: defineCollection({
type: 'page',
source: 'studios/**/*.json',
schema: z.object({
name: z.string(),
elementKey: z.string(),
type: z.union([z.array(z.string()), z.string()]),
link: z.string(),
case_study: z.union([z.array(z.string()), z.string()]).default('')
}),
indexes: [{ columns: ['elementKey'] }]
})
}
})