Skip to content

Commit 41157f5

Browse files
committed
docs: fix cover images
1 parent 599a161 commit 41157f5

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

.vitepress/config.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,32 @@ export default defineConfig({
226226
const coverImage = await ensureLocalImage(pageData.frontmatter.image, "cover", {
227227
baseDestLocation: imageDir.split("/")
228228
});
229-
head.push(["meta", {property: "og:image", content: resolveHref(coverImage.urlPath.absolute, true)}]);
229+
const imageUrl = resolveHref(coverImage.urlPath.absolute, true);
230+
head.push(["meta", {property: "og:image", content: imageUrl}]);
231+
head.push(["meta", {property: "twitter:image", content: imageUrl}]);
232+
head.push(["meta", {property: "twitter:card", content: "summary_large_image"}]);
230233
} else if (typeof pageData.frontmatter.image === "object") {
231234
const coverImage = typeof pageData.frontmatter.image.url === "string"
232235
? await ensureLocalImage(pageData.frontmatter.image.url, "cover", {
233236
baseDestLocation: imageDir.split("/")
234237
})
235238
: undefined;
236239

237-
if (typeof pageData.frontmatter.image.url === "string")
240+
if (typeof pageData.frontmatter.image.url === "string") {
241+
const imageUrl = resolveHref(coverImage?.urlPath.absolute ?? pageData.frontmatter.image.url, true);
238242
head.push(["meta", {
239243
property: "og:image",
240-
content: resolveHref(coverImage?.urlPath.absolute ?? pageData.frontmatter.image.url, true)
244+
content: imageUrl
241245
}]);
246+
head.push(["meta", {
247+
property: "twitter:image",
248+
content: imageUrl
249+
}]);
250+
head.push(["meta", {
251+
property: "twitter:card",
252+
content: "summary_large_image"
253+
}]);
254+
}
242255

243256
if (pageData.frontmatter.image.width != null)
244257
head.push(["meta", {
@@ -691,10 +704,17 @@ export default defineConfig({
691704
"/_blog/": {
692705
text: "Blog",
693706
link: "/blog/",
694-
items: blogPosts.map((post) => ({
695-
text: post.frontmatter.title,
696-
link: post.url
697-
}))
707+
items: blogPosts
708+
.filter((post) => {
709+
const hasCoverImage = typeof post.frontmatter?.image === "string" ||
710+
typeof post.frontmatter?.image?.url === "string";
711+
712+
return !hasCoverImage;
713+
})
714+
.map((post) => ({
715+
text: post.frontmatter.title,
716+
link: post.url
717+
}))
698718
}
699719
}
700720
}

0 commit comments

Comments
 (0)