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
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
interface MarkdownPage {
|
|
filename: string;
|
|
pathname: string;
|
|
}
|
|
|
|
/**
|
|
* Returns the markdowns of the documentation in a flat array.
|
|
*/
|
|
export default function findPagesMarkdown(
|
|
directory: string = path.resolve(__dirname, '../../../docs/data'),
|
|
pagesMarkdown: MarkdownPage[] = [],
|
|
) {
|
|
const items = fs.readdirSync(directory);
|
|
|
|
items.forEach((item) => {
|
|
const filename = path.resolve(directory, item);
|
|
|
|
if (fs.statSync(filename).isDirectory()) {
|
|
findPagesMarkdown(filename, pagesMarkdown);
|
|
return;
|
|
}
|
|
|
|
// Ignore non en-US source markdown.
|
|
if (!/\.mdx?$/.test(item) || /-(zh|pt)\.mdx?/.test(item)) {
|
|
return;
|
|
}
|
|
|
|
let pathname = filename
|
|
.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
|
.replace(/^.*\/data/, '')
|
|
.replace(/\.mdx?/, '');
|
|
|
|
// Remove the last pathname segment.
|
|
pathname = pathname
|
|
.split('/')
|
|
.slice(0, pathname.split('/').length - 1)
|
|
.join('/');
|
|
|
|
pagesMarkdown.push({
|
|
// Relative location of the markdown file in the file system.
|
|
filename,
|
|
// Relative location of the page in the URL.
|
|
pathname,
|
|
});
|
|
});
|
|
|
|
return pagesMarkdown;
|
|
}
|