Website: remove emoji in the handbook on windows (#13683)

Closes: #13222

Changes:
- Updated the handbook page script to remove emoji for users browsing
the handbook on a windows device.

---------

Co-authored-by: Mike Thomas <78363703+mike-j-thomas@users.noreply.github.com>
This commit is contained in:
Eric 2023-09-27 18:12:06 -05:00 committed by GitHub
parent 5a2e426346
commit 4a837af229
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View file

@ -26,7 +26,7 @@
},
"parserOptions": {
"ecmaVersion": 8
"ecmaVersion": 2018
//^ If you are not using a transpiler like Babel, change this to `5`.
},

View file

@ -8,7 +8,8 @@ parasails.registerPage('basic-handbook', {
breadcrumbs: [],
subtopics: [],
handbookIndexLinks: [],
hideEmojisOnPage: false,
regexToMatchEmoji: /(?:[\u00A9\u00AE\u203C\u2049\u2122\u2139\u2194-\u21AA\u2300-\u23FF\u2460-\u24FF\u25AA-\u25FE\u2600-\u26FF\u2700-\u27BF\u2900-\u297F\u2934-\u2935\u2B05-\u2B07\u2B1B-\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70-\uDD71\uDD7E-\uDD7F\uDE00-\uDE02\uDE1A\uDE2F\uDE30-\uDE39\uDE3A-\uDE3F\uDE50-\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96-\uDF97\uDF99-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDDFF\uDE00-\uDE4F\uDE80-\uDEFF\uDFE0-\uDFFF]|\uD83E[\uDD0D-\uDDFF\uDE00-\uDEFF])\s{0,1}/g
},
// ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗
@ -19,11 +20,17 @@ parasails.registerPage('basic-handbook', {
this.isHandbookLandingPage = true;
}
this.breadcrumbs = _.trim(this.thisPage.url, /\//).split(/\//);
},
mounted: async function() {
// If the user is on a windows device, hide emojis in the handbook.
if(typeof bowser !== 'undefined' && bowser.windows) {
this.hideEmojisOnPage = true;
if(!this.isHandbookLandingPage){
this.thisPage.title = this.thisPage.title.replace(this.regexToMatchEmoji, '');
this._removeEmojiFromThisPage();
}
}
// Adding a scroll event listener for scrolling sidebars and showing the back to top button.
window.addEventListener('scroll', this.handleScrollingInHandbook);
@ -58,8 +65,12 @@ parasails.registerPage('basic-handbook', {
let handbookPages = [];
for (let page of this.markdownPages) {
if(_.startsWith(page.url, '/handbook') && !page.title.match(/^readme\.md$/i) && page.sectionRelativeRepoPath.match(/readme\.md$/i)) {
let pageTitle = page.title;
if(this.hideEmojisOnPage){
pageTitle = pageTitle.replace(this.regexToMatchEmoji, '');
}
let handbookPage = {
pageTitle: page.title,
pageTitle: pageTitle,
url: page.url,
pageLinks: page.linksForHandbookIndex,
};
@ -70,7 +81,7 @@ parasails.registerPage('basic-handbook', {
this.handbookIndexLinks = _.sortBy(handbookPages, 'url');
// Sorting the company page to the top of the list, and the handbook page to the bottom
this.handbookIndexLinks.sort((a)=>{
if(a.pageTitle === '🔭 Company') {
if(_.endsWith(a.pageTitle, 'Company')) {
return -1;
} else {
return 0;
@ -89,7 +100,7 @@ parasails.registerPage('basic-handbook', {
// Removing all apostrophes from the title to keep _.kebabCase() from turning words like 'users' into 'user-s'
let kebabCaseFriendlyTitle = title.replace(/[\\']/g, '');
return {
title: title.replace(/([\uE000-\uF8FF]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDDFF])/g, ''), // take out any emojis (they look weird in the menu)
title: title.replace(this.regexToMatchEmoji, ''), // take out any emojis (they look weird in the menu)
url: '#' + _.kebabCase(kebabCaseFriendlyTitle.toLowerCase()),
};
});
@ -130,6 +141,14 @@ parasails.registerPage('basic-handbook', {
this.scrollDistance = scrollTop;
},
_removeEmojiFromThisPage: function() {
$('#body-content').html(
$('#body-content').html()
.replace(/✅/g, '&#x2713;')// Replace green checkmarks with unicode checkmarks
.replace(/❌/g, '&#x2717;')// Replace red crosses with unicode crosses
.replace(this.regexToMatchEmoji, '')// Remove all other emoji
);
},
clickScrollToTop: function() {
window.scrollTo({
top: 0,