diff --git a/website/src/.vitepress/config/head.ts b/website/src/.vitepress/config/head.ts index b6619e15..9ac16171 100644 --- a/website/src/.vitepress/config/head.ts +++ b/website/src/.vitepress/config/head.ts @@ -26,7 +26,6 @@ const head: HeadConfig[] = [ ], ["meta", { property: "og:locale", content: "en_US" }], ["meta", { property: "og:type", content: "website" }], - ["meta", { property: "og:image", content: "/img/logo.png" }], ]; export default head; diff --git a/website/src/.vitepress/config/hooks/generateMeta.ts b/website/src/.vitepress/config/hooks/generateMeta.ts index 8e6696d7..d7ef1ed4 100644 --- a/website/src/.vitepress/config/hooks/generateMeta.ts +++ b/website/src/.vitepress/config/hooks/generateMeta.ts @@ -7,18 +7,23 @@ const generateMeta = (context: TransformContext, hostname: string) => { const url = `${hostname}/${pageData.relativePath.replace(/((^|\/)index)?\.md$/, "$2")}`; 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 }]); - head.push(["meta", { property: "og:description", content: pageData.frontmatter.description }]); - head.push(["meta", { name: "twitter:url", content: url }]); - head.push(["meta", { name: "twitter:title", content: pageData.frontmatter.title }]); - head.push(["meta", { name: "twitter:description", content: pageData.frontmatter.description }]); + if (pageData.frontmatter.theme) { + head.push(["meta", { name: "theme-color", content: pageData.frontmatter.theme }]); + } + if (pageData.frontmatter.type) { + head.push(["meta", { property: "og:type", content: pageData.frontmatter.type }]); + } + if (pageData.frontmatter.title) { + head.push(["meta", { property: "og:title", content: pageData.frontmatter.title }]); + head.push(["meta", { name: "twitter:title", content: pageData.frontmatter.title }]); + } + if (pageData.frontmatter.description) { + head.push(["meta", { property: "og:description", content: pageData.frontmatter.description }]); + head.push(["meta", { name: "twitter:description", content: pageData.frontmatter.description }]); + } if (pageData.frontmatter.image) { head.push([ "meta", @@ -28,25 +33,16 @@ const generateMeta = (context: TransformContext, hostname: string) => { "meta", { name: "twitter:image", content: `${hostname}/${pageData.frontmatter.image.replace(/^\//, "")}` }, ]); + } else { + head.push(["meta", { property: "og:image", content: `${hostname}/img/logo.png` }]); + head.push(["meta", { name: "twitter:image", content: `${hostname}/img/logo.png` }]); } - - 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) { head.push(["meta", { property: "article:tag", content: pageData.frontmatter.tag }]); } - if (pageData.frontmatter.date) { head.push(["meta", { property: "article:published_time", content: pageData.frontmatter.date }]); } - if (pageData.lastUpdated && pageData.frontmatter.lastUpdated !== false) { head.push([ "meta",