Skip to content

Commit

Permalink
Fix AddEnglishSpecifier() producing illegal HTML (#3293)
Browse files Browse the repository at this point in the history
* Update gulpfile.mjs

* Update regex to exclude <title>

* Finalized regex

* Reworked AddEnglishSpecifier to improve build performance

* Fixed replacements inside html-tags

* Readded english-texts

---------
  • Loading branch information
brianebeling authored Jan 27, 2023
1 parent 2f8b4bd commit eeb2c20
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 15 deletions.
20 changes: 15 additions & 5 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import replace from 'gulp-replace';
import sitemap from 'gulp-sitemap';
import sourcemaps from 'gulp-sourcemaps';
import webp from 'gulp-webp';
import change from 'gulp-change';

import autoprefixer from 'autoprefixer';
import browser from 'browser-sync';
Expand Down Expand Up @@ -539,9 +540,18 @@ function deleteTmpFiles(done) {

function AddEnglishSpecifier() {
const data = JSON.parse(fs.readFileSync('src/data/english-texts.json', 'utf8'));
let task = gulp.src([PATHS.dist + '/**/*.html']);
data.texts.forEach((value) => {
task = task.pipe(replace(' ' + value + ' ', `<span lang="en"> ${value} </span>`));
});
return task.pipe(gulp.dest(PATHS.dist));
return gulp
.src([PATHS.dist + '/**/*.html'])
.pipe(
change(function () {
// split HTML to exclude the <head>-section from replacement
const splittedHtml = this.originalContent.split('</head>');
const regex = new RegExp(`(?<!\w)(${data.texts.join('|')})(?![^<]*>)`, 'g');
splittedHtml[1] = splittedHtml[1].replace(regex, (match) => {
return `<span lang="en">${match}</span>`;
});
return splittedHtml.join('</head>');
})
)
.pipe(gulp.dest(PATHS.dist));
}
108 changes: 98 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"dayjs": "^1.11.7",
"google-protobuf": "^3.21.2",
"gulp": "^4.0.2",
"gulp-change": "^1.0.2",
"gulp-clean-css": "^4.3.0",
"gulp-cli": "^2.3.0",
"gulp-if": "^3.0.0",
Expand Down
3 changes: 3 additions & 0 deletions src/data/english-texts.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"API",
"APIs",
"App-Identifier",
"Apple App Store",
"Apple Exposure Notifications API",
"BLE",
"BLE-Messung",
Expand Down Expand Up @@ -46,6 +47,7 @@
"Google Exposure Notifications API",
"Google Mobile Services",
"Google Play Services",
"Google Play Store",
"HTTPS",
"In-App-Reset",
"Interoperability Gateway",
Expand Down Expand Up @@ -80,6 +82,7 @@
"RPIs",
"SafetyNet",
"SARS-CoV-2-Exposition",
"Science",
"Science-Blog",
"Scoping-Document",
"Screenshots",
Expand Down

0 comments on commit eeb2c20

Please sign in to comment.