Skip to content

Commit 1d13c0e

Browse files
authored
docs: fix cover images (#432)
1 parent 599a161 commit 1d13c0e

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

.vitepress/components/BlogEntry/BlogEntry.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const dateText = new Date(props.date).toLocaleDateString("en-US", {
114114
align-self: start;
115115
background-repeat: no-repeat;
116116
background-size: cover;
117-
--max-height: 256px;
117+
--max-height: 320px;
118118
}
119119
}
120120

.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)