From 4a837af2297bd887477a887a3059cfda2dbf84f9 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 27 Sep 2023 18:12:06 -0500 Subject: [PATCH] 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> --- website/assets/.eslintrc | 2 +- .../js/pages/handbook/basic-handbook.page.js | 31 +++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/website/assets/.eslintrc b/website/assets/.eslintrc index 5909cdefba..94cfe4e273 100644 --- a/website/assets/.eslintrc +++ b/website/assets/.eslintrc @@ -26,7 +26,7 @@ }, "parserOptions": { - "ecmaVersion": 8 + "ecmaVersion": 2018 //^ If you are not using a transpiler like Babel, change this to `5`. }, diff --git a/website/assets/js/pages/handbook/basic-handbook.page.js b/website/assets/js/pages/handbook/basic-handbook.page.js index f17a88e5ae..75be12a617 100644 --- a/website/assets/js/pages/handbook/basic-handbook.page.js +++ b/website/assets/js/pages/handbook/basic-handbook.page.js @@ -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 'user’s' 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, '✓')// Replace green checkmarks with unicode checkmarks + .replace(/❌/g, '✗')// Replace red crosses with unicode crosses + .replace(this.regexToMatchEmoji, '')// Remove all other emoji + ); + }, clickScrollToTop: function() { window.scrollTo({ top: 0,