From 48a0d1fdaf8d4474efb2bd2eb52271b5128fb17f Mon Sep 17 00:00:00 2001 From: Romuald Brillout Date: Fri, 2 Aug 2024 09:12:39 +0200 Subject: [PATCH] feat: new settings [`image`](https://vike.dev/image) --- vike-solid/+config.ts | 3 +++ vike-solid/renderer/getHeadSetting.ts | 2 +- vike-solid/renderer/onRenderHtml.tsx | 5 +++++ vike-solid/types/Config.ts | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/vike-solid/+config.ts b/vike-solid/+config.ts index a735194..68274ff 100644 --- a/vike-solid/+config.ts +++ b/vike-solid/+config.ts @@ -36,6 +36,9 @@ export default { description: { env: { server: true }, }, + image: { + env: { server: true }, + }, favicon: { env: { server: true, client: true }, }, diff --git a/vike-solid/renderer/getHeadSetting.ts b/vike-solid/renderer/getHeadSetting.ts index 8faf090..2c7be41 100644 --- a/vike-solid/renderer/getHeadSetting.ts +++ b/vike-solid/renderer/getHeadSetting.ts @@ -4,7 +4,7 @@ import type { PageContext } from "vike/types"; import { isCallable } from "../utils/isCallable.js"; function getHeadSetting( - headSetting: "title" | "description" | "favicon" | "lang", + headSetting: "title" | "description" | "image" | "favicon" | "lang", pageContext: PageContext, ): undefined | null | string { const config = pageContext.configEntries[headSetting]?.[0]; diff --git a/vike-solid/renderer/onRenderHtml.tsx b/vike-solid/renderer/onRenderHtml.tsx index f4d804f..94a92f8 100644 --- a/vike-solid/renderer/onRenderHtml.tsx +++ b/vike-solid/renderer/onRenderHtml.tsx @@ -17,12 +17,16 @@ const onRenderHtml: OnRenderHtmlAsync = async (pageContext): ReturnType${title}`; const faviconTag = !favicon ? "" : escapeInject``; const descriptionTags = !description ? "" : escapeInject``; + const imageTags = !image + ? "" + : escapeInject``; const Head = pageContext.config.Head || (() => <>); const head = renderToString(() => ( @@ -56,6 +60,7 @@ const onRenderHtml: OnRenderHtmlAsync = async (pageContext): ReturnType diff --git a/vike-solid/types/Config.ts b/vike-solid/types/Config.ts index 964b865..4b76a24 100644 --- a/vike-solid/types/Config.ts +++ b/vike-solid/types/Config.ts @@ -66,6 +66,21 @@ declare global { */ description?: string | ((pageContext: PageContextServer) => string); + /** + * Set the page's preview image upon URL sharing. + * + * Generates: + * ```jsx + * + * + * + * + * ``` + * + * https://vike.dev/image + */ + image?: string | ((pageContext: PageContextServer) => string); + /** * Set the page's favicon. *