Skip to content

Commit c194dcf

Browse files
authoredOct 21, 2024··
Fix consent text with override vendor (#6)
1 parent 306ff53 commit c194dcf

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed
 

‎scripts/post-build.js

+30-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require('fs');
2+
const path = require('path');
23

34
const cheerio = require('cheerio');
45
const walkSync = require('walk-sync');
@@ -33,6 +34,19 @@ const notes = {
3334
Важно: 'Warning',
3435
};
3536

37+
const VENDOR_FIX = {
38+
consent: {
39+
ru: {
40+
old: 'Нажав Принять, вы даёте согласие на использование нашим веб-сайтом файлов cookie Google Analytics для предоставления вам наиболее релевантных услуг и в аналитических целях.',
41+
new: 'Мы используем файлы cookie, чтобы вы могли наилучшим образом пользоваться нашим веб-сайтом. Если вы продолжаете использовать наш веб-сайт, мы полагаем, что вы согласны с таким использованием.',
42+
},
43+
en: {
44+
old: 'By clicking Accept, you consent to our website’s use of Google Analytics cookies in order to give you the most relevant experience, and for analytics purposes.',
45+
new: 'We use cookies to ensure that you have the best experience on our website. If you continue to use our website, we assume that you are happy with it.',
46+
},
47+
},
48+
};
49+
3650
const LINK = [
3751
{rel: 'icon', href: '/favicon.ico', sizes: 'any'},
3852
{type: 'image/x-icon', rel: 'shortcut icon', href: '/favicon.ico'},
@@ -66,9 +80,21 @@ async function main() {
6680
includeBasePath: true,
6781
});
6882

83+
// fix vendor script
84+
let vendorScript = fs.readFileSync(path.join(basePath, '_bundle', 'vendor.js')).toString();
85+
Object.keys(VENDOR_FIX).forEach((key) => {
86+
Object.keys(VENDOR_FIX[key]).forEach((lang) => {
87+
vendorScript = vendorScript.replace(
88+
VENDOR_FIX[key][lang].old,
89+
VENDOR_FIX[key][lang].new,
90+
);
91+
});
92+
});
93+
fs.writeFileSync(path.join(basePath, '_bundle', 'vendor.js'), vendorScript);
94+
6995
for (let i = 0; i < paths.length; i += 1) {
70-
const path = paths[i];
71-
const trimPath = path.replace(basePath, '');
96+
const filePath = paths[i];
97+
const trimPath = filePath.replace(basePath, '');
7298
const trimPathLog = trimPath.replace(/^\//g, '');
7399

74100
// eslint-disable-next-line no-console
@@ -90,7 +116,7 @@ async function main() {
90116
}
91117
}
92118

93-
const fileHtml = fs.readFileSync(path);
119+
const fileHtml = fs.readFileSync(filePath);
94120
const $ = cheerio.load(fileHtml);
95121

96122
const head = $('head');
@@ -153,7 +179,7 @@ async function main() {
153179
.replace(/>В этой статье</g, '>In this article<');
154180
}
155181

156-
fs.writeFileSync(path, html);
182+
fs.writeFileSync(filePath, html);
157183
}
158184

159185
if (Object.keys(FILE_CHECK_MAP).length > 0) {

0 commit comments

Comments
 (0)
Please sign in to comment.