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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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 Dec 20, 2024 1:17am

@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

import { metadata as defaultMetadata } from "./layout";
Copy link
Owner

Choose a reason for hiding this comment

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

[Non-Actionable] It would be nice if this had an image... but that's definitely out of scope for this PR 😄. Probably a lot more work. I don't even know what that image would look like.

Opinion: someone should file a feature request issue after this suggesting adding image(s) to the metadata. If you want to, awesome - but I can if you don't have time. 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion! I went ahead and created a PR 😄

src/utils/fetchData.ts Show resolved Hide resolved
};
let result: Error | EstimatedPackage[] | undefined;
export async function generateMetadata({ searchParams }: HomeProps) {
const { options, result } = await fetchData(searchParams);
Copy link
Owner

Choose a reason for hiding this comment

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

[Question] Now there are two calls to the Tidelift API per page load 😬. That's probably not ideal? But I don't do enough Next.js app layout code to know the right pattern for this. Do you know if there's a good way to deduplicate? Surely something in Next.js handles this well.

export async function generateMetadata({ searchParams }: HomeProps) {
const { options, result } = await fetchData(searchParams);
const username = options.username || "";
const packageCount = Array.isArray(result) ? result.length : 0;
Copy link
Owner

Choose a reason for hiding this comment

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

[Non-Actionable] Noting from QA: there's no way in the tidelift-me-up package to know that the reason for no packages is that the user didn't exist. Tracked here: JoshuaKGoldberg/tidelift-me-up#17. So, explicitly saying I don't think we need to block the PR on giving a specific description for that. IF you really want to get that in first I'm ok waiting, but otherwise by default I'd just suggest we go with a followup issue. What do you think?

Could not find {username} on npm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with not blocking this PR and instead creating a follow up issue to address this bug. I went ahead and created an issue so this can be fixed when the tidelift-me-up package is updated.

src/app/page.tsx Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for author Needs an action taken by the original poster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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