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

Loading…
Cancel
Save