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 to blog posts #3709

Closed
wants to merge 1 commit into from

Conversation

Recxsmacx
Copy link

@Recxsmacx Recxsmacx commented Feb 18, 2025

Fixes #3649

Add social sharing buttons for Twitter and LinkedIn to blog posts.

  • BlogLayout.tsx

    • Import IconTwitter and IconLinkedIn components.
    • Add social sharing buttons for Twitter and LinkedIn at the top of each blog post.
    • Generate pre-filled sharing links including the blog post title and URL.
  • BlogPostItem.tsx

    • Import IconTwitter and IconLinkedIn components.
    • Add social sharing buttons for Twitter and LinkedIn to each blog post item.
    • Generate pre-filled sharing links including the blog post title and URL.
  • index.tsx

    • Import IconTwitter and IconLinkedIn components.

Fixes asyncapi#3649

Add social sharing buttons for Twitter and LinkedIn to blog posts.

* **BlogLayout.tsx**
  - Import `IconTwitter` and `IconLinkedIn` components.
  - Add social sharing buttons for Twitter and LinkedIn at the top of each blog post.
  - Generate pre-filled sharing links including the blog post title and URL.

* **BlogPostItem.tsx**
  - Import `IconTwitter` and `IconLinkedIn` components.
  - Add social sharing buttons for Twitter and LinkedIn to each blog post item.
  - Generate pre-filled sharing links including the blog post title and URL.

* **index.tsx**
  - Import `IconTwitter` and `IconLinkedIn` components.
Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

Walkthrough

This pull request introduces social media sharing functionality for blog posts. It adds new imports for Twitter and LinkedIn icons, dynamically generates share URLs using the blog post's title and slug (with proper URL encoding), and integrates anchor tags with secure attributes to open the links in a new tab. Both the blog layout and navigation components have been updated to include these sharing features, while the blog index page now imports the new icons for potential future use.

Changes

File(s) Summary
components/layout/BlogLayout.tsx
components/navigation/BlogPostItem.tsx
Added social media sharing functionality by importing Twitter and LinkedIn icons, generating share URLs using the post's title and slug, and inserting new <div> elements with anchor tags.
pages/blog/index.tsx Imported Twitter and LinkedIn icons for future use; no functional changes were made.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as Component
    participant SM as Social Media Platform
    U->>C: Click on share icon (Twitter/LinkedIn)
    C->>C: Generate encoded share URL from title and slug
    C->>SM: Open URL in a new tab (with security attributes)
Loading

Suggested labels

ready-to-merge

Suggested reviewers

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

Poem

Oh, I'm a rabbit in this digital land,
Hopping through code with a gentle command.
Twitter and LinkedIn now join the show,
Sharing each post wherever you go.
With swift little hops, our changes are grand!
🐇✨


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

netlify bot commented Feb 18, 2025

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

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

@Recxsmacx
Copy link
Author

Screenshot 2025-02-19 003934
before the solution

Screenshot 2025-02-19 004032
after the solution

@Recxsmacx Recxsmacx changed the title add social sharing buttons to blog posts feat: add social sharing buttons to blog posts Feb 18, 2025
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: 2

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

93-93: Optimize Tailwind CSS classes using shorthand.

Replace h-6 w-6 with the equivalent shorthand size-6 for both icons to improve code maintainability.

-<IconTwitter className='h-6 w-6 text-blue-500 hover:text-blue-700' />
+<IconTwitter className='size-6 text-blue-500 hover:text-blue-700' />
-<IconLinkedIn className='h-6 w-6 text-blue-500 hover:text-blue-700' />
+<IconLinkedIn className='size-6 text-blue-500 hover:text-blue-700' />

Also applies to: 96-96

🧰 Tools
🪛 GitHub Actions: PR testing - if Node project

[warning] 93-93: Classnames 'h-6, w-6' could be replaced by the 'size-6' shorthand! tailwindcss/enforces-shorthand

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b1c7f7c and 4323759.

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

[error] 1-16: Run autofix to sort these imports!

(simple-import-sort/imports)

pages/blog/index.tsx

[error] 1-17: Run autofix to sort these imports!

(simple-import-sort/imports)


[error] 16-16: 'IconTwitter' is defined but never used.

(unused-imports/no-unused-imports)


[error] 16-16: 'IconTwitter' is defined but never used.

(no-unused-vars)


[error] 17-17: 'IconLinkedIn' is defined but never used.

(unused-imports/no-unused-imports)


[error] 17-17: 'IconLinkedIn' is defined but never used.

(no-unused-vars)

🪛 GitHub Actions: PR testing - if Node project
components/navigation/BlogPostItem.tsx

[error] 1-1: Run autofix to sort these imports! simple-import-sort/imports


[warning] 137-137: Classnames 'h-6, w-6' could be replaced by the 'size-6' shorthand! tailwindcss/enforces-shorthand


[warning] 140-140: Classnames 'h-6, w-6' could be replaced by the 'size-6' shorthand! tailwindcss/enforces-shorthand

components/layout/BlogLayout.tsx

[error] 1-1: Run autofix to sort these imports! simple-import-sort/imports


[warning] 93-93: Classnames 'h-6, w-6' could be replaced by the 'size-6' shorthand! tailwindcss/enforces-shorthand


[warning] 96-96: Classnames 'h-6, w-6' could be replaced by the 'size-6' shorthand! tailwindcss/enforces-shorthand

pages/blog/index.tsx

[error] 1-1: Run autofix to sort these imports! simple-import-sort/imports


[error] 16-16: 'IconTwitter' is defined but never used. unused-imports/no-unused-imports


[error] 16-16: 'IconTwitter' is defined but never used. no-unused-vars


[error] 17-17: 'IconLinkedIn' is defined but never used. unused-imports/no-unused-imports


