Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for additional image formats in build-rss.js #3396

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions scripts/build-rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ module.exports = async function rssFeed(type, title, desc, outputPath) {
throw new Error(`Missing required fields in posts: ${invalidPosts.map(p => p.title || p.slug).join(', ')}`);
}

const mimeTypes = {
'.jpeg': 'image/jpeg',
'.jpg': 'image/jpeg',
'.png': 'image/png',
'.svg': 'image/svg+xml',
'.webp': 'image/webp',
'.gif': 'image/gif',
'.bmp': 'image/bmp',
'.tiff': 'image/tiff',
'.ico': 'image/x-icon'
};

for (let post of posts) {
const link = `${base}${post.slug}${tracking}`;
const { title, excerpt, date } = post;
Expand All @@ -78,17 +90,13 @@ module.exports = async function rssFeed(type, title, desc, outputPath) {
pubDate
};
if (post.cover) {
const enclosure = {};
enclosure["@url"] = base + post.cover;
enclosure["@length"] = 15026; // dummy value, anything works
enclosure["@type"] = 'image/jpeg';
if (typeof enclosure["@url"] === 'string') {
let tmp = enclosure["@url"].toLowerCase();
if (tmp.indexOf('.png') >= 0) enclosure["@type"] = 'image/png';
if (tmp.indexOf('.svg') >= 0) enclosure["@type"] = 'image/svg+xml';
if (tmp.indexOf('.webp') >= 0) enclosure["@type"] = 'image/webp';
}
item.enclosure = enclosure;
const fileExtension = post.cover.substring(post.cover.lastIndexOf('.')).toLowerCase();
const mimeType = mimeTypes[fileExtension] || 'image/jpeg';
item.enclosure = {
"@url": base + post.cover,
"@length": 15026, // dummy value, anything works
"@type": mimeType
};
}
rss.channel.item.push(item)
}
Expand Down