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: add social sharing buttons for blog posts #3946

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

Arijit-Char
Copy link

@Arijit-Char Arijit-Char commented Mar 22, 2025

feat(blog): add social sharing buttons for blog posts

image

This PR implements issue #3649 (Feature Request #3649) by adding social sharing buttons to blog posts, enabling users to easily share content on social media.

Changes Implemented:

  1. Added Social Sharing Buttons to each blog post for:

    • Twitter
    • LinkedIn
    • Facebook
    • Each button generates a pre-filled sharing link, including the blog post title, URL, and relevant hashtags.
  2. Updated Files:

    • components/layout/BlogLayout.tsx
      • Integrated react-share components for social sharing.
      • Created dynamic share URLs using post.slug and post.title.
    • package.json
      • Added react-share package (^5.2.2).

How This Improves the Blog:

  • Enhances content visibility by enabling easy sharing across social platforms.
  • Improves user engagement by providing an intuitive way to promote blog posts.

Breaking Changes:

  • Yes, this introduces a new dependency (react-share).

Summary by CodeRabbit

  • New Features
    • Social Sharing: Blog posts now feature sharing buttons, allowing users to effortlessly share content on popular social media platforms.
    • Internationalization: Expanded support lays the groundwork for enhanced language capabilities in future updates.
    • Dependency Updates: Added new dependencies for social sharing and internationalization support.

Copy link
Contributor

coderabbitai bot commented Mar 22, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request updates the package.json by adding two new dependencies: react-i18next for internationalization support and react-share for social media sharing. The BlogLayout component is modified to incorporate social media sharing functionality, allowing users to share blog posts on Twitter, LinkedIn, and Facebook with specific URLs, text, and hashtags.

Changes

File Change Summary
package.json Added dependencies: "react-i18next": "^15.4.1" and "react-share": "^5.2.2".
components/layout/BlogLayout.tsx Integrated social media share buttons by importing components from react-share; defined shareUrl, shareText, and hashTags; added JSX to render share buttons; removed AddThis sharing functionality.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant BL as BlogLayout Component
  participant RS as react-share Button
  participant SN as Social Network

  U->>BL: Click share button (Twitter/LinkedIn/Facebook)
  BL->>RS: Provide shareUrl, shareText, hashTags
  RS->>SN: Redirect/share post to selected platform
  SN-->>U: Process share and confirm action
Loading

Possibly related issues

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • derberg
  • akshatnema
  • anshgoyalevil
  • Mayaleeeee
  • devilkiller-ag
  • asyncapi-bot-eve

Poem

I'm a hopping rabbit, coding with glee,
New share buttons now roam wild and free.
Dependencies added with a gentle nudge,
Social media paths no longer a grudge.
I celebrate changes with a joyful leap—
In our code garden, treasures we keep!
🐇💻


🪧 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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

netlify bot commented Mar 22, 2025

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 8397a2b
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67df11b33d001600085d78d8
😎 Deploy Preview https://deploy-preview-3946--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

netlify bot commented Mar 22, 2025

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 01fbfa4
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67e41407482034000820508b
😎 Deploy Preview https://deploy-preview-3946--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
Contributor

@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: 1

🧹 Nitpick comments (4)
components/navigation/BlogPostItem.tsx (4)

61-63: Consider more flexible URL configuration

The hard-coded domain in shareUrl might cause issues in different environments (development, staging, etc.).

Consider using a configurable base URL that can adapt to different environments:

- const shareUrl = `https://www.asyncapi.com${post.slug}`;
+ const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://www.asyncapi.com';
+ const shareUrl = `${baseUrl}${post.slug}`;

101-103: Standardize hashtag format across platforms

The Facebook share button uses a different hashtag format compared to Twitter.

Consider using a consistent approach:

- <FacebookShareButton url={shareUrl} title={shareText} hashtag='#AsyncAPI'>
+ <FacebookShareButton url={shareUrl} title={shareText} hashtag={hashTags[0]}>

Note: Facebook only supports a single hashtag while Twitter supports multiple, so we're using just the first hashtag from the array.


84-105: Consider responsive design for share buttons

The current implementation places the share buttons next to the post type label, which might cause layout issues on smaller screens.

Consider adding responsive styling to ensure the buttons and post type label display properly on all screen sizes:

- className='flex items-center justify-around'
+ className='flex items-center justify-between flex-wrap gap-2'

94-104: Add analytics tracking for share button clicks

Consider tracking social sharing interactions to measure user engagement.

If you're using analytics in your application, consider adding tracking:

<TwitterShareButton 
  url={shareUrl} 
  title={shareText} 
  hashtags={hashTags}
+ onClick={() => {
+   // Example with GoogleAnalytics
+   window.gtag?.('event', 'share', {
+     method: 'twitter',
+     content_type: 'blog',
+     item_id: post.slug,
+   });
+ }}
>
  <TwitterIcon size={32} round />
