-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathastro.config.ts
94 lines (93 loc) · 2.81 KB
/
astro.config.ts
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
import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import path from "path";
import { CUSTOM_DOMAIN, BASE_PATH } from "./src/constants";
const getSite = function () {
if (CUSTOM_DOMAIN) {
return new URL(BASE_PATH, `https://${CUSTOM_DOMAIN}`).toString();
}
if (process.env.VERCEL && process.env.VERCEL_URL) {
return new URL(BASE_PATH, `https://${process.env.VERCEL_URL}`).toString();
}
if (process.env.CF_PAGES) {
if (process.env.CF_PAGES_BRANCH !== "main") {
return new URL(BASE_PATH, process.env.CF_PAGES_URL).toString();
}
return new URL(
BASE_PATH,
`https://${new URL(process.env.CF_PAGES_URL).host.split(".").slice(1).join(".")}`,
).toString();
}
if (process.env.GITHUB_PAGES) {
return new URL(process.env.BASE || BASE_PATH, process.env.SITE).toString();
}
return new URL(BASE_PATH, "http://localhost:4321").toString();
};
import CustomIconDownloader from "./src/integrations/custom-icon-downloader";
import EntryCacheEr from "./src/integrations/entry-cache-er";
import PublicNotionCopier from "./src/integrations/public-notion-copier";
import DeleteBuildCache from "./src/integrations/delete-build-cache";
import buildTimestampRecorder from "./src/integrations/build-timestamp-recorder.ts";
import rssContentEnhancer from "./src/integrations/rss-content-enhancer";
import CSSWriter from "./src/integrations/theme-constants-to-css";
import robotsTxt from "astro-robots-txt";
import config from "./constants-config.json";
import partytown from "@astrojs/partytown";
const key_value_from_json = {
...config,
};
function modifyRedirectPaths(
redirects: Record<string, string>,
basePath: string,
): Record<string, string> {
const modifiedRedirects: Record<string, string> = {};
for (const [key, value] of Object.entries(redirects)) {
if (basePath && !value.startsWith(basePath) && !value.startsWith("/" + basePath)) {
modifiedRedirects[key] = path.join(basePath, value);
} else {
modifiedRedirects[key] = value;
}
}
return modifiedRedirects;
}
// https://astro.build/config
export default defineConfig({
site: getSite(),
base: process.env.BASE || BASE_PATH,
redirects: key_value_from_json["redirects"]
? modifyRedirectPaths(key_value_from_json["redirects"], process.env.BASE || BASE_PATH)
: {},
integrations: [
// mdx({}),
tailwind({
applyBaseStyles: false,
}),
// astroImageTools,
buildTimestampRecorder(),
CustomIconDownloader(),
EntryCacheEr(),
PublicNotionCopier(),
DeleteBuildCache(),
CSSWriter(),
rssContentEnhancer(),
robotsTxt({
sitemapBaseFileName: "sitemap",
}),
partytown({
// Adds dataLayer.push as a forwarding-event.
config: {
forward: ["dataLayer.push"],
},
}),
],
image: {
domains: ["webmention.io"],
},
prefetch: true,
vite: {
plugins: [],
optimizeDeps: {
exclude: ["@resvg/resvg-js"],
},
},
});