Files
react-test/docs/scripts/reportBrokenLinks.mts
how2ice 005cf56baf
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
init project
2025-12-12 14:26:25 +09:00

42 lines
1.4 KiB
TypeScript

import * as path from 'path';
import { crawl } from '@mui/internal-code-infra/brokenLinksChecker';
import { globby } from 'globby';
async function main() {
// The /blog/ page has pagination that's not persisted in the url.
const blogPages = await globby('blog/**/*.js', {
cwd: path.resolve(import.meta.dirname, '../pages'),
});
const blogSeedUrls = blogPages.map((page) => {
const pathname = page.replace(/(?:\/index)?\.js$/, '');
return `/${pathname}`;
});
const { issues } = await crawl({
startCommand: 'pnpm start --no-request-logging -p 3001',
host: 'http://localhost:3001/',
seedUrls: ['/', ...blogSeedUrls],
outPath: path.resolve(import.meta.dirname, '../export/material-ui/link-structure.json'),
// Target paths to ignore during link checking
ignoredPaths: [
// Internal links not on this server
// TODO: Seed crawler with stored links from e.g. mui.com/x/link-structure.json
/^\/(x|base-ui|joy-ui|store|toolpad)(\/|$)/,
],
// CSS selectors for content to ignore during link checking
ignoredContent: [
// Links used in demos under MemoryRouter
// TODO: Create an easier way to identify content under MemoryRouter
// (e.g. a class or an option on the demo)
'[id^="demo-"] a[href^="/inbox"]',
'[id^="demo-"] a[href^="/trash"]',
'[id^="demo-"] a[href^="/spam"]',
'[id^="demo-"] a[href^="/drafts"]',
],
});
process.exit(issues.length);
}
main();