</TwitterShareButton>

Similar tracking can be added to the other share buttons with their respective platforms.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 281c804 and c141f15.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • components/navigation/BlogPostItem.tsx (3 hunks)
  • package.json (1 hunks)
🔇 Additional comments (3)
package.json (2)

103-103: Appropriate react-share dependency added

The addition of react-share dependency aligns well with the PR objective to implement social sharing buttons for blog posts.


101-101:

❓ Verification inconclusive

Verify the need for react-i18next dependency

The PR adds react-i18next as a dependency, but I don't see it being used in the BlogPostItem component implementation. If it's intended for future internationalization of the share button text, consider either documenting this intention or implementing it now.


🏁 Script executed:

#!/bin/bash
# Check if react-i18next is used anywhere in the codebase
echo "Searching for react-i18next imports..."
rg "from ['\"]react-i18next['\"]" --type ts --type tsx

Length of output: 175


🏁 Script executed:

#!/bin/bash
# Improved search: explicitly glob for both .ts and .tsx files to avoid file-type recognition issues
echo "Searching for react-i18next imports in ts and tsx files..."
rg "from ['\"]react-i18next['\"]" --glob "*.ts" --glob "*.tsx"

Length of output: 195


Action Required: Clarify the Necessity of the react-i18next Dependency

  • Searches across TypeScript and TSX files yielded no references to react-i18next, and the BlogPostItem component doesn’t appear to import or use it.
  • If the dependency is being added to support future internationalization (for instance, for the share button text), please document this planned usage in the code or relevant project documentation.
  • Otherwise, consider removing react-i18next from package.json to eliminate an unused dependency.
components/navigation/BlogPostItem.tsx (1)

5-12: Appropriate component imports from react-share

The necessary imports for social sharing buttons and icons are correctly added from the react-share library.

@Arijit-Char
Copy link
Author

Hi @derberg, @akshatnema, @anshgoyalevil, @Mayaleeeee, and @asyncapi-bot-eve,

I've opened PR #3946 to add social sharing buttons to blog posts. While the feature is working as expected, some checks are failing.

Could you please take a look and provide any insights on fixing them? Also, a review would be greatly appreciated! 🙌

Thanks in advance! 😊

Copy link
Member

Hey @Arijit-Char ,
We had these sharing buttons before in the blog post, but it got into some trouble. We don't need these buttons on the Blog card, instead it should be present inside blog page.

Copy link
Contributor

@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

♻️ Duplicate comments (1)
components/navigation/BlogPostItem.tsx (1)

94-113: 🛠️ Refactor suggestion

Add accessibility attributes and fix formatting issues

The social share buttons should include proper accessibility attributes and follow the project's formatting conventions.

Additionally, there's a naming inconsistency: You're using XIcon but the component is called TwitterShareButton. Consider updating the component names to be consistent with the icons or add a comment explaining the discrepancy.

Fix the formatting and add accessibility attributes:

<div className='ml-2 flex space-x-2' onClick={(e) => e.stopPropagation()}>
  <TwitterShareButton 
    url={shareUrl} 
    title={shareText} 
    hashtags={hashTags}
+   aria-label="Share on Twitter">
    <XIcon size={32} round />
  </TwitterShareButton>
  <LinkedinShareButton 
    url={shareUrl} 
    title={shareText} 
    source='AsyncAPI Blog'
+   aria-label="Share on LinkedIn">
    <LinkedinIcon size={32} round />
  </LinkedinShareButton>
  <FacebookShareButton 
    url={shareUrl} 
    title={shareText} 
    hashtag='#AsyncAPI'
+   aria-label="Share on Facebook">
    <FacebookIcon size={32} round />
  </FacebookShareButton>
</div>
🧰 Tools
🪛 ESLint

[error] 95-98: Replace ⏎······················url={shareUrl}⏎······················title={shareText}⏎····················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)


[error] 101-104: Replace ⏎······················url={shareUrl}⏎······················title={shareText}⏎····················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)


[error] 107-110: Replace ⏎······················url={shareUrl}⏎······················title={shareText}⏎····················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)

🧹 Nitpick comments (1)
components/navigation/BlogPostItem.tsx (1)

84-88: Reconsider component hierarchy for social sharing buttons

The social sharing buttons are currently placed within a Paragraph component, which is not semantically correct. A paragraph element should typically contain text content, not UI controls.

Consider placing the sharing buttons in a separate container:

- <Paragraph
-   typeStyle={ParagraphTypeStyle.sm}
-   textColor='text-indigo-500'
-   className='flex items-center justify-around'
- >
+ <div className='flex items-center justify-around'>
+   <Paragraph
+     typeStyle={ParagraphTypeStyle.sm}
+     textColor='text-indigo-500'
+   >
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c141f15 and 94b1c1a.

