-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathastro.config.mjs
74 lines (63 loc) · 1.67 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
import { execFileSync } from 'node:child_process';
import { defineConfig } from 'astro/config';
import solid from '@astrojs/solid-js';
import { env } from 'process';
import sitemap from '@astrojs/sitemap';
import astroI18next from 'astro-i18next';
function enhanceEnvVariables() {
if (!env.PUBLIC_BUILD_DATE) {
env.PUBLIC_BUILD_DATE = new Date().toISOString();
}
if (!env.PUBLIC_COMMIT_ID) {
env.PUBLIC_COMMIT_ID = execFileSync(
'git',
['rev-parse', '--short', 'HEAD'],
{
encoding: 'utf8',
}
).trim();
}
if (!env.PUBLIC_SITE_URL) {
env.PUBLIC_SITE_URL = 'https://romajs.org';
}
}
/**
* @type {(publicUrl: string) => { base: string, site: string | undefined }}
*/
function computeBaseAndSite(publicUrl) {
const siteFullURLWithPath = new URL(publicUrl);
let base = siteFullURLWithPath.pathname || '';
if (/^\/+$/.test(base)) {
base = '';
}
siteFullURLWithPath.pathname =
siteFullURLWithPath.hash =
siteFullURLWithPath.search =
'';
const site = siteFullURLWithPath.href;
env.PUBLIC_URL_BASE = base;
return {
site,
base,
};
}
enhanceEnvVariables();
const { base, site } = computeBaseAndSite(env.PUBLIC_SITE_URL);
// https://astro.build/config
export default defineConfig({
integrations: [
solid(),
astroI18next(),
sitemap({
i18n: {
defaultLocale: 'it', // All urls that don't contain `es` or `fr` after `https://stargazers.club/` will be treated as default locale, i.e. `en`
locales: {
en: 'en-US', // The `defaultLocale` value must present in `locales` keys
it: 'it-IT',
},
},
}),
],
base: base || undefined,
site,
});