-
Notifications
You must be signed in to change notification settings - Fork 4
/
astro.config.mjs
151 lines (143 loc) · 4.58 KB
/
astro.config.mjs
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { defineConfig } from "astro/config";
import react from "@astrojs/react";
import tailwind from "@astrojs/tailwind";
import AutoImport from "astro-auto-import";
import mdx from "@astrojs/mdx";
import sitemap from "@astrojs/sitemap";
import expressiveCode from "astro-expressive-code";
import remarkReplaceVersions from "./src/integrations/remarkReplaceVersions";
import { fetchVersions } from "./src/integrations/fetchSdkVersions";
import rehypeExternalLinks from "rehype-external-links";
import remarkCustomHeadingId from "remark-custom-heading-id";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import redirectList from "./src/redirects.json";
import {
remarkDefinitionList,
defListHastHandlers,
} from "remark-definition-list";
import { writeFile } from "fs";
import markdoc from "@astrojs/markdoc";
console.log(
`${import.meta.env.VITE_GITHUB_TOKEN ? "Token found" : "No token found"}`,
);
const versions = await fetchVersions();
const versionJSON = JSON.stringify(versions, null, 2)
await writeFile("src/versionMap.json", versionJSON, (err) => { });
const locales = ["en", "ja", "ko", "zh"];
const prependLocaleToJSON = (input, locales) => {
const result = {};
for (const [key, value] of Object.entries(input)) {
const localeRegex = /^\/[a-z]{2}\//;
if (localeRegex.exec(value)) return;
locales.forEach((locale) => {
result[`/${locale}${key}`] = `/${locale}${value}`;
});
}
return result;
};
const updatedRedirectList = prependLocaleToJSON(redirectList, locales);
// https://astro.build/config
export default defineConfig({
redirects: updatedRedirectList,
i18n: {
defaultLocale: "en",
locales: ["en", "ja", "ko", "zh"],
routing: {
prefixDefaultLocale: true,
fallbackType: "rewrite",
redirectToDefaultLocale: false,
},
fallback: {
ja: "en",
ko: "en",
zh: "en"
},
},
experimental: {
contentCollectionCache: true
},
integrations: [AutoImport({
imports: [
"@components/Accordion.astro",
"@components/Callout.astro",
"@components/CodeBlock.astro",
"@components/ListColumns.astro",
"@components/MinorVersion.astro",
"@components/Tab.astro",
"@components/Tabs.astro",
],
}), // Enable React for the Algolia search component.
react({
experimentalReactChildren: true,
}), expressiveCode(), mdx({
optimize: true,
}), tailwind(), sitemap(), markdoc()],
site: "https://dev.adjust.com/",
markdown: {
remarkPlugins: [
[remarkReplaceVersions, versions],
remarkCustomHeadingId,
remarkDefinitionList,
],
remarkRehype: {
handlers: defListHastHandlers,
},
rehypePlugins: [
[
rehypeAutolinkHeadings,
{
behavior: "append",
properties: {
className: ["copy-link"],
},
content: {
type: "element",
tagName: "svg",
properties: {
xmlns: "http://www.w3.org/2000/svg",
height: 24,
width: 24,
viewBox: "0 0 24 24",
fill: "currentColor",
},
children: [
{
type: "element",
tagName: "path",
properties: {
fillRule: "evenodd",
d: "M8.464 10.793a.5.5 0 00-.707 0l-1.68 1.68c-1.19 1.19-1.298 3.12-.17 4.248l.943.942c1.155 1.155 3.031.905 4.19-.254l1.667-1.667a.5.5 0 10-.707-.707l-1.666 1.667c-.879.878-2.114.917-2.777.254l-.943-.942c-.681-.682-.687-1.977.17-2.834l1.68-1.68a.5.5 0 000-.707zm2.829-2.829a.5.5 0 010-.707l1.68-1.68c1.19-1.19 3.12-1.298 4.248-.17l.942.942c1.155 1.155.905 3.032-.254 4.191l-1.666 1.667a.5.5 0 01-.707-.707l1.666-1.667c.878-.878.918-2.113.254-2.777l-.942-.942c-.682-.682-1.976-.688-2.833.17L12 7.964a.5.5 0 01-.707 0zm3.535 1.414a.5.5 0 10-.707-.707l-4.95 4.95a.5.5 0 10.708.707l4.95-4.95z",
clipRule: "evenodd",
},
},
],
},
},
],
[
rehypeExternalLinks,
{
content: {
type: "element",
tagName: "svg",
properties: {
style:
"margin-bottom:0.35rem;margin-left:0.15rem;margin-right:0.15rem;display:inline-block;",
width: "16",
height: "16",
},
children: [
{
type: "element",
tagName: "use",
properties: {
href: "#external-link",
},
},
],
},
},
],
],
},
});