From 58442aab3aab36b485959dc5b594618f46982446 Mon Sep 17 00:00:00 2001 From: Soitora Date: Thu, 20 Jul 2023 19:57:20 +0200 Subject: [PATCH] Enable frontmatter og-theme support Also allows changing from large to small og image --- src/.vitepress/config/hooks/generateMeta.ts | 15 +++++++++++++-- src/forks/neko.md | 13 +++---------- src/forks/tachiyomiaz.md | 13 +++---------- src/forks/tachiyomij2k.md | 13 +++---------- src/forks/tachiyomisy.md | 13 +++---------- 5 files changed, 25 insertions(+), 42 deletions(-) diff --git a/src/.vitepress/config/hooks/generateMeta.ts b/src/.vitepress/config/hooks/generateMeta.ts index 51a95af2..b95dbbe2 100644 --- a/src/.vitepress/config/hooks/generateMeta.ts +++ b/src/.vitepress/config/hooks/generateMeta.ts @@ -8,6 +8,8 @@ const generateMeta = (context: TransformContext, hostname: string) => { head.push(["link", { rel: "canonical", href: url }]); + head.push(["meta", { name: "theme-color", content: pageData.frontmatter.theme }]); + head.push(["meta", { property: "og:url", content: url }]); head.push(["meta", { property: "og:type", content: pageData.frontmatter.type }]); head.push(["meta", { property: "og:title", content: pageData.frontmatter.title }]); @@ -18,8 +20,17 @@ const generateMeta = (context: TransformContext, hostname: string) => { head.push(["meta", { name: "twitter:description", content: pageData.frontmatter.description }]); if (pageData.frontmatter.image) { - head.push(["meta", { property: "og:image", content: `${hostname}/${pageData.frontmatter.image}` }]); - head.push(["meta", { name: "twitter:image", content: `${hostname}/${pageData.frontmatter.image}` }]); + head.push(["meta", { property: "og:image", content: `${hostname}/${pageData.frontmatter.image.replace(/^\//, "")}` }]); + head.push(["meta", { name: "twitter:image", content: `${hostname}/${pageData.frontmatter.image.replace(/^\//, "")}` }]); + } + + switch (pageData.frontmatter.imageSize) { + case "small": + head.push(["meta", { name: "twitter:card", content: "summary" }]); + break; + case "large": + head.push(["meta", { name: "twitter:card", content: "summary_large_image" }]); + break; } if (pageData.frontmatter.tag) { diff --git a/src/forks/neko.md b/src/forks/neko.md index 017f0a92..8cbc8ce9 100644 --- a/src/forks/neko.md +++ b/src/forks/neko.md @@ -29,16 +29,9 @@ features: details: Describe Feature here. icon: -head: - - - meta - - property: og:image - content: /forks/forks_logo-neko.png - - - meta - - name: theme-color - content: "#FD6684" - - - meta - - name: msapplication-TileColor - content: "#FD6684" +theme: "#FD6684" +image: /forks/forks_logo-neko.png +imageSize: small ---
diff --git a/src/forks/tachiyomiaz.md b/src/forks/tachiyomiaz.md index 6b67e593..9298ea33 100644 --- a/src/forks/tachiyomiaz.md +++ b/src/forks/tachiyomiaz.md @@ -29,16 +29,9 @@ features: details: Describe Feature here. icon: -head: - - - meta - - property: og:image - content: /forks/forks_logo-az.png - - - meta - - name: theme-color - content: "#FFCC4D" - - - meta - - name: msapplication-TileColor - content: "#FFCC4D" +theme: "#FFCC4D" +image: /forks/forks_logo-az.png +imageSize: small ---
diff --git a/src/forks/tachiyomij2k.md b/src/forks/tachiyomij2k.md index f855dfd2..2d82750d 100644 --- a/src/forks/tachiyomij2k.md +++ b/src/forks/tachiyomij2k.md @@ -38,16 +38,9 @@ features: details: Describe Feature here. icon: 👑 -head: - - - meta - - property: og:image - content: /forks/forks_logo-j2k.png - - - meta - - name: theme-color - content: "#0952AF" - - - meta - - name: msapplication-TileColor - content: "#0952AF" +theme: "#0952AF" +image: /forks/forks_logo-j2k.png +imageSize: small ---
diff --git a/src/forks/tachiyomisy.md b/src/forks/tachiyomisy.md index 93a15e4f..e60b4c0d 100644 --- a/src/forks/tachiyomisy.md +++ b/src/forks/tachiyomisy.md @@ -38,16 +38,9 @@ features: details: Describe Feature here. icon: 🐍 -head: - - - meta - - property: og:image - content: /forks/forks_logo-sy.png - - - meta - - name: theme-color - content: "#CE2828" - - - meta - - name: msapplication-TileColor - content: "#CE2828" +theme: "#CE2828" +image: /forks/forks_logo-sy.png +imageSize: small ---