-
Notifications
You must be signed in to change notification settings - Fork 18
/
docusaurus.config.js
475 lines (438 loc) · 13.3 KB
/
docusaurus.config.js
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
import versions from "./versions.json";
import old_site_redirects from "./old_site_redirects.js";
import captionedCode from "./src/remark/captioned-code.js";
import tabBlocks from "docusaurus-remark-plugin-tab-blocks";
import fs from "fs";
import fsPromises from "fs/promises";
import path from "path";
import { themes as prismThemes } from "prism-react-renderer";
const organizationName = "pantsbuild";
const projectName = "pantsbuild.org";
const numberOfSupportedStableVersions = 2;
// Controls for how much to build:
// - (No env vars set) -> Just uses the docs from `/docs/` (Docusaurus calls this "current version"), and no blog.
// - PANTSBUILD_ORG_INCLUDE_VERSIONS=<version>,<version> -> Use current version and versions specified
// - PANTSBUILD_ORG_INCLUDE_BLOG=1 -> Include the blog.
// Note that `NODE_ENV === 'production' builds _everything_.
const isDev = process.env.NODE_ENV === "development";
// Versions
const onlyIncludeVersions = isDev
? process.env.PANTSBUILD_ORG_INCLUDE_VERSIONS
? ["current"].concat(
(process.env.PANTSBUILD_ORG_INCLUDE_VERSIONS || "").split(",")
)
: ["current"]
: undefined;
// In Docusaurus terms, "current" == main == trunk == dev. It is *newer* than
// the newest in versions.json
function getCurrentVersion() {
const lastReleasedVersion = versions[0];
const version = parseInt(lastReleasedVersion.replace("2.", ""), 10);
return `2.${version + 1}`;
}
const currentVersion = getCurrentVersion();
const isCurrentVersion = (shortVersion) => shortVersion === currentVersion;
const getFullVersion = (shortVersion) => {
const parentDir = isCurrentVersion(shortVersion)
? "docs"
: path.join("versioned_docs", `version-${shortVersion}`);
const helpAll = JSON.parse(
fs.readFileSync(path.join(parentDir, "reference", "help-all.json"), "utf8")
);
const pantsVersion = helpAll["scope_to_help_info"][""]["advanced"].find(
(help) => help["config_key"] === "pants_version"
);
const hardcoded = pantsVersion["value_history"]["ranked_values"].find(
(value) => value["rank"] == "HARDCODED"
);
return hardcoded["value"];
};
const isPrereleaseVersion = (fullVersion) => {
// Check if it's one of xx.xx.0.dev0, xx.xx.0a0, xx.xx.0b0, xx.xx.0rc0, etc.
// We don't treat patch versions pre-releases as pre-releases, since it looks weird.
// Optimally we shouldn't sync those either way, but some have ended up here by accident.
const rex = /^(\d+\.\d+\.0)(\.dev|a|b|rc)\d+$/;
return rex.test(fullVersion);
};
const getVersionDetails = () => {
const versionDetails = [];
let seenStableVersions = 0;
let newestPreReleaseVersion = null;
// Construct the configuration for each version. NB. iterating from newest to oldest is important,
// to be able to label too-old stable versions as unsupported.
for (const shortVersion of [currentVersion, ...versions]) {
const fullVersion = getFullVersion(shortVersion);
// NB. "maintained" versions includes pre-releases
const isMaintained = seenStableVersions < numberOfSupportedStableVersions;
const isPrerelease = isPrereleaseVersion(fullVersion);
const isCurrent = isCurrentVersion(shortVersion);
if (!isCurrent && isPrerelease && newestPreReleaseVersion === null) {
newestPreReleaseVersion = shortVersion;
}
// compute the appropriate configuration this version
let config;
if (isCurrent) {
// current version => dev
config = {
label: `${shortVersion} (dev)`,
path: "dev",
};
} else if (isPrerelease) {
// prerelease => prerelease
config = {
label: `${shortVersion} (prerelease)`,
banner: "unreleased",
noIndex: false,
path:
shortVersion == newestPreReleaseVersion ? "prerelease" : shortVersion,
};
} else if (isMaintained) {
// a new-enough stable version => so still supported
config = {
label: shortVersion,
banner: "none",
noIndex: false,
path: seenStableVersions == 0 ? "stable" : shortVersion,
};
} else {
// stable, but too old => deprecated
config = {
label: `${shortVersion} (deprecated)`,
banner: "unmaintained",
noIndex: true,
path: shortVersion,
};
}
versionDetails.push({
shortVersion,
fullVersion,
isMaintained,
isPrerelease,
isCurrent,
config,
});
if (!isPrerelease) {
seenStableVersions += 1;
}
}
return versionDetails;
};
const versionDetails = getVersionDetails();
const mostRecentPreReleaseVersion = versionDetails.find(
(ver) => ver.isPrerelease && !ver.isCurrent
);
const mostRecentStableVersion = versionDetails.find(
({ isPrerelease }) => !isPrerelease
);
// Blog
const includeBlog = process.env.PANTSBUILD_ORG_INCLUDE_BLOG === "1" || !isDev;
// Other information
const formatCopyright = () => {
const makeLink = (href, text) => `<a href="${href}">${text}</a>`;
const repoUrl = `https://github.com/${organizationName}/${projectName}`;
const repoLink = makeLink(repoUrl, "Website source");
// Only set by CI, so fallback to just `local` for local dev
const docsCommit = process.env.GITHUB_SHA;
const commitLink = docsCommit
? makeLink(`${repoUrl}/commit/${docsCommit}`, docsCommit.slice(0, 6))
: "local";
return `Copyright © Pants project contributors. ${repoLink} @ ${commitLink}.`;
};
const config = {
title: "Pantsbuild",
tagline: "The ergonomic build system",
favicon: "img/favicon.ico",
url: "https://www.pantsbuild.org",
baseUrl: "/",
trailingSlash: false,
organizationName,
projectName,
// @TODO: This should throw on prod
onBrokenLinks: isDev ? "warn" : "warn",
onBrokenMarkdownLinks: isDev ? "warn" : "warn",
webpack: {
jsLoader: (isServer) => ({
loader: require.resolve("swc-loader"),
options: {
jsc: {
parser: {
syntax: "ecmascript",
tsx: false,
jsx: true,
},
transform: {
react: {
runtime: "automatic",
},
},
target: "es2017",
},
module: {
type: isServer ? "commonjs" : "es6",
},
},
}),
},
clientModules: ["./src/js/redirectCodeFragment.js"],
presets: [
[
"@docusaurus/preset-classic",
{
gtag: {
trackingID: "G-SEHBXJRF42",
anonymizeIP: true,
},
debug: process.env.NODE_ENV !== "production",
docs: false, // NB: See `docsPluginWithTopLevel404.js` reference below
blog: includeBlog && {
showReadingTime: true,
editUrl: `https://github.com/${organizationName}/${projectName}/edit/main/`,
remarkPlugins: [captionedCode, tabBlocks],
blogSidebarTitle: "All posts",
blogSidebarCount: "ALL",
postsPerPage: "ALL",
},
theme: {
customCss: require.resolve("./src/css/custom.css"),
},
},
],
],
themeConfig: {
// Temporary: Announce the 2024 User Survey.
announcementBar: {
content:
'The Pantsbuild 2024 User Survey is live! Check out the <a href="/blog/2024/10/08/user-survey-2024">blog post</a> or <a target="_blank" href="https://forms.gle/eo7Y4DuxurjaMSZn6">take the survey</a>.',
},
image: "img/social-card.png",
navbar: {
title: "Pantsbuild",
logo: {
alt: "My Site Logo",
src: "img/logo.svg",
},
items: [
{
type: "docSidebar",
position: "left",
sidebarId: "docsSidebar",
label: "Docs",
},
{
type: "docSidebar",
position: "left",
sidebarId: "referenceSidebar",
label: "Reference",
},
{ to: "/blog", label: "Blog", position: "left" },
{ to: "/sponsors", label: "Sponsors", position: "left" },
// Right
{
type: "docsVersionDropdown",
position: "right",
dropdownActiveClassDisabled: true,
dropdownItemsAfter: [
{ type: "html", value: '<hr class="dropdown-separator">' },
{ to: "/versions", label: "All Versions" },
],
},
{
type: "dropdown",
label: "Slack",
position: "right",
items: [
{
label: "Workspace",
href: "https://pantsbuild.slack.com",
},
{
label: "Workspace Invite",
href: "https://docs.google.com/forms/d/e/1FAIpQLSf9zgf-MXRnVDJbrVEST3urqneq7LCcy0zw8qU-GH4hPMn52A/viewform?usp=sf_link",
},
{
label: "Linen Mirror",
href: "https://chat.pantsbuild.org",
},
],
},
{
href: "https://github.com/pantsbuild/pants",
label: "GitHub",
position: "right",
},
{
type: "search",
position: "right",
},
],
},
footer: {
style: "dark",
links: [
{
title: "Spotlight",
items: [
{
label: "Users",
to: "/spotlight/users",
},
{
label: "Testimonials",
to: "/spotlight/testimonials",
},
{
label: "Media",
to: "/spotlight/media",
},
{
label: "Service Providers",
to: "/spotlight/service-providers",
},
],
},
{
title: "Connect",
items: [
{
label: "GitHub",
href: "https://github.com/pantsbuild/pants",
},
{
label: "Twitter",
href: "https://twitter.com/pantsbuild",
},
{
label: "YouTube",
href: "https://www.youtube.com/@pantsbuild",
},
{
label: "Mailing List",
href: "https://groups.google.com/forum/#!forum/pants-devel",
},
],
},
{
title: "More",
items: [
{
label: "Blog",
to: "/blog",
},
{
label: "Sponsors",
href: "/sponsors",
},
],
},
{
title: "Community",
items: [
{
label: "Getting Help",
href: "/community/getting-help",
},
{
label: "Members",
href: "/community/members",
},
{
label: "Code of Conduct",
href: "/community/code-of-conduct",
},
{
label: "Meet the Team",
href: "/community/meet-the-team",
},
{
label: "Maintainers",
href: "/community/maintainers",
},
{
label: "Contentious Decisions",
href: "/community/contentious-decisions",
},
],
},
],
copyright: formatCopyright(),
},
algolia: {
appId: "QD9KY1TRVK",
apiKey: "487e5f50fad326e6126bf593c06b3310",
indexName: "pantsbuild",
contextualSearch: true,
},
prism: {
additionalLanguages: [
"bash",
"docker",
"go",
"ini",
"java",
"json",
"log",
"protobuf",
"python",
"shell-session",
"toml",
// TODO: Add thrift once supported: https://github.com/PrismJS/prism/issues/3641
],
// NB: Not all themes support shell-session well. Check before you change this.
theme: prismThemes.palenight,
darkTheme: prismThemes.nightOwl,
},
},
plugins: [
[
"./src/js/docsPluginWithTopLevel404.js",
{
sidebarPath: require.resolve("./sidebars.js"),
routeBasePath: "/",
onlyIncludeVersions,
lastVersion: onlyIncludeVersions
? undefined
: mostRecentStableVersion.shortVersion,
versions: Object.fromEntries(
versionDetails.map(({ isCurrent, shortVersion, config }) => [
isCurrent ? "current" : shortVersion,
config,
])
),
remarkPlugins: [captionedCode, tabBlocks],
editUrl: ({ docPath }) => {
if (docPath.startsWith("reference/")) {
return undefined;
}
return `https://github.com/pantsbuild/pants/edit/main/docs/${docPath}`;
},
},
],
[
"@docusaurus/plugin-client-redirects",
{
redirects: old_site_redirects,
createRedirects(existingPath) {
if (existingPath.startsWith("/dev/")) {
return [existingPath.replace("/dev/", `/${currentVersion}/`)];
} else if (existingPath.startsWith("/prerelease/")) {
return [
existingPath.replace(
"/prerelease/",
`/${mostRecentPreReleaseVersion.shortVersion}/`
),
];
} else if (existingPath.startsWith("/stable/")) {
return [
existingPath.replace(
"/stable/",
`/${mostRecentStableVersion.shortVersion}/`
),
];
}
return undefined;
},
},
],
],
};
module.exports = config;