-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: The responsive viewport tag is now injected by default (`<meta name="viewport" content="width=device-width,initial-scale=1">`). If you already inject `<meta name="viewport">` then remove it or set the `viewport` setting to `null`, see https://vike.dev/viewport.
- Loading branch information
Showing
3 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ const onRenderHtml: OnRenderHtmlAsync = async (pageContext): ReturnType<OnRender | |
? "" | ||
: escapeInject`<meta property="og:image" content="${image}"><meta name="twitter:card" content="summary_large_image">`; | ||
|
||
const viewportTag = dangerouslySkipEscape(getViewportTag(pageContext.config.viewport)); | ||
|
||
const Head = pageContext.config.Head || (() => <></>); | ||
const head = renderToString(() => ( | ||
<PageContextProvider pageContext={pageContext}> | ||
|
@@ -57,6 +59,7 @@ const onRenderHtml: OnRenderHtmlAsync = async (pageContext): ReturnType<OnRender | |
<head> | ||
<meta charset="UTF-8" /> | ||
${titleTag} | ||
${viewportTag} | ||
${headHtml} | ||
${faviconTag} | ||
${descriptionTags} | ||
|
@@ -91,6 +94,19 @@ function mergeTagAttributesList(tagAttributesList: TagAttributes[] = []) { | |
return tagAttributes; | ||
} | ||
|
||
export type Viewport = "responsive" | number | null; | ||
function getViewportTag(viewport: Viewport | undefined): string { | ||
if (viewport === "responsive" || viewport === undefined) { | ||
// `user-scalable=no` isn't recommended anymore: | ||
// - https://stackoverflow.com/questions/22354435/to-user-scalable-no-or-not-to-user-scalable-no/22544312#comment120949420_22544312 | ||
return '<meta name="viewport" content="width=device-width,initial-scale=1">'; | ||
} | ||
if (typeof viewport === "number") { | ||
return `<meta name="viewport" content="width=${viewport}">`; | ||
} | ||
return ""; | ||
} | ||
|
||
// We don't need this anymore starting from [email protected] which added the `require` setting. | ||
// TODO/eventually: remove this once <=0.4.172 versions become rare. | ||
function checkVikeVersion() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters