diff options
author | Ajay <[email protected]> | 2022-01-14 15:56:38 -0500 |
---|---|---|
committer | Ajay <[email protected]> | 2022-01-14 15:56:38 -0500 |
commit | 35da572f3f5cfecab2b9cea580bcac9f1c14d3a6 (patch) | |
tree | 8a78c45413b97d920617f4e10541a0ddc3c607a2 /webpack | |
parent | cf01679f1676c7901dcb0f9eff4b4c467bed641e (diff) | |
download | SponsorBlock-35da572f3f5cfecab2b9cea580bcac9f1c14d3a6.tar.gz SponsorBlock-35da572f3f5cfecab2b9cea580bcac9f1c14d3a6.zip |
Add build option for safari that fixes locales
Fix #801 and #1061
Diffstat (limited to 'webpack')
-rw-r--r-- | webpack/webpack.common.js | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index ccc1c82c..7f0d64ac 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -3,6 +3,7 @@ const path = require('path'); const CopyPlugin = require('copy-webpack-plugin'); const BuildManifest = require('./webpack.manifest'); const srcDir = '../src/'; +const fs = require("fs"); module.exports = env => ({ entry: { @@ -38,16 +39,46 @@ module.exports = env => ({ plugins: [ // exclude locale files in moment new CopyPlugin({ - patterns: [ - { - from: '.', - to: '../', - globOptions: { - ignore: ['manifest.json'], - }, - context: './public', - } - ] + patterns: [ + { + from: '.', + to: '../', + globOptions: { + ignore: ['manifest.json'], + }, + context: './public', + filter: async (path) => { + if (path.match(/\/_locales\/.+/)) { + const data = await fs.promises.readFile(path); + const parsed = JSON.parse(data.toString()); + + return parsed.fullName && parsed.Description; + } else { + return true; + } + }, + transform(content, path) { + if (path.match(/\/_locales\/.+/)) { + const parsed = JSON.parse(content.toString()); + if (env.browser.toLowerCase() === "safari") { + parsed.fullName.message = parsed.fullName.message.match(/^.+(?= -)/)?.[0] || parsed.fullName.message; + if (parsed.fullName.message.length > 50) { + parsed.fullName.message = parsed.fullName.message.substr(0, 47) + "..."; + } + + parsed.Description.message = parsed.Description.message.match(/^.+(?=\. )/)?.[0] || parsed.Description.message; + if (parsed.Description.message.length > 80) { + parsed.Description.message = parsed.Description.message.substr(0, 77) + "..."; + } + } + + return Buffer.from(JSON.stringify(parsed)); + } + + return content; + } + } + ] }), new BuildManifest({ browser: env.browser, |