From 75d427efa3637e7a8608e708079b6daae0604c9b Mon Sep 17 00:00:00 2001 From: Steven Spriggs Date: Wed, 29 Mar 2023 19:54:07 -0400 Subject: [PATCH 1/3] fix(tools): remove special characters from slug --- tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts b/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts index ebb4f27312..a4bd12674c 100644 --- a/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts +++ b/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts @@ -266,7 +266,9 @@ export class Manifest { const { prettyTag } = Manifest; return this.getDemos(tagName).map(demo => { const permalink = demo.url.replace(options.demoURLPrefix, '/'); - const [, slug = ''] = permalink.match(/\/components\/(.*)\/demo/) ?? []; + let [, slug = ''] = permalink.match(/\/components\/(.*)\/demo/) ?? []; + // remove all special characters from slug + slug = slug.replace(/^a-zA-Z0-9 ]/g, ''); const primaryElementName = deslugify(slug, options.rootDir); const filePath = demo.source?.href.replace(options.sourceControlURLPrefix, `${options.rootDir}/`) ?? ''; const [last = ''] = filePath.split('/').reverse(); From f65e106d16b50171175e5bc76dd81d3c99fbe36f Mon Sep 17 00:00:00 2001 From: Steven Spriggs Date: Wed, 29 Mar 2023 20:46:31 -0400 Subject: [PATCH 2/3] fix(tools): use slugify strict option to enforce no special characters --- tools/pfe-tools/11ty/DocsPage.ts | 2 +- tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/pfe-tools/11ty/DocsPage.ts b/tools/pfe-tools/11ty/DocsPage.ts index 5b95950fbb..5e3138c622 100644 --- a/tools/pfe-tools/11ty/DocsPage.ts +++ b/tools/pfe-tools/11ty/DocsPage.ts @@ -74,7 +74,7 @@ export class DocsPage implements DocsPageRenderer { private options?: DocsPageOptions) { this.tagName = options?.tagName ?? ''; this.title = options?.title ?? Manifest.prettyTag(this.tagName); - this.slug = slugify(options?.aliases?.[this.tagName] ?? this.tagName.replace(/^\w+-/, '')).toLowerCase(); + this.slug = slugify(options?.aliases?.[this.tagName] ?? this.tagName.replace(/^\w+-/, ''), { strict: true, lower: true }); this.summary = this.manifest.getSummary(this.tagName); this.description = this.manifest.getDescription(this.tagName); this.templates = nunjucks.configure(DocsPage.#templatesDir); diff --git a/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts b/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts index a4bd12674c..cb82855612 100644 --- a/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts +++ b/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts @@ -20,6 +20,7 @@ import { join } from 'node:path'; import { readFileSync } from 'node:fs'; import { getAllPackages } from './get-all-packages.js'; +import slugify from 'slugify'; import { deslugify } from '@patternfly/pfe-tools/config.js'; type PredicateFn = (x: unknown) => boolean; @@ -267,8 +268,8 @@ export class Manifest { return this.getDemos(tagName).map(demo => { const permalink = demo.url.replace(options.demoURLPrefix, '/'); let [, slug = ''] = permalink.match(/\/components\/(.*)\/demo/) ?? []; - // remove all special characters from slug - slug = slug.replace(/^a-zA-Z0-9 ]/g, ''); + // strict removes all special characters from slug + slug = slugify(slug, { strict: true, lower: true }); const primaryElementName = deslugify(slug, options.rootDir); const filePath = demo.source?.href.replace(options.sourceControlURLPrefix, `${options.rootDir}/`) ?? ''; const [last = ''] = filePath.split('/').reverse(); From 71eb28adf1f47e6c2e0cc723599e7e211e570b8e Mon Sep 17 00:00:00 2001 From: Steven Spriggs Date: Wed, 29 Mar 2023 20:47:03 -0400 Subject: [PATCH 3/3] chore(tools): add changeset --- .changeset/cuddly-scissors-reply.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cuddly-scissors-reply.md diff --git a/.changeset/cuddly-scissors-reply.md b/.changeset/cuddly-scissors-reply.md new file mode 100644 index 0000000000..8cde1de895 --- /dev/null +++ b/.changeset/cuddly-scissors-reply.md @@ -0,0 +1,5 @@ +--- +"@patternfly/pfe-tools": patch +--- + +Removes special characters from component slugs ie. `special (characters)` becomes `special-characters`