-
-
Notifications
You must be signed in to change notification settings - Fork 786
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
Conversation
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.
WalkthroughThis 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
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)
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
✅ Deploy Preview for asyncapi-website ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this 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 shorthandsize-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
📒 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.
<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> |
There was a problem hiding this comment.
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:
- Moving the share buttons outside the
Link
component - Adding
onClick
handlers withstopPropagation()
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.
<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
import IconTwitter from '@/components/icons/Twitter'; | ||
import IconLinkedIn from '@/components/icons/LinkedIn'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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
Fixes #3649
Add social sharing buttons for Twitter and LinkedIn to blog posts.
BlogLayout.tsx
IconTwitter
andIconLinkedIn
components.BlogPostItem.tsx
IconTwitter
andIconLinkedIn
components.index.tsx
IconTwitter
andIconLinkedIn
components.