Skip to content

Commit

Permalink
[docs-infra] Mandatory versions
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jun 4, 2023
1 parent 4b4b2fe commit fb85b7a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 27 deletions.
33 changes: 28 additions & 5 deletions docs/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ function AppWrapper(props) {

if (product === 'material-ui') {
return {
name: 'Material UI',
metadata: 'MUI Core',
name: 'Material UI',
versions: [
{ text: `v${materialPkgJson.version}`, current: true },
{
Expand All @@ -169,16 +169,16 @@ function AppWrapper(props) {

if (product === 'joy-ui') {
return {
name: 'Joy UI',
metadata: 'MUI Core',
name: 'Joy UI',
versions: [{ text: `v${joyPkgJson.version}`, current: true }],
};
}

if (product === 'system') {
return {
name: 'MUI System',
metadata: 'MUI Core',
name: 'MUI System',
versions: [
{ text: `v${systemPkgJson.version}`, current: true },
{ text: 'v4', href: `https://v4.mui.com${languagePrefix}/system/basics/` },
Expand All @@ -192,13 +192,36 @@ function AppWrapper(props) {

if (product === 'base') {
return {
name: 'Base UI',
metadata: 'MUI Core',
name: 'Base UI',
versions: [{ text: `v${basePkgJson.version}`, current: true }],
};
}

return null; // The identifier for X and Toolpad is handled by their own site
if (product === 'core') {
return {
metadata: '',
name: 'MUI Core',
versions: [
{ text: `v${materialPkgJson.version}`, current: true },
{
text: 'View all versions',
href: `https://mui.com${languagePrefix}/versions/`,
},
],
};
}

return {
metadata: '',
name: 'Docs-infra',
versions: [
{
text: 'v0.0.0',
href: `https://mui.com${languagePrefix}/versions/`,
},
],
};
}, [pageProps.userLanguage, product]);

const pageContextValue = React.useMemo(() => {
Expand Down
30 changes: 18 additions & 12 deletions docs/src/modules/components/AppNavDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ ProductDrawerButton.propTypes = {
productName: PropTypes.string,
};

function ProductIdentifier({ name, metadata, versionSelector }) {
function ProductIdentifier(props) {
const { name, metadata, versionSelector } = props;
return (
<Box sx={{ flexGrow: 1 }}>
<Typography
Expand All @@ -114,8 +115,8 @@ function ProductIdentifier({ name, metadata, versionSelector }) {

ProductIdentifier.propTypes = {
metadata: PropTypes.string,
name: PropTypes.string,
versionSelector: PropTypes.element,
name: PropTypes.string.isRequired,
versionSelector: PropTypes.element.isRequired,
};

// To match scrollMarginBottom
Expand Down Expand Up @@ -401,15 +402,11 @@ export default function AppNavDrawer(props) {
<SvgMuiLogo width={30} />
</Box>
</NextLink>
{productIdentifier && (
<ProductIdentifier
name={productIdentifier.name}
metadata={productIdentifier.metadata}
versionSelector={
productIdentifier.versions ? renderVersionSelector(productIdentifier.versions) : []
}
/>
)}
<ProductIdentifier
name={productIdentifier.name}
metadata={productIdentifier.metadata}
versionSelector={renderVersionSelector(productIdentifier.versions)}
/>
</ToolbarDiv>
<Divider
sx={(theme) => ({
Expand All @@ -425,6 +422,15 @@ export default function AppNavDrawer(props) {
);
}, [onClose, pages, activePageParents, t, productIdentifier, anchorEl]);

if (process.env.NODE_ENV !== 'production') {
if (!productIdentifier) {
throw new Error('docs-infra: missing productIdentifier in PageContext');
}
if (!productIdentifier.versions) {
throw new Error('docs-infra: missing productIdentifier.versions in PageContext');
}
}

return (
<nav className={className} aria-label={t('mainNavigation')}>
{disablePermanent || mobile ? (
Expand Down
18 changes: 15 additions & 3 deletions docs/src/modules/utils/useRouterExtra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@ export default function useRouterExtra() {
const router = useRouter();

const asPathWithoutLang = router.asPath.replace(/^\/+[a-zA-Z]{2}\//, '/');
let product = asPathWithoutLang.replace(/^\/+([^/]+)\/.*/, '$1');
const firstFolder = asPathWithoutLang.replace(/^\/+([^/]+)\/.*/, '$1');
let product = firstFolder;
if (asPathWithoutLang.startsWith('/x/')) {
product = asPathWithoutLang.replace('/x/react-', '').replace(/\/.*/, '');
}

if (asPathWithoutLang === '/versions/') {
product = 'core';
}

return {
...router,
asPathWithoutLang,
product: product as 'base' | 'material-ui' | 'joy-ui' | 'system' | 'data-grid' | 'date-pickers',
isMuiX: asPathWithoutLang.startsWith('/x'),
product: product as
| 'core'
| 'base'
| 'material-ui'
| 'joy-ui'
| 'system'
| 'data-grid'
| 'date-pickers',
};
}
16 changes: 9 additions & 7 deletions packages/markdown/parseMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function checkUrlHealth(href, linkText, context) {
if (url.pathname[url.pathname.length - 1] !== '/') {
throw new Error(
[
'Missing trailing slash. The following link:',
'docs-infra: Missing trailing slash. The following link:',
`[${linkText}](${href}) in ${context.location} is missing a trailing slash, please add it.`,
'',
'See https://ahrefs.com/blog/trailing-slash/ for more details.',
Expand All @@ -76,7 +76,7 @@ function checkUrlHealth(href, linkText, context) {
if (href[0] !== '/') {
throw new Error(
[
'Missing leading slash. The following link:',
'docs-infra: Missing leading slash. The following link:',
`[${linkText}](${href}) in ${context.location} is missing a leading slash, please add it.`,
'',
].join('\n'),
Expand Down Expand Up @@ -150,7 +150,9 @@ function getHeaders(markdown) {

return headers;
} catch (err) {
throw new Error(`${err.message} in getHeader(markdown) with markdown: \n\n${header}`);
throw new Error(
`docs-infra: ${err.message} in getHeader(markdown) with markdown: \n\n${header}`,
);
}
}

Expand Down Expand Up @@ -274,7 +276,7 @@ function createRender(context) {
});
} else if (level === 3) {
if (!toc[toc.length - 1]) {
throw new Error(`Missing parent level for: ${headingText}`);
throw new Error(`docs-infra: Missing parent level for: ${headingText}`);
}

toc[toc.length - 1].children.push({
Expand Down Expand Up @@ -449,21 +451,21 @@ function prepareMarkdown(config) {
const description = headers.description || getDescription(markdown);

if (title == null || title === '') {
throw new Error(`Missing title in the page: ${location}`);
throw new Error(`docs-infra: Missing title in the page: ${location}`);
}

if (title.length > 70) {
throw new Error(
[
`The title "${title}" is too long (${title.length} characters).`,
`docs-infra: The title "${title}" is too long (${title.length} characters).`,
'It needs to have fewer than 70 characters—ideally less than 60. For more details, see:',
'https://developers.google.com/search/docs/advanced/appearance/title-link',
].join('\n'),
);
}

if (description == null || description === '') {
throw new Error(`Missing description in the page: ${location}`);
throw new Error(`docs-infra: Missing description in the page: ${location}`);
}

const contents = getContents(markdown);
Expand Down

0 comments on commit fb85b7a

Please sign in to comment.