Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Check link validity in PR #6497

Merged
merged 8 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ jobs:
- run:
name: '`yarn l10n` changes committed?'
command: git diff --exit-code
- run:
name: '`yarn docs:link-check` changes committed?'
command: |
yarn docs:link-check
git diff --exit-code
test_browser:
<<: *defaults
docker:
Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const defaultAlias = {
'@mui/x-license-pro': resolveAliasPath('./packages/x-license-pro/src'),
'@mui/x-date-pickers': resolveAliasPath('./packages/x-date-pickers/src'),
'@mui/x-date-pickers-pro': resolveAliasPath('./packages/x-date-pickers-pro/src'),
'@mui/markdown': '@mui/monorepo/docs/packages/markdown',
'typescript-to-proptypes': '@mui/monorepo/packages/typescript-to-proptypes/src',
docs: resolveAliasPath('./node_modules/@mui/monorepo/docs'),
test: resolveAliasPath('./test'),
Expand Down
6 changes: 6 additions & 0 deletions docs/.link-check-errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Broken links found by `yarn docs:link-check` that exist:

- https://mui.com/blog/material-ui-v4-is-out/#premium-themes-store-✨
- https://mui.com/size-snapshot
- https://mui.com/x/react-data-grid/migration-v4
- https://mui.com/x/react-date-pickers/migration-lab
2 changes: 1 addition & 1 deletion docs/data/data-grid/components/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The grid exposes two hooks to help you to access the grid data while overriding

They can be used as below:

- `useGridApiContext`: returns the `apiRef` object (more details in the [API object page](/x/react-data-grid/api-object/#use-it-inside-the-grid)).
- `useGridApiContext`: returns the `apiRef` object (more details in the [API object page](/x/react-data-grid/api-object/#inside-the-data-grid)).
- `useGridSelector`: returns the result of a selector on the current state (more details in the [State page](/x/react-data-grid/state/#access-the-state)).

```tsx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Most breaking changes are renaming of CSS classes or variables to improve the co
Using MUI Core v4 with v5 can be achieved with the following steps:

1. First, make sure you have MUI Core v5 installed. If not, install it with these [instructions](/material-ui/getting-started/installation/).
1. Add a custom [`createGenerateClassName`](/system/styles/api/#heading-creategenerateclassname-options-class-name-generator) to disable the generation of global class names in JSS.
1. Add a custom [`createGenerateClassName`](/system/styles/api/#creategenerateclassname-options-class-name-generator) to disable the generation of global class names in JSS.

```jsx
import { createGenerateClassName } from '@material-ui/core/styles';
Expand Down
68 changes: 68 additions & 0 deletions docs/scripts/reportBrokenLinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-disable no-console */
const path = require('path');
const fse = require('fs-extra');
const { parseDocFolder, getAnchor } = require('@mui/monorepo/docs/scripts/reportBrokenLinks');

const docsSpaceRoot = path.join(__dirname, '../');

function save(lines) {
const fileContents = [...lines, ''].join('\n');
fse.writeFileSync(path.join(docsSpaceRoot, '.link-check-errors.txt'), fileContents);
}

const UNSUPPORTED_PATHS = ['/api/', '/careers/', '/store/'];

const buffer = [];

function write(text) {
buffer.push(text);
}

// {[url with hash]: true}
const availableLinksX = {};
const availableLinksCore = {};

// {[url with hash]: list of files using this link}
const usedLinksX = {};
const usedLinksCore = {};

parseDocFolder(path.join(docsSpaceRoot, './pages/'), availableLinksX, usedLinksX, '');
parseDocFolder(
path.resolve(__dirname, '../../node_modules/@mui/monorepo/docs/pages/'),
availableLinksCore,
usedLinksCore,
'',
);

function getPageUrlFromLink(link) {
const [rep] = link.split('/#');
return rep;
}

const usedLinks = { ...usedLinksCore, ...usedLinksX };
const availableLinks = { ...availableLinksCore, ...availableLinksX };

write('Broken links found by `yarn docs:link-check` that exist:\n');
Object.keys(usedLinks)
.filter((link) => link.startsWith('/'))
.filter((link) => !availableLinks[link])
// unstyled sections are added by scripts (can not be found in markdown)
.filter((link) => !link.includes('#unstyled'))
.filter((link) => UNSUPPORTED_PATHS.every((unsupportedPath) => !link.includes(unsupportedPath)))
.sort()
.forEach((linkKey) => {
write(`- https://mui.com${linkKey}`);
console.log(`https://mui.com${linkKey}`);
console.log(`used in`);
usedLinks[linkKey].forEach((f) => console.log(`- ${path.relative(docsSpaceRoot, f)}`));
console.log('available anchors on the same page:');
console.log(
Object.keys(availableLinks)
.filter((link) => getPageUrlFromLink(link) === getPageUrlFromLink(linkKey))
.sort()
.map(getAnchor)
.join('\n'),
);
console.log('\n\n');
});
save(buffer);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"docs:create-playground": "yarn workspace docs create-playground",
"docs:api": "yarn docs:api:build",
"docs:api:build": "cross-env BABEL_ENV=development babel-node -i \"/node_modules/(?!@mui)/\" -x .ts,.tsx,.js ./docs/scripts/api/buildApi.ts",
"docs:link-check": "cross-env BABEL_ENV=development babel-node -i \"/node_modules/(?!@mui)/\" --extensions \".tsx,.ts,.js\" ./docs/scripts/reportBrokenLinks.js",
"docs:build": "yarn workspace docs build",
"docs:export": "yarn workspace docs export",
"docs:typescript:formatted": "yarn workspace docs typescript:transpile",
Expand Down