-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathastro.config.mjs
More file actions
93 lines (86 loc) · 2.54 KB
/
Copy pathastro.config.mjs
File metadata and controls
93 lines (86 loc) · 2.54 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
// @ts-check
import netlify from "@astrojs/netlify";
import sitemap from "@astrojs/sitemap";
import svelte from "@astrojs/svelte";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "astro/config";
import { readdirSync, writeFileSync } from "fs";
const LOCALES_DIR = new URL("src/locales/", import.meta.url);
/** Locale codes, derived from the files in src/locales/. */
function getLocaleCodes() {
return readdirSync(LOCALES_DIR)
.filter((f) => f.endsWith(".ts"))
.map((f) => f.slice(0, -3));
}
/**
* Vite plugin that generates a strict Locale type from the locales directory,
* so adding a new locale file is all that's needed.
*/
function localeTypes() {
function generate() {
const type = getLocaleCodes()
.map((f) => `"${f}"`)
.join(" | ");
writeFileSync(
new URL("src/types/locale.gen.ts", import.meta.url),
`// Auto-generated — do not edit\nexport type Locale = ${type};\n`,
);
}
return {
name: "locale-types",
buildStart: generate,
};
}
/** https://docs.netlify.com/configure-builds/environment-variables/#read-only-variables */
const NETLIFY_PREVIEW_SITE =
process.env.CONTEXT !== "production" && process.env.DEPLOY_PRIME_URL;
// https://astro.build/config
export default defineConfig({
site: NETLIFY_PREVIEW_SITE || "https://rosepinetheme.com",
prefetch: true,
integrations: [
svelte(),
sitemap({
i18n: {
defaultLocale: "en",
locales: Object.fromEntries(
getLocaleCodes().map((code) => [code, code]),
),
},
filter: (page) => !new URL(page).pathname.startsWith("/en/"),
namespaces: {
news: false,
image: false,
video: false,
},
}),
],
image: {
domains: ["avatars.githubusercontent.com", "raw.githubusercontent.com"],
responsiveStyles: true,
},
vite: {
plugins: [tailwindcss(), localeTypes()],
},
markdown: {
shikiConfig: {
themes: { dark: "rose-pine", light: "rose-pine-dawn" },
},
},
// use netlify adapter to translate redirects to the proper _redirects format
// https://docs.astro.build/en/guides/integrations-guide/netlify/#static-sites-with-the-netlify-adapter
adapter: netlify({ imageCDN: false }),
redirects: {
"/en": "/",
"/en/:path*": "/:path*",
"/palette/ingredients": "/palette",
"/:lang/palette/ingredients": "/:lang/palette",
"/resources": "/create",
"/:lang/resources": "/:lang/create",
"/resources/:slug*": "/create/:slug*",
"/:lang/resources/:slug*": "/:lang/create/:slug*",
"/discord": "https://discord.gg/M7UBHVuerY",
"/new":
"https://github.com/rose-pine/rose-pine-site/issues/new?template=theme.yaml",
},
});