Skip to content

Commit 738af06

Browse files
authored
Add blog post about site notification feature (#147)
* Create 2024-10-28-mobile-sidebar-nav-notifications.jpg * Create 2024-10-28-mobile-sidebar-nav-notifications-style-problem.jpg * Create 2024-10-28-mobile-navbar-notifications-style-problem.jpg * Create 2024-10-28-desktop-navbar-notifications.jpg * Create 2024-11-02-site-notification-feature.mdx * Change file name * Rename file * Make notifications component easier to read * Change notification URL * Revise content
1 parent 0eb3e60 commit 738af06

6 files changed

+73
-3
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
date: 2024-11-20
3+
authors: josh-wong
4+
tags: [open source, software engineering]
5+
image: "assets/images/2024-11-20-desktop-navbar-notifications.jpg"
6+
---
7+
8+
# Adding a notifications feature to my Docusaurus-based site
9+
10+
Recently, I added a notification feature to show noteworthy messages to visitors of my Docusaurus-based site. The purpose of having notifications is to show a short list of new or updated content. While implementing this feature, I faced an unexpected challenge that needed some troubleshooting to ensure a smooth experience, especially on mobile devices.
11+
12+
<!-- truncate -->
13+
14+
## Initial implementation
15+
16+
The first PR ([#118](https://github.com/josh-wong/josh-wong.github.io/pull/118)) was straightforward: Add a bell as a notification icon in the navbar on my Docusaurus-based personal site. This icon, with the number of notifications shown in a red circle, signals whenever notable content has been added. To specify when notable content is available, I add a new message to the custom notifications component, which I add in my Docusaurus configuration file, `docusaurus.config.js`.
17+
18+
The first attempt required the user to update the notifications in the JavaScript file for the custom notification component. However, I was able to modify the code to allow users to update the notification messages in `docusaurus.config.js`. This way of updating notification messages is more in line with how other features, like the [announcement bar](https://docusaurus.io/docs/api/themes/configuration#announcement-bar), work in Docusaurus.
19+
20+
After doing some quick QA on desktop and mobile, I merged the PR. However, I soon noticed some issues on the mobile version of the site.
21+
22+
## Issues on mobile devices
23+
24+
After merging PR [#118](https://github.com/josh-wong/josh-wong.github.io/pull/118), I noticed the following issues on my iPhone:
25+
26+
- In the navbar, the notification icon appeared behind the search icon in the navbar at the top of the screen, causing a visual glitch.
27+
28+
![Problem #1 - Notification icon appears behind the search icon in navbar on mobile](assets/images/2024-11-20-mobile-navbar-notifications-style-problem.jpg)
29+
30+
- In the sidebar nav, the notification count was misaligned with the notification bell icon.
31+
32+
![Problem #2 - Notification icon misaligned in sidebar nav on mobile](assets/images/2024-11-20-mobile-sidebar-nav-notifications-style-problem.jpg)
33+
34+
To prevent disruption on mobile, I reverted the initial PR with a follow-up PR ([#120](https://github.com/josh-wong/josh-wong.github.io/pull/120)) and dug into troubleshooting. After identifying the issue, I moved forward with a refined approach to ensure everything displayed correctly on both desktop and mobile.
35+
36+
## Issues resolved and improvements implemented
37+
38+
The PR ([#121](https://github.com/josh-wong/josh-wong.github.io/pull/121)) restored the notification functionality, with the issues on mobile fixed, and introduced additional improvements:
39+
40+
- **Notifications update dynamically:** Once opened, the notification count decreases automatically.
41+
- **Links open contextually:** Internal links open in the same tab, while external links open in a new tab.
42+
- **Configuration considerations:** To ensure a smooth experience with updating notifications, each new notification must have a unique, incremented `id` in `docusaurus.config.js`. Otherwise, they won't display as new notifications.
43+
44+
The following shows the results of the implemented notifications feature:
45+
46+
How the notifications feature looks in the navbar on desktop:
47+
48+
![Notifications in navbar on desktop](assets/images/2024-11-20-desktop-navbar-notifications.jpg)
49+
50+
How the notifications feature looks in the sidebar nav on mobile:
51+
52+
![Notifications in sidebar nav on mobile](assets/images/2024-11-20-mobile-sidebar-nav-notifications.jpg)
53+
54+
## Wrap-up
55+
56+
The new notification feature is now live on this site, ready to keep visitors informed of noteworthy content. Working through the challenges was a valuable experience, especially needing to consider the mobile aspect, which can vary across devices.
57+
58+
Although the existing announcement bar is great in making single announcements at the top of the page, I think this notification feature could increase visitor interaction on a documentation site.
9.51 KB
Loading
16.1 KB
Loading
11.5 KB
Loading
11.6 KB
Loading

docusaurus.config.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,21 @@ const config = {
243243
type: 'custom-NotificationBell',
244244
position: 'right',
245245
notifications: [
246-
{ id: 1, message: 'New feature!: Site notifications🚨', url: 'https://github.com/josh-wong/josh-wong.github.io/pull/121' },
247-
{ id: 2, message: 'Check out the unofficial Baird beer flavor quadrants🍺', url: '/baird-beer-quadrants' },
248-
{ id: 3, message: 'Enjoy Baird beer? Ask the unofficial AI chatbot for recommendations🤖', url: 'https://typebot.co/baird-beer-recommendations-experimental-080f53' },
246+
{
247+
id: 3,
248+
message: 'New feature!: Site notifications🚨',
249+
url: '/2024/11/20/site-notification-feature'
250+
},
251+
{
252+
id: 2,
253+
message: 'Check out the unofficial Baird beer flavor quadrants🍺',
254+
url: '/baird-beer-quadrants'
255+
},
256+
{
257+
id: 1,
258+
message: 'Enjoy Baird beer? Ask the unofficial AI chatbot for recommendations🤖',
259+
url: 'https://typebot.co/baird-beer-recommendations-experimental-080f53'
260+
},
249261
],
250262
},
251263
{

0 commit comments

Comments
 (0)