-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsidebars.js
More file actions
124 lines (112 loc) · 3.81 KB
/
Copy pathsidebars.js
File metadata and controls
124 lines (112 loc) · 3.81 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
// @ts-check
// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)
/**
* Dynamic sidebar generator.
*
* This file programmatically inspects the `docs/` directory and generates sidebar
* categories for top-level folders that contain documentation. It preserves the
* generated-index link pattern and tries to create deterministic ordering.
*
* If you need fully manual control over a specific category, replace or edit
* the generated block below.
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const DOCS_DIR = path.join(__dirname, 'docs');
// Friendly overrides for some category labels shown in the sidebar.
/** @type {{[key:string]: string}} */
const LABEL_OVERRIDES = {
projects: 'Projects',
repositories: 'Repositories',
technologies: 'Technologies & Stack',
guidelines: 'Guidelines & Standards',
identity: 'Visual Identity & UI Components',
contribution: 'Contribution & Governance',
architecture: 'Architecture',
};
/**
* Read optional `_category_.json` metadata for a docs folder.
* @param {string} dir
*/
function readCategoryMeta(dir) {
try {
const p = path.join(DOCS_DIR, dir, '_category_.json');
if (fs.existsSync(p)) return JSON.parse(fs.readFileSync(p, 'utf8'));
} catch (e) {
// ignore
}
const defaultLabel = dir.replace(/-/g, ' ').replace(/\b\w/g, (s) => s.toUpperCase());
return { label: LABEL_OVERRIDES[dir] || defaultLabel };
}
/**
* List docs in a directory and normalize to sidebar ids.
* @param {string} dir
* @returns {string[]}
*/
function listDocsInDir(dir) {
const base = path.join(DOCS_DIR, dir);
if (!fs.existsSync(base)) return [];
const entries = fs.readdirSync(base, { withFileTypes: true });
const items = [];
for (const ent of entries) {
if (ent.name === '_category_.json') continue;
const full = path.join(base, ent.name);
if (ent.isFile() && /\.(md|mdx)$/.test(ent.name)) {
const id = `${dir}/${ent.name.replace(/\.(md|mdx)$/, '')}`;
items.push(id);
} else if (ent.isDirectory()) {
// prefer directory index.md/mdx
const idxMd = path.join(full, 'index.md');
const idxMdx = path.join(full, 'index.mdx');
if (fs.existsSync(idxMd) || fs.existsSync(idxMdx)) {
items.push(`${dir}/${ent.name}/index`);
} else {
const subfiles = fs.readdirSync(full).filter((n) => /\.(md|mdx)$/.test(n));
subfiles.forEach((sf) => items.push(`${dir}/${ent.name}/${sf.replace(/\.(md|mdx)$/, '')}`));
}
}
}
// dedupe items (avoid duplicates when both index.md and index.mdx exist)
const uniqueItems = Array.from(new Set(items));
// replace items with unique list
items.length = 0;
uniqueItems.forEach((i) => items.push(i));
// deterministic ordering: index first, then alpha
items.sort((a, b) => {
if (a.endsWith('/index') && !b.endsWith('/index')) return -1;
if (b.endsWith('/index') && !a.endsWith('/index')) return 1;
return a.localeCompare(b);
});
return items;
}
// Top-level folders we want to expose in the sidebar (in desired order).
const TOP_FOLDERS = [
'projects',
'repositories',
'technologies',
'guidelines',
'identity',
'contribution',
'architecture',
];
/** @type {any[]} */
const tutorialSidebar = ['intro', 'content-audit-2025-11'];
for (const folder of TOP_FOLDERS) {
const items = listDocsInDir(folder);
if (items.length === 0) continue;
const meta = readCategoryMeta(folder);
tutorialSidebar.push({
type: 'category',
label: meta.label || folder,
link: {
type: 'generated-index',
description: (meta.link && meta.link.description) || `Documentation for ${meta.label || folder}`,
},
items,
});
}
const sidebars = { tutorialSidebar };
export default sidebars;