-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathastro.config.ts
More file actions
173 lines (165 loc) · 5.58 KB
/
astro.config.ts
File metadata and controls
173 lines (165 loc) · 5.58 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import starlightSidebarTopics from "starlight-sidebar-topics";
import starlightLinksValidator from "starlight-links-validator";
import partytown from "@astrojs/partytown";
import vercel from "@astrojs/vercel";
import { setGlobalDispatcher, Agent } from "undici";
import { unwatchFile, watchFile } from "node:fs";
import { glob, readFile, writeFile, utimes } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { globalConfig } from "./src/config";
import redirects from "./src/redirects";
import { officialPluginsList } from "./src/content/officialPluginList";
import { sidebarTopics, sidebarTopicOptions } from "./src/sidebar";
import path from "node:path";
// We set this up to prefer IPv4 connections to IPv6 connections
// as otherwise the Vercel deployments were failing when trying to access
// the Ghost API
setGlobalDispatcher(new Agent({ connect: { family: 4 } }));
export default defineConfig({
site: globalConfig.url + "/",
adapter: vercel({}),
integrations: [
starlight({
title: "Hardhat 3",
favicon: "/favicon.ico",
disable404Route: true,
logo: {
light: "./src/assets/hardhat-logo-light.svg",
dark: "./src/assets/hardhat-logo-dark.svg",
replacesTitle: true,
},
editLink: {
baseUrl:
"https://github.com/NomicFoundation/hardhat-website/edit/main/",
},
head: [
{
tag: "meta",
attrs: {
property: "og:image",
content: globalConfig.url + "/thumbnail.png",
},
},
],
social: [
{
icon: "github",
label: "GitHub",
href: globalConfig.hardhatRepoUrl,
},
{
icon: "x.com",
label: "X",
href: "https://x.com/HardhatHQ",
},
{
icon: "discord",
label: "Discord",
href: "https://hardhat.org/discord",
},
],
plugins: [
// While we use this multi-sidebar plugin, each item of the array of
// sidebars is configured like a normal Starlight sidebar.
// See: https://starlight.astro.build/guides/sidebar/
starlightSidebarTopics(sidebarTopics, sidebarTopicOptions),
starlightLinksValidator({
exclude: Object.keys(redirects)
.concat(officialPluginsList.map((p) => `/docs/plugins/${p.slug}`))
.concat([
"/docs/plugins/official-plugins",
"/docs/plugins/community-plugins",
]),
}),
],
customCss: ["./src/styles/custom-starlight-theme.css"],
components: {
Sidebar: "./src/components/starlight-overrides/Sidebar.astro",
Head: "./src/components/starlight-overrides/Head.astro",
Header: "./src/components/starlight-overrides/Header.astro",
TableOfContents:
"./src/components/starlight-overrides/TableOfContents.astro",
},
}),
partytown({
config: {
forward: ["dataLayer.push"],
},
}),
{
// The plugin @astrojs/sitemap doesn't generate entries for our .md files
// because it only does it for routes of `r.type === "page"`, and our
// .md files are not pages. We use a custom hook to fixup the sitemap.
name: "sitemap-md-urls",
hooks: {
"astro:build:done": async ({ dir, logger }) => {
const distPath = fileURLToPath(dir);
const mdFiles = await Array.fromAsync(
glob(path.join(distPath, "**", "*.md")),
);
const sitemapPath = path.join(distPath, "sitemap-0.xml");
let sitemap = await readFile(sitemapPath, "utf-8");
const siteUrl = globalConfig.url;
const existingUrls = new Set(
[...sitemap.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1]),
);
const newFiles = [...mdFiles, path.join(distPath, "llms.txt")];
const newUrls = newFiles
.filter((f) => {
const relative = path.relative(distPath, f);
return !existingUrls.has(`${siteUrl}/${relative}`);
})
.map((f) => {
const relative = path.relative(distPath, f);
return `<url><loc>${siteUrl}/${relative}</loc></url>`;
})
.join("");
sitemap = sitemap.replace("</urlset>", newUrls + "</urlset>");
await writeFile(sitemapPath, sitemap);
logger.info(`Added ${newFiles.length} .md URLs to sitemap`);
},
},
},
],
trailingSlash: "never",
redirects,
vite: {
server: {
watch: {
ignored: [
"./.vercel/**",
"./.vscode/**",
"./dist/**",
"./.git/**",
"**/node_modules/**",
],
},
},
plugins: [
{
name: "custom-watcher",
async configureServer(_server) {
const files = await Array.fromAsync(
glob(path.join(import.meta.dirname, "src", "**", "*.{json,ts,js}")),
);
for (const file of files) {
watchFile(file, { interval: 1000 }, async (curr, prev) => {
if (curr.mtimeMs === prev.mtimeMs) {
return;
}
for (const fileToRemove of files) {
unwatchFile(fileToRemove);
}
console.log("File modified", file);
const now = new Date();
// We `touch` the config so that astro does its thing
await utimes(import.meta.filename, now, now);
});
}
},
},
],
},
});