mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-01 10:22:30 +02:00
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:
parent
81170a79f4
commit
f7b5e90390
3 changed files with 14 additions and 9 deletions
|
@ -18,6 +18,7 @@
|
|||
"@babel/preset-env": "^7.12.16",
|
||||
"@docusaurus/core": "2.0.0-beta.3",
|
||||
"@docusaurus/theme-common": "2.0.0-beta.3",
|
||||
"@docusaurus/utils": "2.0.0-beta.3",
|
||||
"@docusaurus/utils-validation": "2.0.0-beta.3",
|
||||
"babel-loader": "^8.2.2",
|
||||
"clsx": "^1.1.1",
|
||||
|
|
|
@ -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};
|
||||
},
|
||||
|
|
|
@ -196,12 +196,12 @@ const isVersioningDisabled = !!process.env.DISABLE_VERSIONING || isI18nStaging;
|
|||
{
|
||||
tagName: 'link',
|
||||
rel: 'icon',
|
||||
href: `${baseUrl}img/docusaurus.png`,
|
||||
href: 'img/docusaurus.png',
|
||||
},
|
||||
{
|
||||
tagName: 'link',
|
||||
rel: 'manifest',
|
||||
href: `${baseUrl}manifest.json`,
|
||||
href: 'manifest.json',
|
||||
},
|
||||
{
|
||||
tagName: 'meta',
|
||||
|
@ -221,18 +221,18 @@ const isVersioningDisabled = !!process.env.DISABLE_VERSIONING || isI18nStaging;
|
|||
{
|
||||
tagName: 'link',
|
||||
rel: 'apple-touch-icon',
|
||||
href: `${baseUrl}img/docusaurus.png`,
|
||||
href: 'img/docusaurus.png',
|
||||
},
|
||||
{
|
||||
tagName: 'link',
|
||||
rel: 'mask-icon',
|
||||
href: `${baseUrl}img/docusaurus.png`,
|
||||
href: 'img/docusaurus.png',
|
||||
color: 'rgb(62, 204, 94)',
|
||||
},
|
||||
{
|
||||
tagName: 'meta',
|
||||
name: 'msapplication-TileImage',
|
||||
href: `${baseUrl}img/docusaurus.png`,
|
||||
href: 'img/docusaurus.png',
|
||||
},
|
||||
{
|
||||
tagName: 'meta',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue