Fixes to head/meta generation

This commit is contained in:
Soitora 2023-07-26 01:25:23 +02:00
parent ca560632b8
commit c56a5184cd
No known key found for this signature in database
GPG Key ID: A6D711EB4F2CCD97
2 changed files with 17 additions and 22 deletions

View File

@ -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;

View File

@ -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",