Files
dashy/sidebars.js
2026-07-10 20:38:14 +01:00

54 lines
1.9 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const DOCS_DIR = path.join(__dirname, 'docs');
const labelFor = (id) => id
.split('-')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
// Docs with a same-named folder of sub-pages become expandable categories (readme stubs don't count)
const withSubPages = (id) => {
if (typeof id !== 'string') return id;
const dir = path.join(DOCS_DIR, id);
const hasSubPages = fs.existsSync(dir) && fs.readdirSync(dir)
.some((file) => /\.mdx?$/i.test(file) && !/^readme\.mdx?$/i.test(file));
if (!hasSubPages) return id;
return {
type: 'category',
label: labelFor(id),
link: { type: 'doc', id },
items: [{ type: 'autogenerated', dirName: id }],
};
};
const categories = {
'Running Dashy': ['quick-start', 'deployment', 'configuring', 'management', 'troubleshooting'],
'Feature Docs': [
'icons', 'widgets', 'theming', 'status-indicators', 'authentication',
'searching', 'alternate-views', 'multi-language-support', 'backup-restore',
'pages-and-sections', 'api',
],
'Community': ['showcase', 'contributing', 'developing', 'development-guides', 'credits'],
'Misc': ['privacy', 'security', 'license', 'release-workflow'],
};
// Any new doc that hasn't been assigned a category yet lands in Misc, so nothing goes missing
const listed = new Set(Object.values(categories).flat());
const unlisted = fs.readdirSync(DOCS_DIR)
.filter((file) => /\.mdx?$/i.test(file) && !/^readme\.mdx?$/i.test(file))
.map((file) => file.replace(/\.mdx?$/i, ''))
.filter((id) => !listed.has(id))
.sort();
categories.Misc.push(...unlisted);
// The footer in docusaurus.config.js is generated from this export, keeping the two in sync
module.exports = {
dashySidebar: Object.entries(categories).map(([label, ids]) => ({
type: 'category',
label,
items: ids.map(withSubPages),
})),
};