From f8d334e6e0f5a11b8e2758f0888e85a24c6ef2dc Mon Sep 17 00:00:00 2001 From: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> Date: Sat, 9 Sep 2023 20:02:54 -0300 Subject: [PATCH] Fix bad HTML encoding in OG images and add news dir. (#39) --- .../.vitepress/config/hooks/generateOgImages.ts | 14 +++++++++++++- .../theme/components/OgImageTemplate.vue | 13 ++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/website/src/.vitepress/config/hooks/generateOgImages.ts b/website/src/.vitepress/config/hooks/generateOgImages.ts index a5fd3321..de058125 100644 --- a/website/src/.vitepress/config/hooks/generateOgImages.ts +++ b/website/src/.vitepress/config/hooks/generateOgImages.ts @@ -61,6 +61,18 @@ interface GenerateImagesOptions { fonts: SatoriOptions["fonts"] } +function getDir(url: string) { + if (url.startsWith("/docs/faq/")) { + return "FAQ" + } else if (url.startsWith("/docs/guides/")) { + return "Guide" + } else if (url.startsWith("/news/") && url !== "/news/") { + return "News" + } + + return undefined +} + async function generateImage({ page, template, outDir, fonts }: GenerateImagesOptions) { const { frontmatter, url } = page @@ -77,7 +89,7 @@ async function generateImage({ page, template, outDir, fonts }: GenerateImagesOp frontmatter.layout === "home" ? frontmatter.hero.tagline ?? frontmatter.description : frontmatter.description, - dir: url.startsWith("/docs/faq/") ? "FAQ" : url.startsWith("/docs/guides/") ? "Guide" : undefined, + dir: getDir(url), }, } diff --git a/website/src/.vitepress/theme/components/OgImageTemplate.vue b/website/src/.vitepress/theme/components/OgImageTemplate.vue index d9f38f98..efa2d07e 100644 --- a/website/src/.vitepress/theme/components/OgImageTemplate.vue +++ b/website/src/.vitepress/theme/components/OgImageTemplate.vue @@ -16,20 +16,15 @@ defineProps<{ title: string; description?: string; dir?: string }>()
-
- {{ dir }} -
+
+
-
- {{ title }} -
-
- {{ description }} -
+
+