-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathconfig.ts
More file actions
75 lines (70 loc) · 2.88 KB
/
config.ts
File metadata and controls
75 lines (70 loc) · 2.88 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
import { defineCollection, z } from 'astro:content';
import { docsLoader, i18nLoader } from '@astrojs/starlight/loaders';
import { docsSchema, i18nSchema } from '@astrojs/starlight/schema';
import { starlightLocales } from '../utils/i18n.ts';
import { getBaseDocId, localizeDocId } from '../utils/docsSlug.ts';
export const collections = {
docs: defineCollection({
loader: customDocsLoader(),
schema: docsSchema({
extend: z.object({
hideHeader: z.boolean().optional(),
metaRobots: z.string().optional(),
}),
}),
}),
i18n: defineCollection({
loader: i18nLoader(),
schema: i18nSchema({
extend: z.object({
sidebar: z.record(z.string(), z.string()).optional(),
'copyContent': z.string().optional(),
'editLink.loading': z.string().optional(),
'editLink.copied': z.string().optional(),
'editLink.error': z.string().optional(),
'feedback.question': z.string().optional(),
'feedback.placeholder': z.string().optional(),
'feedback.submit': z.string().optional(),
'feedback.success': z.string().optional(),
'footer.status': z.string().optional(),
'footer.terms': z.string().optional(),
'footer.privacy': z.string().optional(),
'footer.cookies': z.string().optional(),
'footer.security': z.string().optional(),
'footer.llms': z.string().optional(),
'hero.crowdinHelp': z.string().optional(),
'hero.enterpriseHelp': z.string().optional(),
'hero.developerPortal': z.string().optional(),
'languages.errorLoading': z.string().optional(),
'formats.alt': z.string().optional(),
'formats.supported': z.string().optional(),
'formats.viewOnStore': z.string().optional(),
'repo.official': z.string().optional(),
'repo.viewInstall': z.string().optional(),
'social.applePodcast': z.string().optional(),
'social.spotifyPodcast': z.string().optional(),
'modal.header': z.string().optional(),
'translateInCrowdin': z.string().optional(),
}),
}),
}),
};
const localizedLocales = Object.keys(starlightLocales).filter(locale => locale !== 'root');
/*
Crowdin returns translations keeping the source page's frontmatter `slug` (no
locale prefix). Starlight routes by content id, so a `tr/` file whose id lacks the
`tr/` prefix is served at the root path and collides with the same-slug English page.
We override `generateId` to re-apply the prefix before the id becomes the store key.
*/
function customDocsLoader() {
return docsLoader({
generateId: ({ entry, data }) => {
const baseId = getBaseDocId(entry, data.slug);
const id = localizeDocId(entry, baseId, localizedLocales);
if (id !== baseId) {
console.warn(`[custom-docs-loader] Re-prefixed locale slug for ${entry}: '${baseId}' -> '${id}'`);
}
return id;
},
});
}