From 94e2966babfe572a62c71907332450b18c6c9509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=83=BD=E5=AE=81?= Date: Fri, 21 Jul 2023 22:08:51 +0800 Subject: [PATCH] feat(build): support overriding meta viewport tag (#2642) Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> --- src/node/build/render.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/node/build/render.ts b/src/node/build/render.ts index 40675408..a3079903 100644 --- a/src/node/build/render.ts +++ b/src/node/build/render.ts @@ -152,7 +152,11 @@ export async function renderPage( - + ${ + isMetaViewportOverridden(head) + ? '' + : '' + } ${title} ${stylesheetLink} @@ -248,11 +252,14 @@ function renderAttrs(attrs: Record): 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' + }) }