Skip to content

Commit 13679a7

Browse files
committed
Make sidebar loading resilient for builds
1 parent 83b4798 commit 13679a7

File tree

6 files changed

+90
-18
lines changed

6 files changed

+90
-18
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ $ npm run typecheck
3232

3333
This runs TypeScript checks using the project `tsconfig.json` (which extends the Docusaurus base config).
3434

35+
### Sidebar Checks
36+
37+
```
38+
$ npm run test:sidebars
39+
```
40+
41+
This verifies that API sidebar modules can be loaded from either `.js` or `.ts` files.
42+
3543
### Deployment
3644

3745
Using SSH:

TODO.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
- [x] 2026-02-05 Bump docs version to 3.12.0 and refresh the Version Notice with the Monitor API guide.
44
- [x] 2026-02-05 Fix typecheck by aligning tsconfig/types and sidebar imports.
5+
- [x] 2026-02-05 Make sidebar loading resilient to .js/.ts generation differences and add a test.
6+
- [x] 2026-02-05 Bump patch version to 3.12.1 for sidebar build fix.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docs",
3-
"version": "3.12.0",
3+
"version": "3.12.1",
44
"private": true,
55
"scripts": {
66
"docusaurus": "docusaurus",
@@ -10,6 +10,7 @@
1010
"deploy": "docusaurus deploy",
1111
"clear": "docusaurus clear",
1212
"serve": "docusaurus serve",
13+
"test:sidebars": "node scripts/sidebars-utils.test.js",
1314
"write-translations": "docusaurus write-translations",
1415
"write-heading-ids": "docusaurus write-heading-ids",
1516
"typecheck": "tsc"

scripts/sidebars-utils.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
function loadSidebar(relativePathBase) {
5+
const jsPath = `${relativePathBase}.js`;
6+
const tsPath = `${relativePathBase}.ts`;
7+
const absJsPath = path.resolve(__dirname, "..", jsPath);
8+
const absTsPath = path.resolve(__dirname, "..", tsPath);
9+
10+
if (fs.existsSync(absJsPath)) {
11+
const mod = require(absJsPath);
12+
return mod.default ?? mod;
13+
}
14+
15+
if (fs.existsSync(absTsPath)) {
16+
const mod = require(absTsPath);
17+
return mod.default ?? mod;
18+
}
19+
20+
throw new Error(
21+
`Sidebar module not found. Tried ${absJsPath} and ${absTsPath}.`
22+
);
23+
}
24+
25+
module.exports = {
26+
loadSidebar,
27+
};

scripts/sidebars-utils.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const assert = require("assert");
2+
const { loadSidebar } = require("./sidebars-utils");
3+
4+
const sidebarPaths = [
5+
"./docs/api/agent/sidebar",
6+
"./docs/api/analysis/sidebar",
7+
"./docs/api/audit/sidebar",
8+
"./docs/api/classification/sidebar",
9+
"./docs/api/content-evaluations/sidebar",
10+
"./docs/api/content-generation/sidebar",
11+
"./docs/api/events/sidebar",
12+
"./docs/api/fact-check/sidebar",
13+
"./docs/api/graphql/sidebar",
14+
"./docs/api/gsc-url-inspections/sidebar",
15+
"./docs/api/inspector/sidebar",
16+
"./docs/api/long-tail/sidebar",
17+
"./docs/api/manager/sidebar",
18+
"./docs/api/middleware/sidebar",
19+
"./docs/api/query-fan-out/sidebar",
20+
"./docs/api/sitemap-generator/sidebar",
21+
"./docs/api/summarizer/sidebar",
22+
];
23+
24+
for (const sidebarPath of sidebarPaths) {
25+
const loaded = loadSidebar(sidebarPath);
26+
assert.ok(
27+
Array.isArray(loaded),
28+
`Expected ${sidebarPath} to resolve to an array.`
29+
);
30+
}
31+
32+
console.log("sidebars-utils.test.js: all sidebar modules resolved.");

sidebars.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// @ts-check
22

3+
const { loadSidebar } = require("./scripts/sidebars-utils");
4+
35
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
46
const sidebars = {
57
docs: [
@@ -241,87 +243,87 @@ const sidebars = {
241243
{
242244
type: "category",
243245
label: "Agent WordLift",
244-
items: require("./docs/api/agent/sidebar.js").default,
246+
items: loadSidebar("./docs/api/agent/sidebar"),
245247
},
246248
{
247249
type: "category",
248250
label: "Audit",
249-
items: require("./docs/api/audit/sidebar.js").default,
251+
items: loadSidebar("./docs/api/audit/sidebar"),
250252
},
251253
{
252254
type: "category",
253255
label: "Analysis",
254-
items: require("./docs/api/analysis/sidebar.js").default,
256+
items: loadSidebar("./docs/api/analysis/sidebar"),
255257
},
256258
{
257259
type: "category",
258260
label: "Classification",
259-
items: require("./docs/api/classification/sidebar.js").default,
261+
items: loadSidebar("./docs/api/classification/sidebar"),
260262
},
261263
{
262264
type: "category",
263265
label: "Content Generation",
264-
items: require("./docs/api/content-generation/sidebar.js").default,
266+
items: loadSidebar("./docs/api/content-generation/sidebar"),
265267
},
266268
{
267269
type: "category",
268270
label: "Content Evaluations",
269-
items: require("./docs/api/content-evaluations/sidebar.js").default,
271+
items: loadSidebar("./docs/api/content-evaluations/sidebar"),
270272
},
271273
{
272274
type: "category",
273275
label: "Fact Check",
274-
items: require("./docs/api/fact-check/sidebar.js").default,
276+
items: loadSidebar("./docs/api/fact-check/sidebar"),
275277
},
276278
{
277279
type: "category",
278280
label: "GraphQL",
279-
items: require("./docs/api/graphql/sidebar.js").default,
281+
items: loadSidebar("./docs/api/graphql/sidebar"),
280282
},
281283
{
282284
type: "category",
283285
label: "Inspector",
284-
items: require("./docs/api/inspector/sidebar.js").default,
286+
items: loadSidebar("./docs/api/inspector/sidebar"),
285287
},
286288
{
287289
type: "category",
288290
label: "KPI Events",
289-
items: require("./docs/api/events/sidebar.js").default,
291+
items: loadSidebar("./docs/api/events/sidebar"),
290292
},
291293
{
292294
type: "category",
293295
label: "Long Tail",
294-
items: require("./docs/api/long-tail/sidebar.js").default,
296+
items: loadSidebar("./docs/api/long-tail/sidebar"),
295297
},
296298
{
297299
type: "category",
298300
label: "Manager",
299-
items: require("./docs/api/manager/sidebar.js").default,
301+
items: loadSidebar("./docs/api/manager/sidebar"),
300302
},
301303
{
302304
type: "category",
303305
label: "Google Search Console",
304-
items: require("./docs/api/gsc-url-inspections/sidebar.js").default,
306+
items: loadSidebar("./docs/api/gsc-url-inspections/sidebar"),
305307
},
306308
{
307309
type: "category",
308310
label: "Middleware",
309-
items: require("./docs/api/middleware/sidebar.js").default,
311+
items: loadSidebar("./docs/api/middleware/sidebar"),
310312
},
311313
{
312314
type: "category",
313315
label: "Summarization",
314-
items: require("./docs/api/summarizer/sidebar.js").default,
316+
items: loadSidebar("./docs/api/summarizer/sidebar"),
315317
},
316318
{
317319
type: "category",
318320
label: "Sitemap Generator",
319-
items: require("./docs/api/sitemap-generator/sidebar.js").default,
321+
items: loadSidebar("./docs/api/sitemap-generator/sidebar"),
320322
},
321323
{
322324
type: "category",
323325
label: "Query Fan-Out",
324-
items: require("./docs/api/query-fan-out/sidebar.js").default,
326+
items: loadSidebar("./docs/api/query-fan-out/sidebar"),
325327
},
326328
],
327329
},

0 commit comments

Comments
 (0)