Skip to content

Commit

Permalink
Added check for duplicated slugs during manifest.json generation (Wor…
Browse files Browse the repository at this point in the history
…dPress#61332)

Co-authored-by: juanmaguitar <[email protected]>
Co-authored-by: oandregal <[email protected]>
  • Loading branch information
3 people authored May 3, 2024
1 parent 7cd9b5e commit 0612581
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/tool/manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint no-console: [ 'error', { allow: [ 'error' ] } ] */

/**
* External dependencies
*/
Expand Down Expand Up @@ -124,6 +126,29 @@ function generateRootManifestFromTOCItems( items, parent = null ) {
pageItems = pageItems.concat( getPackageManifest( packagePaths ) );
}
} );

const slugs = pageItems.map( ( { slug } ) => slug );
const duplicatedSlugs = slugs.filter(
( item, idx ) => idx !== slugs.indexOf( item )
);

const FgRed = '\x1b[31m';
const Reset = '\x1b[0m';

if ( duplicatedSlugs.length > 0 ) {
console.error(
`${ FgRed } The handbook generation setup creates pages based on their slug, so each slug has to be unique. ${ Reset }`
);
console.error(
`${ FgRed } More info at https://github.com/WordPress/gutenberg/issues/61206#issuecomment-2085361154 ${ Reset }\n`
);
throw new Error(
`${ FgRed } Duplicate slugs found in the TOC: ${ duplicatedSlugs.join(
', '
) } ${ Reset }`
);
}

return pageItems;
}

Expand Down

0 comments on commit 0612581

Please sign in to comment.