Skip to content

Commit 94e2966

Browse files
zonemeenbrc-dd
andauthored
feat(build): support overriding meta viewport tag (#2642)
Co-authored-by: Divyansh Singh <[email protected]>
1 parent 8ff431a commit 94e2966

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Diff for: src/node/build/render.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ export async function renderPage(
152152
<html lang="${siteData.lang}" dir="${siteData.dir}">
153153
<head>
154154
<meta charset="utf-8">
155-
<meta name="viewport" content="width=device-width,initial-scale=1">
155+
${
156+
isMetaViewportOverridden(head)
157+
? ''
158+
: '<meta name="viewport" content="width=device-width,initial-scale=1">'
159+
}
156160
<title>${title}</title>
157161
<meta name="description" content="${description}">
158162
${stylesheetLink}
@@ -248,11 +252,14 @@ function renderAttrs(attrs: Record<string, string>): string {
248252
.join('')
249253
}
250254

251-
function isMetaDescription(headConfig: HeadConfig) {
252-
const [type, attrs] = headConfig
253-
return type === 'meta' && attrs?.name === 'description'
255+
function filterOutHeadDescription(head: HeadConfig[] = []) {
256+
return head.filter(([type, attrs]) => {
257+
return !(type === 'meta' && attrs?.name === 'description')
258+
})
254259
}
255260

256-
function filterOutHeadDescription(head: HeadConfig[] | undefined) {
257-
return head ? head.filter((h) => !isMetaDescription(h)) : []
261+
function isMetaViewportOverridden(head: HeadConfig[] = []) {
262+
return head.some(([type, attrs]) => {
263+
return type === 'meta' && attrs?.name === 'viewport'
264+
})
258265
}

0 commit comments

Comments
 (0)