Skip to content

Commit 90b3ade

Browse files
authored
fix(tools): remove special characters from slugs (#2460)
* fix(tools): remove special characters from slug * fix(tools): use slugify strict option to enforce no special characters * chore(tools): add changeset
1 parent 3e9fafb commit 90b3ade

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@patternfly/pfe-tools": patch
3+
---
4+
5+
Removes special characters from component slugs ie. `special (characters)` becomes `special-characters`

tools/pfe-tools/11ty/DocsPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class DocsPage implements DocsPageRenderer {
7474
private options?: DocsPageOptions) {
7575
this.tagName = options?.tagName ?? '';
7676
this.title = options?.title ?? Manifest.prettyTag(this.tagName);
77-
this.slug = slugify(options?.aliases?.[this.tagName] ?? this.tagName.replace(/^\w+-/, '')).toLowerCase();
77+
this.slug = slugify(options?.aliases?.[this.tagName] ?? this.tagName.replace(/^\w+-/, ''), { strict: true, lower: true });
7878
this.summary = this.manifest.getSummary(this.tagName);
7979
this.description = this.manifest.getDescription(this.tagName);
8080
this.templates = nunjucks.configure(DocsPage.#templatesDir);

tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { join } from 'node:path';
2020
import { readFileSync } from 'node:fs';
2121

2222
import { getAllPackages } from './get-all-packages.js';
23+
import slugify from 'slugify';
2324
import { deslugify } from '@patternfly/pfe-tools/config.js';
2425

2526
type PredicateFn = (x: unknown) => boolean;
@@ -266,7 +267,9 @@ export class Manifest {
266267
const { prettyTag } = Manifest;
267268
return this.getDemos(tagName).map(demo => {
268269
const permalink = demo.url.replace(options.demoURLPrefix, '/');
269-
const [, slug = ''] = permalink.match(/\/components\/(.*)\/demo/) ?? [];
270+
let [, slug = ''] = permalink.match(/\/components\/(.*)\/demo/) ?? [];
271+
// strict removes all special characters from slug
272+
slug = slugify(slug, { strict: true, lower: true });
270273
const primaryElementName = deslugify(slug, options.rootDir);
271274
const filePath = demo.source?.href.replace(options.sourceControlURLPrefix, `${options.rootDir}/`) ?? '';
272275
const [last = ''] = filePath.split('/').reverse();

0 commit comments

Comments
 (0)