📒 Files selected for processing (1)
  • components/navigation/BlogPostItem.tsx (3 hunks)
🧰 Additional context used
🪛 ESLint
components/navigation/BlogPostItem.tsx

[error] 95-98: Replace ⏎······················url={shareUrl}⏎······················title={shareText}⏎····················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)


[error] 101-104: Replace ⏎······················url={shareUrl}⏎······················title={shareText}⏎····················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)


[error] 107-110: Replace ⏎······················url={shareUrl}⏎······················title={shareText}⏎····················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)

🔇 Additional comments (3)
components/navigation/BlogPostItem.tsx (3)

5-12: Good addition of react-share components for social sharing

The import of appropriate components from the react-share library is well structured and provides a good foundation for implementing social sharing functionality.


61-63: Well-defined constants for sharing functionality

The constants are correctly defined:

  • shareUrl properly constructs the URL using the post's slug
  • shareText includes a clear message with the blog post title
  • hashTags contains relevant tags that enhance discoverability

Consider adding a test to ensure these URLs are constructed correctly for various post slugs.


94-113: Consider the placement of share buttons based on user feedback

According to the PR comments, there was a suggestion that share buttons should be placed within the blog page itself rather than on the Blog card. Review this placement decision with the team.

Also, consider if the size of the icons (32px) is appropriate for this context. A visual review would be helpful to ensure these buttons don't overwhelm the card's layout.

🧰 Tools
🪛 ESLint

[error] 95-98: Replace ⏎······················url={shareUrl}⏎······················title={shareText}⏎····················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)


[error] 101-104: Replace ⏎······················url={shareUrl}⏎······················title={shareText}⏎····················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)


[error] 107-110: Replace ⏎······················url={shareUrl}⏎······················title={shareText}⏎····················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)

@Arijit-Char
Copy link
Author

Hey @Arijit-Char , We had these sharing buttons before in the blog post, but it got into some trouble. We don't need these buttons on the Blog card, instead it should be present inside blog page.

Hey @akshatnema ,

Got it! I’ll update the PR to move the sharing buttons inside the blog page instead of the blog card. I'm working on the changes now and will push the updates soon.

Thanks for the clarification!

@Arijit-Char
Copy link
Author

Hey @akshatnema ,

I've updated the PR to move the sharing buttons inside the blog page as requested. The changes are now implemented and ready for review.

Let me know if any further improvements are needed. Thanks!

image

Copy link
Contributor

@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: 1

🧹 Nitpick comments (2)
components/layout/BlogLayout.tsx (2)

49-51: Consider making the shareUrl and hashtags more configurable.

The implementation works but could be improved:

  1. The base URL is hardcoded as "https://www.asyncapi.com". Consider using an environment variable or configuration setting for the base URL to make it more maintainable across environments.

  2. The hashtags are statically defined. Consider making them dynamic based on the blog post's tags or categories if available.

- const shareUrl = `https://www.asyncapi.com${post.slug}`;
+ const shareUrl = `${process.env.NEXT_PUBLIC_SITE_URL || 'https://www.asyncapi.com'}${post.slug}`;
- const hashTags = ['AsyncAPI', 'TechBlog', 'DevCommunity', 'TechTrends'];
+ const hashTags = post.tags ? [...post.tags, 'AsyncAPI'] : ['AsyncAPI', 'TechBlog', 'DevCommunity', 'TechTrends'];

111-112: Consider consistency in hashtag usage across platforms.

For Facebook, you're using a single hashtag with '#AsyncAPI', but for Twitter you're using the array of hashtags. Consider using the same set of hashtags for Facebook by combining them.

- hashtag='#AsyncAPI'>
+ hashtag={hashTags.map(tag => `#${tag}`).join(' ')}>
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94b1c1a and 11a9f3c.

📒 Files selected for processing (1)
  • components/layout/BlogLayout.tsx (3 hunks)
🧰 Additional context used
🪛 ESLint
components/layout/BlogLayout.tsx

[error] 95-98: Replace ⏎····················url={shareUrl}⏎····················title={shareText}⏎··················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)


[error] 101-104: Replace ⏎····················url={shareUrl}⏎····················title={shareText}⏎··················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)


[error] 107-110: Replace ⏎····················url={shareUrl}⏎····················title={shareText}⏎··················· with ·url={shareUrl}·title={shareText}

(prettier/prettier)

🔇 Additional comments (1)
components/layout/BlogLayout.tsx (1)

6-13: Good addition of social sharing components from react-share.

The imported components are appropriate for the feature requirements and enable the sharing functionality on Twitter, LinkedIn, and Facebook platforms.

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.

3 participants