Repository: mui/material-ui
File: docs/packages/markdown/parseMarkdown.js (JavaScript)

Code before:
  const headingHashes = {};

  translations
    // Process the English markdown before the other locales.
    // English ToC anchor links are used in all languages
    .sort((a) => (a.userLanguage === 'en' ? -1 : 1))
    .forEach((translation) => {
      const { filename, markdown, userLanguage } = translation;
      const headers = getHeaders(markdown);
      const location = headers.filename || `/docs${pageFilename}/${filename}`;
      const title = headers.title || getTitle(markdown);
      const description = headers.description || getDescription(markdown);

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

      if (title.length > 60) {
        throw new Error(
          [
            `The title "${title}" is too long (${title.length} characters).`,
            'It needs to have fewer than 60 characters, see for more details:',
            '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}`);
      }

      const contents = getContents(markdown);

      if (headers.unstyled) {
        contents.push(`
## Unstyled

The component also comes with an [unstyled version](${headers.unstyled}). It's ideal for doing heavy customizations and minimizing bundle size.
        `);
      }

      if (headers.components.length > 0) {
        contents.push(`
## API

${headers.components
  .map((component) => {
    const componentPkgMap = componentPackageMapping[headers.product];
    const componentPkg = componentPkgMap ? componentPkgMap[component] : null;
    return `- [\`<${component} />\`](${resolveComponentApiUrl(
      headers.product,

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

Code after:
  const headingHashes = {};

  translations
    // Process the English markdown before the other locales.
    // English ToC anchor links are used in all languages
    .sort((a) => (a.userLanguage === 'en' ? -1 : 1))
    .forEach((translation) => {
      const { filename, markdown, userLanguage } = translation;
      const headers = getHeaders(markdown);
      const location = headers.filename || `/docs${pageFilename}/${filename}`;
      const title = headers.title || getTitle(markdown);
      const description = headers.description || getDescription(markdown);

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

      if (title.length > 70) {
        throw new Error(
          [
            `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}`);
      }

      const contents = getContents(markdown);

      if (headers.unstyled) {
        contents.push(`
## Unstyled

The component also comes with an [unstyled version](${headers.unstyled}). It's ideal for doing heavy customizations and minimizing bundle size.
        `);
      }

      if (headers.components.length > 0) {
        contents.push(`
## API

${headers.components
  .map((component) => {
    const componentPkgMap = componentPackageMapping[headers.product];
    const componentPkg = componentPkgMap ? componentPkgMap[component] : null;
    return `- [\`<${component} />\`](${resolveComponentApiUrl(
      headers.product,