Skip to content
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 dynamic metadata for search results #842

Conversation

maggienegm
Copy link
Contributor

@maggienegm maggienegm commented Dec 20, 2024

PR Checklist

Overview

This PR introduces dynamic metadata generation for the home/search page. It's metadata is now dynamically generated based on the searchParams in the URL:

{username} | Tidelift Me Up
{username} has {packageCount} npm packages eligible for Tidelift funding. 💸

This includes when a valid user has 0 packages eligible for funding based on search parameters. The metadata will look like the following:

{username} | Tidelift Me Up
{username} has 0 npm packages eligible for Tidelift funding. 💸

When no searchParams are provided, the default metadata is used, which is defined in layout.tsx:

Tidelift Me Up
Find your npm packages eligible for Tidelift funding. 💸

Also, something to note is that the API-related logic that was in page.tsx has been extracted into a separate file to improve code readability and maintainability.

Copy link

vercel bot commented Dec 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tidelift-me-up-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 15, 2025 9:30pm

@maggienegm maggienegm force-pushed the feat-dynamic-metadata-for-search-results branch from e22c518 to 5ff089f Compare December 20, 2024 01:17
@maggienegm maggienegm marked this pull request as ready for review December 20, 2024 01:31
@JoshuaKGoldberg
Copy link
Owner

Just noting for future reference, some test values:

Copy link
Owner

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

🚀 This is looking great, thank you so much! Really excited to finally fix this darn accessibility/title bug.

Left a few comments and I think only about half of them are actually blockers. LMK what you think! 🙌

src/app/page.tsx Show resolved Hide resolved
src/app/page.tsx Show resolved Hide resolved
src/utils/fetchData.ts Outdated Show resolved Hide resolved
src/app/page.tsx Outdated Show resolved Hide resolved
src/app/page.tsx Outdated Show resolved Hide resolved
src/app/page.tsx Outdated Show resolved Hide resolved
@maggienegm
Copy link
Contributor Author

maggienegm commented Jan 14, 2025

I just wanted to note that I've added caching to ensure data consistency between the generateMetadata and Home functions. Since these functions are run separately in the Next.js app lifecycle and cannot share data directly, they will still need to call fetchData separately, which includes the risk of data inconsistencies. Caching is one solution to address this.

I didn't see any existing caching in the app, so I chose node-cache. The node-cache package is a non-persistent in-memory caching solution. (Since this app doesn't have a traditional backend, it would store the data temporarily in the server's memory (RAM).) I believe this fits our use case since:
1) we don't need to have the data persist once a user closes the app,
2) and this will also ensure data consistency without having to make more fetch requests than needed.

[See comment below 😅]

With all that being said, would love to hear your thoughts!

@github-actions github-actions bot removed the status: waiting for author Needs an action taken by the original poster label Jan 14, 2025
@maggienegm
Copy link
Contributor Author

maggienegm commented Jan 15, 2025

Replaced node-cache with a built-in cache function.

Copy link
Owner

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

This is great, thanks! The use of cache makes a lot of sense to me.

Wiggling drawn animation of the 100 emoji

@JoshuaKGoldberg JoshuaKGoldberg merged commit 1dc9e6e into JoshuaKGoldberg:main Jan 20, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 Feature: Add SEO meta description tag for search results
2 participants