-
Notifications
You must be signed in to change notification settings - Fork 274
Expand file tree
/
Copy pathcontent.config.ts
More file actions
74 lines (67 loc) · 1.69 KB
/
content.config.ts
File metadata and controls
74 lines (67 loc) · 1.69 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 { DefinedCollection } from "@nuxt/content";
import { defineCollection, defineContentConfig, z } from "@nuxt/content";
import { useNuxt } from "@nuxt/kit";
import { joinURL } from "ufo";
const { options } = useNuxt();
const cwd = joinURL(options.rootDir, "content");
const locales = options.i18n?.locales;
const createDocsSchema = () =>
z.object({
category: z.string(),
tags: z.array(z.string()),
badge: z.enum(["New", "Updated"]).optional(),
links: z
.array(
z.object({
label: z.string(),
icon: z.string(),
to: z.string(),
target: z.string().optional(),
}),
)
.optional(),
});
let collections: Record<string, DefinedCollection>;
if (locales && Array.isArray(locales)) {
collections = {};
for (const locale of locales) {
const code = typeof locale === "string" ? locale : locale.code;
collections[`landing_${code}`] = defineCollection({
type: "page",
source: {
cwd,
include: `${code}/index.md`,
},
});
collections[`docs_${code}`] = defineCollection({
type: "page",
source: {
cwd,
include: `${code}/**/*.md`,
prefix: `/${code}`,
exclude: [`${code}/index.md`],
},
schema: createDocsSchema(),
});
}
} else {
collections = {
landing: defineCollection({
type: "page",
source: {
cwd,
include: "index.md",
},
}),
docs: defineCollection({
type: "page",
source: {
cwd,
include: "**/*.md",
exclude: ["index.md"],
},
schema: createDocsSchema(),
}),
};
}
export default defineContentConfig({ collections });