This commit is contained in:
taskylizard
2023-11-14 22:48:52 +05:30
parent fbebbefb80
commit ffedc34675
11 changed files with 97 additions and 69 deletions

View File

@@ -6,28 +6,31 @@ export function generateMeta(context: TransformContext, hostname: string) {
const url = `${hostname}/${pageData.relativePath.replace(/((^|\/)index)?\.md$/, "$2")}`;
head.push(["link", { rel: "canonical", href: url }]);
head.push(["meta", { property: "og:url", content: url }]);
head.push(["meta", { name: "twitter:url", content: url }]);
head.push(["meta", { name: "twitter:card", content: "summary_large_image" }]);
head.push(["meta", { property: "og:title", content: pageData.frontmatter.title }]);
head.push(["meta", { name: "twitter:title", content: pageData.frontmatter.title }]);
head.push(
["link", { rel: "canonical", href: url }],
["meta", { property: "og:url", content: url }],
["meta", { name: "twitter:url", content: url }],
["meta", { name: "twitter:card", content: "summary_large_image" }],
["meta", { property: "og:title", content: pageData.frontmatter.title }],
["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,
},
]);
head.push(
[
"meta",
{
property: "og:description",
content: pageData.frontmatter.description,
},
],
[
"meta",
{
name: "twitter:description",
content: pageData.frontmatter.description,
},
],
);
}
if (pageData.frontmatter.image) {
head.push([
@@ -46,17 +49,19 @@ export function generateMeta(context: TransformContext, hostname: string) {
]);
} else {
const url = pageData.filePath.replace("index.md", "").replace(".md", "");
const imageUrl = `${url}/__og_image__/og.png`.replace(/\/\//g, "/").replace(/^\//, "");
const imageUrl = `${url}/__og_image__/og.png`.replaceAll("//", "/").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}/${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 }]);
head.push(
["meta", { property: "og:image", content: `${hostname}/${imageUrl}` }],
["meta", { property: "og:image:width", content: "1200" }],
["meta", { property: "og:image:height", content: "628" }],
["meta", { property: "og:image:type", content: "image/png" }],
["meta", { property: "og:image:alt", content: pageData.frontmatter.title }],
["meta", { name: "twitter:image", content: `${hostname}/${imageUrl}` }],
["meta", { name: "twitter:image:width", content: "1200" }],
["meta", { name: "twitter:image:height", content: "628" }],
["meta", { name: "twitter:image:alt", content: pageData.frontmatter.title }],
);
}
if (pageData.frontmatter.tag) {
head.push(["meta", { property: "article:tag", content: pageData.frontmatter.tag }]);

View File

@@ -80,7 +80,7 @@ async function generateImage({ page, template, outDir, fonts }: GenerateImagesOp
const render = await renderAsync(svg);
const outputFolder = resolve(outDir, url.substring(1), "__og_image__");
const outputFolder = resolve(outDir, url.slice(1), "__og_image__");
const outputFile = resolve(outputFolder, "og.png");
await mkdir(outputFolder, { recursive: true });

View File

@@ -1,7 +1,9 @@
import { readFile } from "node:fs/promises";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { SatoriOptions, defineSatoriConfig } from "x-satori/vue";
import type { SatoriOptions } from "x-satori/vue";
import { defineSatoriConfig } from "x-satori/vue";
const __dirname = dirname(fileURLToPath(import.meta.url));
const __fonts = resolve(__dirname, "../fonts");