Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): avoid breadcrumbs over-shortening #8830

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions build/document-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ const TRANSFORM_STRINGS = new Map(
/**
* Temporary fix for long titles in breadcrumbs
* @see https://github.com/mdn/yari-private/issues/612
* @param {String} title : the title of the document
* @param title : the title of the document
* @returns transformed title or original title as a string
*/
function transformTitle(title) {
function transformTitle(title: string) {
// if the title contains a string like `<input>: The Input (Form Input) element`,
// return only the `<input>` portion of the title
if (/<\w+>/g.test(title)) {
return /<\w+>/g.exec(title)[0];
}

const htmlTagTopic = /^<\w+>/.exec(title)?.[0];
// if the above did not match, see if it is one of the strings in the
// transformStrings object and return the relevant replacement or
// the unmodified title string
return TRANSFORM_STRINGS.get(title) || title;
return htmlTagTopic ?? TRANSFORM_STRINGS.get(title) ?? title;
}

/**
Expand Down