refactor(v2): automatically add base URL to PWA head tags (#5169)

* refactor(v2): automatically add base URL to PWA head tags

* Add baseUrl only if necessary
This commit is contained in:
Alexey Pyltsyn 2021-07-15 16:38:14 +03:00 committed by GitHub
parent 81170a79f4
commit f7b5e90390
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 9 deletions

View file

@ -8,6 +8,7 @@
const LogPlugin = require('@docusaurus/core/lib/webpack/plugins/LogPlugin')
.default;
const {compile} = require('@docusaurus/core/lib/webpack/utils');
const {normalizeUrl} = require('@docusaurus/utils');
const path = require('path');
const webpack = require('webpack');
const {injectManifest} = require('workbox-build');
@ -88,12 +89,15 @@ function plugin(context, options) {
injectHtmlTags() {
const headTags = [];
if (isProd && pwaHead) {
pwaHead.forEach(({tagName, ...attributes}) =>
headTags.push({
pwaHead.forEach(({tagName, ...attributes}) => {
if (attributes.href && !attributes.href.startsWith(baseUrl)) {
attributes.href = normalizeUrl([baseUrl, attributes.href]);
}
return headTags.push({
tagName,
attributes,
}),
);
});
});
}
return {headTags};
},