feat(build): support overriding meta viewport tag (#2642)

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
pull/2667/head
烽宁 1 year ago committed by GitHub
parent 8ff431a6bc
commit 94e2966bab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -152,7 +152,11 @@ export async function renderPage(
<html lang="${siteData.lang}" dir="${siteData.dir}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
${
isMetaViewportOverridden(head)
? ''
: '<meta name="viewport" content="width=device-width,initial-scale=1">'
}
<title>${title}</title>
<meta name="description" content="${description}">
${stylesheetLink}
@ -248,11 +252,14 @@ function renderAttrs(attrs: Record<string, string>): string {
.join('')
}
function isMetaDescription(headConfig: HeadConfig) {
const [type, attrs] = headConfig
return type === 'meta' && attrs?.name === 'description'
function filterOutHeadDescription(head: HeadConfig[] = []) {
return head.filter(([type, attrs]) => {
return !(type === 'meta' && attrs?.name === 'description')
})
}
function filterOutHeadDescription(head: HeadConfig[] | undefined) {
return head ? head.filter((h) => !isMetaDescription(h)) : []
function isMetaViewportOverridden(head: HeadConfig[] = []) {
return head.some(([type, attrs]) => {
return type === 'meta' && attrs?.name === 'viewport'
})
}

Loading…
Cancel
Save