refactor(v2): remove type attribute from link and script tags (#4907)

* refactor(v2): remove type attribute from link and script tags

* minor TS fix

* stylesheets.type => optional

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
Alexey Pyltsyn 2021-06-09 15:55:47 +03:00 committed by GitHub
parent d81d43c247
commit 55e9bd8ac9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 18 deletions

View file

@ -178,9 +178,6 @@ export default function docusaurusThemeClassic(
preBodyTags: [
{
tagName: 'script',
attributes: {
type: 'text/javascript',
},
innerHTML: noFlashColorMode(colorMode),
},
],

View file

@ -20,7 +20,7 @@ module.exports = `
<%~ metaAttribute %>
<% }); %>
<% it.stylesheets.forEach((stylesheet) => { %>
<link rel="stylesheet" type="text/css" href="<%= it.baseUrl %><%= stylesheet %>" />
<link rel="stylesheet" href="<%= it.baseUrl %><%= stylesheet %>" />
<% }); %>
<% it.scripts.forEach((script) => { %>
<link rel="preload" href="<%= it.baseUrl %><%= script %>" as="script">
@ -32,7 +32,7 @@ module.exports = `
<%~ it.appHtml %>
</div>
<% it.scripts.forEach((script) => { %>
<script type="text/javascript" src="<%= it.baseUrl %><%= script %>"></script>
<script src="<%= it.baseUrl %><%= script %>"></script>
<% }); %>
<%~ it.postBodyTags %>
</body>

View file

@ -150,7 +150,7 @@ const ConfigSchema = Joi.object({
Joi.string(),
Joi.object({
href: Joi.string().required(),
type: Joi.string().required(),
type: Joi.string(),
}).unknown(),
),
clientModules: Joi.array().items(Joi.string()),

View file

@ -24,6 +24,7 @@ import loadThemeAlias from './themes';
import {
DocusaurusConfig,
DocusaurusSiteMetadata,
HtmlTagObject,
LoadContext,
PluginConfig,
Props,
@ -194,24 +195,23 @@ export async function load(
const stylesheetsTags = stylesheets.map((source) =>
typeof source === 'string'
? `<link rel="stylesheet" href="${source}">`
: {
: ({
tagName: 'link',
attributes: {
rel: 'stylesheet',
...source,
},
},
} as HtmlTagObject),
);
const scriptsTags = scripts.map((source) =>
typeof source === 'string'
? `<script type="text/javascript" src="${source}"></script>`
: {
? `<script src="${source}"></script>`
: ({
tagName: 'script',
attributes: {
type: 'text/javascript',
...source,
},
},
} as HtmlTagObject),
);
return {
headTags: [...stylesheetsTags, ...scriptsTags],