Repository navigation
Expand file tree
/
Copy pathastro.config.mjs
More file actions
71 lines (66 loc) 路 2.26 KB
/
Copy pathastro.config.mjs
File metadata and controls
71 lines (66 loc) 路 2.26 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
import { writeFile } from 'node:fs/promises';
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
import { sentryVitePlugin } from '@sentry/vite-plugin';
import { getModel } from './src/lib/data/model.js';
import { getData } from './src/lib/data/load.js';
import { site } from './src/lib/site.js';
const uploadMaps = Boolean(process.env.SENTRY_AUTH_TOKEN && process.env.SENTRY_URL);
const data = getData();
const { devices, roms, brands } = getModel();
const imported = new Map(data.upstream.map((file) => [file.name, file.data.imported]));
const newest = (dates) => dates.filter(Boolean).sort().at(-1);
const lastmodOf = (rows) =>
newest(rows.map((row) => row.latest?.date)) ??
newest(rows.map((row) => imported.get(row.rom.key)));
const lastChanged = new Map([
...devices.map((device) => [device.url, lastmodOf(device.support)]),
...roms.map((rom) => [rom.url, lastmodOf(rom.support)]),
...brands.map((brand) => [
brand.url,
lastmodOf(brand.devices.flatMap((device) => device.support)),
]),
]);
const codenameRedirects = Object.fromEntries(
devices.flatMap((device) =>
device.codenames.map((codename) => [`/devices/${codename}/`, device.url]),
),
);
const redirectsFile = {
name: 'codename-redirects-file',
hooks: {
'astro:build:done': ({ dir }) =>
writeFile(
new URL('_redirects', dir),
Object.entries(codenameRedirects)
.map(([from, to]) => `${from} ${to} 301\n`)
.join(''),
),
},
};
export default defineConfig({
site: site.url,
trailingSlash: 'always',
redirects: codenameRedirects,
vite: {
build: { assetsInlineLimit: 0, sourcemap: uploadMaps && 'hidden' },
plugins: [
uploadMaps &&
sentryVitePlugin({
telemetry: false,
release: { create: false, finalize: false, setCommits: false, deploy: false },
bundleSizeOptimizations: { excludeDebugStatements: true, excludeTracing: true },
sourcemaps: { assets: './dist/**', filesToDeleteAfterUpload: './dist/**/*.map' },
}),
],
},
integrations: [
sitemap({
serialize: (item) => {
const lastmod = lastChanged.get(new URL(item.url).pathname);
return lastmod ? { ...item, lastmod } : item;
},
}),
redirectsFile,
],
});