Skip to content

Commit

Permalink
fix: duplicate image thumbnail logic for GitHub sites (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcshzj authored Jan 13, 2025
1 parent 69c314b commit ab7de7f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tooling/build/scripts/generate-sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ const JSON_SCHEMA_VERSION = "0.1.0"
const schemaDirPath = path.join(__dirname, "../schema")
const sitemapPath = path.join(__dirname, "../sitemap.json")

const getResourceImage = (schemaData) => {
if (schemaData.page.image) return schemaData.page.image

if (!Array.isArray(schemaData.content)) return undefined

const firstImageComponent = schemaData.content.find(
(item) => item.type === "image",
)
return firstImageComponent
? {
src: firstImageComponent.src,
alt: firstImageComponent.alt,
}
: undefined
}

const getSchemaJson = async (filePath) => {
try {
const schemaContent = await fs.readFile(filePath, "utf8")
Expand Down Expand Up @@ -70,7 +86,7 @@ const getSiteMapEntry = async (fullPath, relativePath, name) => {
summary,
category: schemaData.page.category,
date: schemaData.page.date,
image: schemaData.page.image,
image: getResourceImage(schemaData),
tags: schemaData.page.tags,
}

Expand Down

0 comments on commit ab7de7f

Please sign in to comment.