-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Add GitHub reactions system for blog posts to measure community engagement #73
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
Open
belloibrahv
wants to merge
15
commits into
hiero-ledger:main
Choose a base branch
from
belloibrahv:feature/github-reactions-blog-posts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,752
−33
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
86b04d3
feat: Add GitHub reactions system for blog posts
belloibrahv e67e2d2
fix: Address Codacy security and code quality issues
belloibrahv 04bf8e8
fix: Address PR reviewer feedback and improve auto-discovery
belloibrahv 96ddc23
security: Eliminate all Codacy security vulnerabilities
belloibrahv e6d931c
fix: Eliminate remaining Codacy security issues
belloibrahv bc03adc
fix: Eliminate all remaining Codacy security issues
belloibrahv 67daaf8
feat: Implement GitHub reactions on blog posts
belloibrahv c09517e
Hardens the JavaScript against security vulnerabilities flagged by Co…
belloibrahv 61ff8b8
feat: complete GitHub reactions implementation with enhanced UX
belloibrahv 2eb5b5d
security: fix Codacy vulnerabilities in github-reactions.js
belloibrahv a2529ce
security: fix remaining Codacy vulnerabilities in github-reactions.js
belloibrahv 846a9bc
refactor: clean up github-reactions.js to match project standards
belloibrahv ee02369
Fix URL security and lockfile
belloibrahv 3267bfa
feat: Implement GitHub reactions system for blog posts
belloibrahv 38dc872
feat: Redesign GitHub reactions with professional styling
belloibrahv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ resources/ | |
| .idea | ||
| .env | ||
| *.code-workspace | ||
| pnpm-lock.yaml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| +++ | ||
| title = 'GitHub Reactions Demo - Testing Community Engagement' | ||
| featured_image = "/images/Hiero_v4.png" | ||
| date = 2025-01-15T10:00:00-07:00 | ||
| categories = ["Blog", "Demo"] | ||
| duration = "5 min read" | ||
| abstract = "This is a demo post to test the GitHub reactions feature for measuring community engagement with blog posts." | ||
| pr_number = "73" | ||
| [[authors]] | ||
| name = "Hiero Team" | ||
exploreriii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| title = "" | ||
| organization = "" | ||
| link = "" | ||
| image = "/images/profile-hiero.png" | ||
| +++ | ||
|
|
||
| ## 🚀 Testing GitHub Reactions Feature | ||
|
|
||
| This is a demo blog post to test our new GitHub reactions feature. This feature allows readers to react to blog posts through GitHub PR reactions, helping us measure community engagement. | ||
|
|
||
| ### How It Works | ||
|
|
||
| The GitHub reactions feature: | ||
|
|
||
| 1. **Displays reactions** from the corresponding GitHub PR | ||
| 2. **Shows reaction counts** for different emoji types (👍, ❤️, 🚀, etc.) | ||
| 3. **Provides a link** to the GitHub PR for users to add their own reactions | ||
| 4. **Auto-discovers PRs** when no specific PR number is provided | ||
|
|
||
| ### Testing the Feature | ||
|
|
||
| This demo post is linked to [PR #73](https://github.com/hiero-ledger/hiero-website/pull/73) which implements the GitHub reactions feature. You should see the reactions from that PR displayed below. | ||
|
|
||
| ### Features Implemented | ||
|
|
||
| - ✅ GitHub API integration | ||
| - ✅ Reaction caching and rate limiting | ||
| - ✅ Auto-discovery of related PRs | ||
| - ✅ Responsive design with Tailwind CSS | ||
| - ✅ Development mode with mock data | ||
| - ✅ Error handling and fallbacks | ||
| - ✅ Accessibility features | ||
|
|
||
| ### Try It Out | ||
|
|
||
| Visit the [GitHub PR #73](https://github.com/hiero-ledger/hiero-website/pull/73) to add your own reactions, and they should appear on this blog post! | ||
|
|
||
| --- | ||
|
|
||
| ## 💬 Join the Discussion | ||
|
|
||
| We value your feedback on this feature! Visit the [GitHub Pull Request #73](https://github.com/hiero-ledger/hiero-website/pull/73) where this feature was developed to share your thoughts, ask questions, or contribute to the discussion. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| # GitHub Reactions for Blog Posts | ||
|
|
||
| This feature allows blog posts to display GitHub reactions from their corresponding Pull Requests, providing a way to measure community engagement without requiring a backend. | ||
|
|
||
| ## How It Works | ||
|
|
||
| The GitHub reactions system automatically fetches reaction data from GitHub PRs and displays them on blog posts. Users can see community reactions (thumbs up, heart, rocket, etc.) and click through to the GitHub PR to add their own reactions. | ||
|
|
||
| ## Features | ||
|
|
||
| - **Automatic PR Discovery**: If no PR number is specified, the system automatically searches for PRs that modified the blog post | ||
| - **Real-time Reactions**: Fetches current reaction counts from GitHub | ||
| - **Caching**: Implements intelligent caching to respect GitHub API rate limits | ||
| - **Fallback Handling**: Gracefully handles cases where no PR is found | ||
| - **Responsive Design**: Works on all device sizes | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Option 1: Specify PR Number (Recommended) | ||
|
|
||
| Add a `pr_number` field to your blog post frontmatter: | ||
|
|
||
| ```yaml | ||
| +++ | ||
| title = 'Your Blog Post Title' | ||
| date = 2025-01-01T00:00:00Z | ||
| pr_number = "456" # GitHub PR number | ||
| +++ | ||
| ``` | ||
|
|
||
| ### Option 2: Automatic Discovery | ||
|
|
||
| If you don't specify a PR number, the system will automatically search for PRs that modified your blog post file. This works by: | ||
|
|
||
| 1. Searching through recent closed PRs | ||
| 2. Checking which files were modified in each PR | ||
exploreriii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 3. Matching the blog post filename/slug | ||
| 4. Loading reactions from the discovered PR | ||
|
|
||
| ## Supported Reaction Types | ||
|
|
||
| The system supports all standard GitHub reactions: | ||
| - 👍 thumbs up | ||
| - 👎 thumbs down | ||
| - 😄 laugh | ||
| - 🎉 hooray | ||
| - 😕 confused | ||
| - ❤️ heart | ||
| - 🚀 rocket | ||
| - 👀 eyes | ||
|
|
||
| ## Technical Implementation | ||
|
|
||
| ### Files | ||
| - **Shortcode**: `layouts/shortcodes/github-reactions.html` | ||
| - **CSS**: `static/css/github-reactions.css` | ||
| - **JavaScript**: `static/js/github-reactions.js` | ||
| - **Layout Integration**: `layouts/posts/single.html` | ||
|
|
||
| ### API Endpoints Used | ||
| - `GET /repos/hiero-ledger/hiero-website/pulls/{pr_number}/reactions` | ||
| - `GET /repos/hiero-ledger/hiero-website/pulls/{pr_number}` | ||
| - `GET /repos/hiero-ledger/hiero-website/pulls?state=closed&sort=updated&direction=desc&per_page=50` | ||
| - `GET /repos/hiero-ledger/hiero-website/pulls/{pr_number}/files` | ||
|
|
||
| ### Rate Limiting | ||
| - Respects GitHub API rate limits | ||
| - Implements intelligent caching (30-minute cache) | ||
| - Graceful fallback when rate limits are exceeded | ||
|
|
||
| ## Customization | ||
|
|
||
| ### Styling | ||
| The appearance can be customized by modifying `static/css/github-reactions.css`. The component uses CSS custom properties and supports both light and dark modes. | ||
exploreriii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### JavaScript Behavior | ||
| Modify `static/js/github-reactions.js` to change: | ||
| - Cache duration | ||
| - API endpoints | ||
| - Reaction display logic | ||
| - Error handling | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Common Issues | ||
|
|
||
| 1. **No reactions displayed** | ||
| - Check browser console for errors | ||
| - Verify the PR number is correct | ||
| - Ensure the PR has reactions | ||
|
|
||
| 2. **Rate limit errors** | ||
| - The system will show appropriate error messages | ||
| - Reactions will load when rate limits reset | ||
|
|
||
| 3. **PR not found** | ||
| - Verify the PR number exists | ||
| - Check if the PR is public and accessible | ||
|
|
||
| ### Debug Mode | ||
|
|
||
| Open browser console and look for: | ||
| - `🚀 Initializing GitHub reactions...` | ||
| - `Found X reaction containers` | ||
| - `Processing container X: {prNumber, slug}` | ||
|
|
||
| ## Future Enhancements | ||
|
|
||
| - GitHub token support for higher rate limits | ||
| - Real-time updates via GitHub webhooks | ||
| - Analytics integration | ||
| - Custom reaction types | ||
| - Bulk reaction loading for multiple posts | ||
|
|
||
| ## Contributing | ||
|
|
||
| To contribute to this feature: | ||
|
|
||
| 1. Fork the repository | ||
| 2. Make your changes | ||
| 3. Test with different PR scenarios | ||
| 4. Submit a PR with clear description of changes | ||
|
|
||
| ## Support | ||
|
|
||
| For issues or questions: | ||
| 1. Check the browser console for error messages | ||
| 2. Review this documentation | ||
| 3. Open an issue on GitHub with detailed information | ||
| 4. Tag @belloibrahv for assistance | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| {{ $prNumber := .Params.pr_number | default "" }} | ||
| {{ $postSlug := .File.BaseFileName }} | ||
|
|
||
| <div class="github-reactions" data-pr="{{ $prNumber }}" data-slug="{{ $postSlug }}"> | ||
| <div class="reactions-container"> | ||
| <div class="reactions-header"> | ||
| <span class="reactions-label"> | ||
| <svg class="reaction-icon" width="20" height="20" viewBox="0 0 24 24" fill="currentColor"> | ||
| <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm5 11H7v-2h10v2zm0-4H7V7h10v2z"/> | ||
| </svg> | ||
| Community Reactions | ||
| </span> | ||
| <a href="#" class="github-link" target="_blank" rel="noopener" style="display: none;"> | ||
| <span>React on GitHub</span> | ||
| <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"> | ||
| <path d="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z"/> | ||
| </svg> | ||
| </a> | ||
| </div> | ||
| <div class="reactions-list" id="reactions-{{ $postSlug }}"> | ||
| <div class="loading"> | ||
| <div class="loading-spinner"></div> | ||
| <span>Loading reactions...</span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| {{/* layouts/shortcodes/github-reactions.html */}} | ||
| {{ $prNumber := .Get "pr" }} | ||
| {{ $postSlug := .Get "slug" | default .Page.File.BaseFileName }} | ||
|
|
||
| <div class="github-reactions" data-pr="{{ $prNumber }}" data-slug="{{ $postSlug }}"> | ||
| <div class="reactions-container"> | ||
| <div class="reactions-header"> | ||
| <span class="reactions-label"> | ||
| <svg class="reaction-icon" width="16" height="16" viewBox="0 0 16 16" fill="currentColor"> | ||
| <path d="M8 0C3.58 0 0 3.58 0 8c0 4.42 3.58 8 8 8s8-3.58 8-8c0-4.42-3.58-8-8-8zM8 14c-3.31 0-6-2.69-6-6s2.69-6 6-6 6 2.69 6 6-2.69 6-6 6z"/> | ||
| <path d="M5 6.5a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0zM8 6.5a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0zM5.5 9.5c0 1.38 1.12 2.5 2.5 2.5s2.5-1.12 2.5-2.5"/> | ||
| </svg> | ||
| Community reactions | ||
| </span> | ||
| <a href="#" class="github-link" target="_blank" rel="noopener"> | ||
| <span>React on GitHub</span> | ||
| <svg width="12" height="12" viewBox="0 0 16 16" fill="currentColor"> | ||
| <path d="M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2Z"/> | ||
| <path d="M6.854 10.146a.75.75 0 0 1-1.061 1.061L1.646 7.061a.75.75 0 0 1 0-1.061L5.793 1.854a.75.75 0 1 1 1.061 1.061L3.207 6.5H14a.75.75 0 0 1 0 1.5H3.207l3.647 3.646Z"/> | ||
| </svg> | ||
| </a> | ||
| </div> | ||
| <div class="reactions-list" id="reactions-{{ $postSlug }}"> | ||
| <div class="loading"> | ||
| <div class="loading-spinner"></div> | ||
| <span>Loading reactions...</span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.