Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
// @ts-check
|
|
import path from 'path';
|
|
import fs from 'node:fs/promises';
|
|
import { pageToTitle } from 'docs/src/modules/utils/helpers';
|
|
import materialPages from 'docs/data/material/pages';
|
|
import systemPages from 'docs/data/system/pages';
|
|
import joyPages from 'docs/data/joy/pages';
|
|
import { MuiPage } from 'docs/src/MuiPage';
|
|
|
|
const EXCLUDES = ['/api', '/blog', '/x/react-', '/toolpad'];
|
|
|
|
async function run() {
|
|
const translationsFilename = path.join(__dirname, '../translations/translations.json');
|
|
const translationsFile = await fs.readFile(translationsFilename, 'utf8');
|
|
/**
|
|
* @type {{ pages: Record<String, string> }}
|
|
*/
|
|
const output = JSON.parse(translationsFile);
|
|
output.pages = {};
|
|
|
|
/**
|
|
* @param {readonly import('docs/src/MuiPage').MuiPage[]} pages
|
|
*/
|
|
const traverse = (pages: MuiPage[]) => {
|
|
pages.forEach((page) => {
|
|
if (
|
|
(page.pathname !== '/' && page.pathname === '/api-docs') ||
|
|
!EXCLUDES.some((exclude) => page.pathname.includes(exclude))
|
|
) {
|
|
const title = pageToTitle(page);
|
|
|
|
if (title) {
|
|
const pathname = page.subheader || page.pathname;
|
|
output.pages[pathname] = title;
|
|
}
|
|
}
|
|
|
|
if (page.children) {
|
|
traverse(page.children);
|
|
}
|
|
});
|
|
};
|
|
|
|
traverse([...systemPages, ...materialPages, ...joyPages]);
|
|
|
|
await fs.writeFile(translationsFilename, `${JSON.stringify(output, null, 2)}\n`);
|
|
}
|
|
|
|
run().catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|