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: convert special html symbols in page titles to understandable characters (resolves #387) #388

Merged
merged 19 commits into from
Sep 10, 2020

Conversation

TeddTech
Copy link
Contributor

@TeddTech TeddTech commented Sep 10, 2020

  • This pull request has been linted by running npm run lint without errors
  • This pull request has been tested by running npm run start and reviewing affected routes
  • This pull request has been built by running npm run build without errors
  • This isn't a duplicate of an existing pull request

Description

Remove ­ from title tags on webpages with soft hyphens in title.

Steps to test

  1. Go to The Importa­nce of Perip­heral Vision views article of the deploy preview.
  2. View the tab title and the <title> tag in the <head> tag

Expected behavior:
&shy; should not appear

Additional information

This PR also replaces &#8217; with an apostrophe in title tags.

Related issues

resolves #387

@@ -10,6 +10,7 @@ const dataFetcherAirtable = require("./src/utils/data-fetcher-airtable.js");
const htmlMinifyTransform = require("./src/transforms/html-minify.js");
const parseTransform = require("./src/transforms/parse.js");
const dateFilter = require("./src/filters/date.js");
const metaTitleFilter = require("./src/filters/meta-title.js");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

titleFilter might be a better name than metaTitleFilter.

src/js/utils.js Outdated
@@ -2,6 +2,17 @@

/* global convertDate, stripHtmlTags, htmlDecode, chunkArray, escapeSpecialChars */

/*
* Remove soft hyphens and replace &#8217; with apostrophe.
* @param {String} webpageString - A string with one or more soft hyphens or &#8217;.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to rename webpageString to inputStr. In this case, try to pick a name that suits the function itself rather than the context you wanted to use this function.

src/js/utils.js Outdated
*/
// eslint-disable-next-line
metaTitle = function (webpageString) {
webpageString = webpageString.replace(/&#8217;/g, "’");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use a logic like:

const toReplace = {
    "&#8217;": "’",
    "&shy;": ""
};

// Iterate thru toReplace object to replace every match.

When a new replacement needs to be added, extending the data in toReplace will be enough rather than copying the .replace() code over and over.

@cindyli cindyli changed the title Remove Soft Hyphens from Title Tags (resolves #387) fix: convert special html symbols in page titles to understandable characters (resolves #387) Sep 10, 2020
@cindyli cindyli merged commit 01e9746 into inclusive-design:dev Sep 10, 2020
@TeddTech TeddTech deleted the remove-softhyphens-titletags branch September 18, 2020 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove &shy; from title tags on webpages with hyphenate breaks in title
2 participants