[error] 17-17: 'IconLinkedIn' is defined but never used. no-unused-vars

⏰ Context from checks skipped due to timeout of 180000ms (2)
  • GitHub Check: Notify-triagers
  • GitHub Check: Lighthouse CI
🔇 Additional comments (1)
components/layout/BlogLayout.tsx (1)

44-45: LGTM! Secure URL construction.

The share URLs are properly constructed using encodeURIComponent for both the title and URL parameters, preventing XSS vulnerabilities.

Comment on lines +135 to +142
<div className='mt-4 flex space-x-4'>
<a href={twitterShareUrl} target='_blank' rel='noopener noreferrer' aria-label='Share on Twitter'>
<IconTwitter className='h-6 w-6 text-blue-500 hover:text-blue-700' />
</a>
<a href={linkedInShareUrl} target='_blank' rel='noopener noreferrer' aria-label='Share on LinkedIn'>
<IconLinkedIn className='h-6 w-6 text-blue-500 hover:text-blue-700' />
</a>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider UX impact of share buttons placement.

The share buttons are currently placed inside a clickable card (Link component). This could lead to accidental navigation when users try to share the post. Consider either:

  1. Moving the share buttons outside the Link component
  2. Adding onClick handlers with stopPropagation() to prevent card navigation
           </div>
         </div>
+      </span>
+    </Link>
+    <div className='mt-4 flex space-x-4'>
+      <a
+        href={twitterShareUrl}
+        target='_blank'
+        rel='noopener noreferrer'
+        aria-label='Share on Twitter'
+        onClick={(e) => e.stopPropagation()}
+      >
+        <IconTwitter className='size-6 text-blue-500 hover:text-blue-700' />
+      </a>
+      <a
+        href={linkedInShareUrl}
+        target='_blank'
+        rel='noopener noreferrer'
+        aria-label='Share on LinkedIn'
+        onClick={(e) => e.stopPropagation()}
+      >
+        <IconLinkedIn className='size-6 text-blue-500 hover:text-blue-700' />
+      </a>
+    </div>
-        <div className='mt-4 flex space-x-4'>
-          <a href={twitterShareUrl} target='_blank' rel='noopener noreferrer' aria-label='Share on Twitter'>
-            <IconTwitter className='h-6 w-6 text-blue-500 hover:text-blue-700' />
-          </a>
-          <a href={linkedInShareUrl} target='_blank' rel='noopener noreferrer' aria-label='Share on LinkedIn'>
-            <IconLinkedIn className='h-6 w-6 text-blue-500 hover:text-blue-700' />
-          </a>
-        </div>
-      </div>
-    </span>
-  </Link>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div className='mt-4 flex space-x-4'>
<a href={twitterShareUrl} target='_blank' rel='noopener noreferrer' aria-label='Share on Twitter'>
<IconTwitter className='h-6 w-6 text-blue-500 hover:text-blue-700' />
</a>
<a href={linkedInShareUrl} target='_blank' rel='noopener noreferrer' aria-label='Share on LinkedIn'>
<IconLinkedIn className='h-6 w-6 text-blue-500 hover:text-blue-700' />
</a>
</div>
</div>
</div>
</span>
</Link>
<div className='mt-4 flex space-x-4'>
<a
href={twitterShareUrl}
target='_blank'
rel='noopener noreferrer'
aria-label='Share on Twitter'
onClick={(e) => e.stopPropagation()}
>
<IconTwitter className='size-6 text-blue-500 hover:text-blue-700' />
</a>
<a
href={linkedInShareUrl}
target='_blank'
rel='noopener noreferrer'
aria-label='Share on LinkedIn'
onClick={(e) => e.stopPropagation()}
>
<IconLinkedIn className='size-6 text-blue-500 hover:text-blue-700' />
</a>
</div>
🧰 Tools
🪛 GitHub Actions: PR testing - if Node project

[warning] 137-137: Classnames 'h-6, w-6' could be replaced by the 'size-6' shorthand! tailwindcss/enforces-shorthand


[warning] 140-140: Classnames 'h-6, w-6' could be replaced by the 'size-6' shorthand! tailwindcss/enforces-shorthand

Comment on lines +16 to +17
import IconTwitter from '@/components/icons/Twitter';
import IconLinkedIn from '@/components/icons/LinkedIn';
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused imports.

The IconTwitter and IconLinkedIn imports are not used in this component. Remove them to keep the code clean and prevent bundle size bloat.

-import IconTwitter from '@/components/icons/Twitter';
-import IconLinkedIn from '@/components/icons/LinkedIn';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import IconTwitter from '@/components/icons/Twitter';
import IconLinkedIn from '@/components/icons/LinkedIn';
// (No imports for IconTwitter or IconLinkedIn; they have been removed)
🧰 Tools
🪛 ESLint

[error] 1-17: Run autofix to sort these imports!

(simple-import-sort/imports)


[error] 16-16: 'IconTwitter' is defined but never used.

(unused-imports/no-unused-imports)


[error] 16-16: 'IconTwitter' is defined but never used.

(no-unused-vars)


[error] 17-17: 'IconLinkedIn' is defined but never used.

(unused-imports/no-unused-imports)


[error] 17-17: 'IconLinkedIn' is defined but never used.

(no-unused-vars)

🪛 GitHub Actions: PR testing - if Node project

[error] 16-16: 'IconTwitter' is defined but never used. unused-imports/no-unused-imports


[error] 16-16: 'IconTwitter' is defined but never used. no-unused-vars


[error] 17-17: 'IconLinkedIn' is defined but never used. unused-imports/no-unused-imports


[error] 17-17: 'IconLinkedIn' is defined but never used. no-unused-vars

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.

[FEATURE] <Social Sharing Buttons on Blogs>
1 participant