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 6 commits into
base: master
Choose a base branch
from

Conversation

SahilDahekar
Copy link
Contributor

@SahilDahekar SahilDahekar commented Nov 14, 2024

Description

  • Added support for additional image formats in build-rss.js

image

Related issue(s)

Resolves #3357

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of MIME types for cover images in RSS feeds, enhancing reliability.
  • Refactor

    • Simplified the logic for MIME type assignment by centralizing definitions, improving maintainability.

Copy link

netlify bot commented Nov 14, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 343377d
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/6761b2b4e46b680008046e11
😎 Deploy Preview https://deploy-preview-3396--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

coderabbitai bot commented Nov 14, 2024

Walkthrough

The changes in this pull request focus on improving the MIME type detection logic within the rssFeed function of scripts/build-rss.js. A new constant, mimeTypes, has been introduced to map image file extensions to their corresponding MIME types. This replaces the previous inline logic for determining MIME types, enhancing maintainability. The handling of the enclosure property for posts with cover images has been refactored to simplify the logic while preserving existing error handling.

Changes

File Change Summary
scripts/build-rss.js Introduced mimeTypes constant for MIME type mapping; refactored enclosure handling for cover images.

Assessment against linked issues

Objective Addressed Explanation
Improve image type detection in build-rss.js (#3357)

Possibly related PRs

Suggested labels

ready-to-merge, gsoc

Suggested reviewers

  • akshatnema

Poem

In the code where images dwell,
MIME types now ring a bell.
With a map that's clear and bright,
Cover images take flight.
Errors caught, logic neat,
Building feeds, oh what a feat! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.47%. Comparing base (dc7d0d3) to head (6d18810).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3396      +/-   ##
==========================================
- Coverage   86.59%   86.47%   -0.13%     
==========================================
  Files          21       21              
  Lines         664      658       -6     
==========================================
- Hits          575      569       -6     
  Misses         89       89              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Nov 14, 2024

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 45
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3396--asyncapi-website.netlify.app/

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
scripts/build-rss.js (2)

66-76: LGTM! Well-structured MIME type mapping.

The implementation of mimeTypes constant improves code maintainability by centralizing the MIME type definitions. The coverage of image formats is comprehensive.

Consider adding a helper function to normalize file extensions before lookup:

+    function normalizeExtension(filename) {
+      return filename.substring(filename.lastIndexOf('.')).toLowerCase();
+    }

     const mimeTypes = {
       '.jpeg': 'image/jpeg',
       // ... other mappings
     };

Line range hint 66-99: Consider caching MIME type results.

For better performance in high-traffic scenarios, consider implementing a caching mechanism for MIME type lookups, especially if the RSS feed is generated frequently.

You could use:

  1. In-memory caching for MIME types during runtime
  2. File-based caching for feed generation results
  3. HTTP caching headers in the RSS feed response

This would reduce computational overhead and improve response times for RSS feed consumers.

🧰 Tools
🪛 eslint

[error] 63-63: Replace p with (p)

(prettier/prettier)


[error] 78-78: 'post' is never reassigned. Use 'const' instead.

(prefer-const)


[error] 80-80: 'title' is already declared in the upper scope on line 18 column 47.

(no-shadow)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6f15381 and 4934f57.

📒 Files selected for processing (1)
  • scripts/build-rss.js (2 hunks)
🧰 Additional context used
🪛 eslint
scripts/build-rss.js

[error] 96-96: Replace "@url" with '@url'

(prettier/prettier)


[error] 97-97: Replace "@length" with '@length'

(prettier/prettier)


[error] 98-98: Replace "@type" with '@type'

(prettier/prettier)

🔇 Additional comments (1)
scripts/build-rss.js (1)

93-99: 🛠️ Refactor suggestion

Address string quote consistency and improve enclosure properties.

The enclosure handling logic looks good, but there are a few improvements to consider:

  1. Fix quote consistency as per static analysis:
     item.enclosure = {
-      "@url": base + post.cover,
-      "@length": 15026, // dummy value, anything works
-      "@type": mimeType
+      '@url': base + post.cover,
+      '@length': 15026, // dummy value, anything works
+      '@type': mimeType
     };
  1. Consider replacing the hardcoded length with actual file size:
const https = require('https');

function getFileSize(url) {
  return new Promise((resolve, reject) => {
    https.get(url, (response) => {
      resolve(response.headers['content-length'] || 15026);
    }).on('error', reject);
  });
}

Let's verify the cover image URLs in the posts:

🧰 Tools
🪛 eslint

[error] 96-96: Replace "@url" with '@url'

(prettier/prettier)


[error] 97-97: Replace "@length" with '@length'

(prettier/prettier)


[error] 98-98: Replace "@type" with '@type'

(prettier/prettier)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve image type detection in build-rss.js
2 participants