-
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 2 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
Some comments aren't visible on the classic Files Changed page.
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
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,92 @@ | ||
| +++ | ||
| title = 'GitHub Reactions Demo - Community Engagement Feature' | ||
| featured_image = "/images/Hiero_v4.png" | ||
| date = 2024-12-29T12:00:00-07:00 | ||
| categories = ["Blog"] | ||
| duration = "2 min read" | ||
| abstract = "This post demonstrates the new GitHub reactions feature that allows community members to react to blog posts and see engagement metrics." | ||
| pr_number = "456" | ||
| [[authors]] | ||
| name = "Hiero Team" | ||
exploreriii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| title = "Development Team" | ||
| organization = "Hiero" | ||
| link = "" | ||
| image = "/images/profile-hiero.png" | ||
| +++ | ||
|
|
||
| ## 🎉 Introducing GitHub Reactions for Blog Posts | ||
|
|
||
| We're excited to announce a new feature that enhances community engagement on our blog posts! The GitHub reactions system allows community members to react to blog posts using the same reaction system they're familiar with from GitHub. | ||
|
|
||
| ## ✨ How It Works | ||
|
|
||
| This feature automatically fetches reactions from GitHub Pull Requests 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. | ||
|
|
||
| ### Key Features | ||
|
|
||
| - **Real-time Reactions**: See current reaction counts from GitHub | ||
| - **Automatic PR Discovery**: If no PR number is specified, the system automatically searches for PRs that modified the blog post | ||
| - **Smart Caching**: Implements intelligent caching to respect GitHub API rate limits | ||
| - **Responsive Design**: Works perfectly on all device sizes | ||
|
|
||
| ## 🚀 Supported Reaction Types | ||
|
|
||
| The system supports all standard GitHub reactions: | ||
| - 👍 thumbs up | ||
| - 👎 thumbs down | ||
| - 😄 laugh | ||
| - 🎉 hooray | ||
| - 😕 confused | ||
| - ❤️ heart | ||
| - 🚀 rocket | ||
| - 👀 eyes | ||
|
|
||
| ## 📱 Try It Out | ||
|
|
||
| Below this post, you'll see the GitHub reactions component in action. It will automatically load reactions from PR #456 (this demo post's PR number). | ||
|
|
||
| The component shows: | ||
| - A loading state while fetching reactions | ||
| - Real-time reaction counts from GitHub | ||
| - A link to the GitHub PR for adding reactions | ||
| - Graceful fallbacks if no reactions are found | ||
|
|
||
| ## 🔧 Technical Implementation | ||
|
|
||
| This feature is built using: | ||
| - **Frontend**: HTML, CSS, and JavaScript | ||
| - **Backend**: GitHub REST API | ||
| - **Caching**: Intelligent caching with 30-minute TTL | ||
| - **Fallbacks**: Automatic PR discovery and error handling | ||
|
|
||
| ## 🌟 Benefits | ||
|
|
||
| - **Community Engagement**: Measure what resonates with readers | ||
| - **No Backend Required**: Leverages existing GitHub infrastructure | ||
| - **Real-time Data**: Always up-to-date reaction counts | ||
| - **User Experience**: Familiar interface for GitHub users | ||
|
|
||
| ## 📖 Usage | ||
|
|
||
| To enable reactions on your blog post, simply add a `pr_number` field to the frontmatter: | ||
|
|
||
| ```yaml | ||
| +++ | ||
| title = 'Your Post Title' | ||
| pr_number = "123" # GitHub PR number | ||
| +++ | ||
| ``` | ||
|
|
||
exploreriii marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| If no PR number is specified, the system will automatically search for PRs that modified your blog post file. | ||
|
|
||
| ## 🎯 What's Next | ||
|
|
||
| This is just the beginning! Future enhancements could include: | ||
| - GitHub token support for higher rate limits | ||
| - Real-time updates via GitHub webhooks | ||
| - Analytics integration | ||
| - Custom reaction types | ||
|
|
||
| --- | ||
|
|
||
| *Try reacting to this post on GitHub and see your reaction appear here in real-time!* | ||
exploreriii marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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,29 @@ | ||
| {{ $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="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 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" style="display: none;"> | ||
| <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> |
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" style="display: none;"> | ||
| <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.