mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Fix issue where images sometimes not set as cover image
This commit is contained in:
+13
-13
@@ -122,25 +122,25 @@ function collectScrapedImages(data) {
|
||||
}
|
||||
|
||||
function mergeImagesIntoPosts(images, posts) {
|
||||
// create lookup table for quicker traversal
|
||||
const postsLookup = posts.reduce((lookup, post) => {
|
||||
lookup[post.meta.id] = post;
|
||||
return lookup;
|
||||
}, {});
|
||||
|
||||
images.forEach(image => {
|
||||
const post = postsLookup[image.postId];
|
||||
if (post) {
|
||||
posts.forEach(post => {
|
||||
let shouldAttach = false;
|
||||
|
||||
// this image was uploaded as an attachment to this post
|
||||
if (image.postId === post.meta.id) {
|
||||
shouldAttach = true;
|
||||
}
|
||||
|
||||
// this image was set as the featured image for this post
|
||||
if (image.id === post.meta.coverImageId) {
|
||||
// save cover image filename to frontmatter
|
||||
shouldAttach = true;
|
||||
post.frontmatter.coverImage = shared.getFilenameFromUrl(image.url);
|
||||
}
|
||||
|
||||
// save (unique) full image URLs for downloading later
|
||||
if (!post.meta.imageUrls.includes(image.url)) {
|
||||
|
||||
if (shouldAttach && !post.meta.imageUrls.includes(image.url)) {
|
||||
post.meta.imageUrls.push(image.url);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user