Skip to content

Add in-site notification feature to Docusaurus #814

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

Merged
merged 19 commits into from
May 9, 2025

Conversation

josh-wong
Copy link
Member

@josh-wong josh-wong commented May 7, 2025

Description

This pull request introduces a new in-site notification feature to enhance visitor engagement by displaying notifications in the navigation bar at the top of the page in both English and Japanese. The changes include adding a custom notification bell component, integrating it into the navbar, and styling it for both desktop and mobile views. Additionally, a data structure and utility functions were implemented to manage notifications dynamically based on user language and read status.

Related issues and/or PRs

N/A

Changes made

Notification feature implementation:

  • src/components/NotificationBell.tsx: Added the NotificationBell component to display notifications, track read/unread status, and handle user interactions. Notifications are fetched dynamically and support language-specific (English or Japanese) messages.
  • src/data/notifications.js: Created this file to define notification data and utility functions, including getNotifications for fetching notifications based on language and detectLanguage for determining the user's language from the URL.
  • src/theme/NavbarItem/index.tsx: Modified to include the custom notification bell in the navbar when the item type is custom-NotificationBell. Notifications are passed dynamically to the component.

Configuration and styling

  • docusaurus.config.js: Updated to import the getNotifications function and add a custom navbar item for the notification bell. [1] [2]
  • src/css/custom.css: Added styles for the notification bell, dropdown, and responsive behavior. Includes support for dark mode and mobile-specific adjustments.

Dependency updates

  • package.json: Added @fortawesome/fontawesome-free for consistent icon usage across the notification bell component.

Checklist

The following is a best-effort checklist. If any items in this checklist are not applicable to this PR or are dependent on other, unmerged PRs, please still mark the checkboxes after you have read and understood each item.

  • I have updated the side navigation as necessary.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

N/A

josh-wong added 15 commits May 1, 2025 21:14
Adjust notification styles for consistency with other dropdown menus.
Clicking a link in the notification dropdown and then clicking another link resulted in a broken link because the relative path was taken into account when then next link was clicked. For example, if the relative link was `AAA/BBB`, then when the link `CCC/DDD` was selected, the URL would be `AAA/CCC/DDD`. This commit ensures that the base URL is called first and then the relative link in the notification message is applied to that base link.
@josh-wong josh-wong requested a review from Copilot May 7, 2025 05:38
@josh-wong josh-wong self-assigned this May 7, 2025
@josh-wong josh-wong added the enhancement New feature or request label May 7, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces an in-site notification feature to enhance visitor engagement on the Docusaurus documentation site. The key changes include adding a custom NotificationBell component, implementing notification data and utility functions, and updating the navbar and configuration to integrate the notification bell.

Reviewed Changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

File Description
src/theme/NavbarItem/index.tsx Integrates the NotificationBell via a condition on the item type
src/data/notifications.js Implements notifications data and utility functions for language-specific handling
src/components/NotificationBell.tsx Develops the NotificationBell component with dynamic notification retrieval and localStorage tracking
docusaurus.config.js Updates the navbar configuration to include a custom notification bell entry
Files not reviewed (2)
  • package.json: Language not supported
  • src/css/custom.css: Language not supported
Comments suppressed due to low confidence (1)

src/theme/NavbarItem/index.tsx:10

  • [nitpick] The 'notifications' prop is declared in the component props but is not used when 'type' equals 'custom-NotificationBell'. Consider either removing this prop or using it if external notification data should override the internal getNotifications call.
notifications?: any[];

@josh-wong josh-wong marked this pull request as draft May 8, 2025 10:14
@josh-wong josh-wong force-pushed the docusaurus/add-in-site-notification-feature branch from e89fa24 to c9835b5 Compare May 8, 2025 11:17
@josh-wong josh-wong marked this pull request as ready for review May 8, 2025 11:19
Implemented content fingerprinting to detect changes in notification messages and URLs. When content changes, the system automatically increments the version number, marking the notification as unread.
@josh-wong josh-wong force-pushed the docusaurus/add-in-site-notification-feature branch from c9835b5 to 1bbb91d Compare May 9, 2025 01:37
Copy link

netlify bot commented May 9, 2025

Deploy Preview for staging-scalardl-docs-site ready!

Name Link
🔨 Latest commit 1bbb91d
🔍 Latest deploy log https://app.netlify.com/sites/staging-scalardl-docs-site/deploys/681d5c543ed4950008f7ee22
😎 Deploy Preview https://deploy-preview-814--staging-scalardl-docs-site.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 44
Accessibility: 95
Best Practices: 92
SEO: 97
PWA: 80
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@josh-wong josh-wong merged commit 019735b into main May 9, 2025
5 checks passed
@josh-wong josh-wong deleted the docusaurus/add-in-site-notification-feature branch May 9, 2025 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant