From 269d9f25094554fa10ac97cfb344c0d451921c7e Mon Sep 17 00:00:00 2001 From: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> Date: Fri, 1 Sep 2023 20:36:17 -0300 Subject: [PATCH] Fix dir alignment and URL for OG images (#12) --- .../src/.vitepress/config/hooks/generateMeta.ts | 8 ++++++-- .../theme/components/OgImageTemplate.vue | 15 +++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/website/src/.vitepress/config/hooks/generateMeta.ts b/website/src/.vitepress/config/hooks/generateMeta.ts index cf31312b..6127780f 100644 --- a/website/src/.vitepress/config/hooks/generateMeta.ts +++ b/website/src/.vitepress/config/hooks/generateMeta.ts @@ -72,12 +72,16 @@ const generateMeta = (context: TransformContext, hostname: string) => { const url = pageData.filePath .replace("index.md", "") .replace(".md", ""); - head.push(["meta", { property: "og:image", content: `${hostname}/${url}__og_image__/og.png` }]); + const imageUrl = `${url}/__og_image__/og.png` + .replace(/\/\//g, "/") + .replace(/^\//, ""); + + head.push(["meta", { property: "og:image", content: `${hostname}/${imageUrl}` }]); head.push(["meta", { property: "og:image:width", content: "1200" }]); head.push(["meta", { property: "og:image:height", content: "628" }]); head.push(["meta", { property: "og:image:type", content: "image/png" }]); head.push(["meta", { property: "og:image:alt", content: pageData.frontmatter.title }]); - head.push(["meta", { name: "twitter:image", content: `${hostname}/${url}__og_image__/og.png` }]); + head.push(["meta", { name: "twitter:image", content: `${hostname}/${imageUrl}` }]); head.push(["meta", { name: "twitter:image:width", content: "1200" }]); head.push(["meta", { name: "twitter:image:height", content: "628" }]); head.push(["meta", { name: "twitter:image:alt", content: pageData.frontmatter.title }]); diff --git a/website/src/.vitepress/theme/components/OgImageTemplate.vue b/website/src/.vitepress/theme/components/OgImageTemplate.vue index 242eabde..d517ef8a 100644 --- a/website/src/.vitepress/theme/components/OgImageTemplate.vue +++ b/website/src/.vitepress/theme/components/OgImageTemplate.vue @@ -3,18 +3,21 @@ defineProps<{ title: string; description?: string; dir?: string }>();