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

Docs: Wrong Example Code #62947

Closed
theDeal opened this issue Mar 6, 2024 · 3 comments · Fixed by #62960
Closed

Docs: Wrong Example Code #62947

theDeal opened this issue Mar 6, 2024 · 3 comments · Fixed by #62960
Labels
Documentation Related to Next.js' official documentation. good first issue Easy to fix issues, good for newcomers locked

Comments

@theDeal
Copy link

theDeal commented Mar 6, 2024

What is the improvement or update you wish to see?

On this Page
The TS Type from the function sitemap is wrong.

Right Now:

export default async function sitemap({
  id,
}: {
  id: number
}): MetadataRoute.Sitemap {
  // Google's limit is 50,000 URLs per sitemap
  const start = id * 50000
  const end = start + 50000
  const products = await getProducts(
    `SELECT id, date FROM products WHERE id BETWEEN ${start} AND ${end}`
  )
  return products.map((product) => ({
    url: `${BASE_URL}/product/${product.id}`
    lastModified: product.date,
  }))
}

Corrected Version:

export default async function sitemap({
  id,
}: {
  id: number
}): Promise<MetadataRoute.Sitemap> {
  // Google's limit is 50,000 URLs per sitemap
  const start = id * 50000
  const end = start + 50000
  const products = await getProducts(
    `SELECT id, date FROM products WHERE id BETWEEN ${start} AND ${end}`
  )
  return products.map((product) => ({
    url: `${BASE_URL}/product/${id}`,
    lastModified: product.date,
  }))
}

Difference:

: MetadataRoute.Sitemap to : Promise<MetadataRoute.Sitemap>

Is there any context that might help us understand?

Should be understandable

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap

@theDeal theDeal added the Documentation Related to Next.js' official documentation. label Mar 6, 2024
@balazsorban44 balazsorban44 added the good first issue Easy to fix issues, good for newcomers label Mar 6, 2024
Copy link
Contributor

github-actions bot commented Mar 6, 2024

The issue was marked with the good first issue label by a maintainer.

This means that it is a good candidate for someone interested in contributing to the project, but does not know where to start.

To get started, read the Contributing Guide. When you are ready, open a PR and link back to this issue in the form of adding Fixes #1234 to the PR description, where 1234 is the issue number. This will automatically close the issue when the PR gets merged, making it easier for us to keep track of what has been fixed.

Please remember to add tests to confirm your code changes will fix the issue and we do not regress in the future.

If you have any questions, feel free to ask below or on the PR. Generally, you don't need to @mention anyone directly, as we will get notified anyway and will respond as soon as we can.

Note

There is no need to ask for permission "can I work on this?" Please, go ahead if there is no linked PR 🙂

@balazsorban44
Copy link
Member

elenistvr added a commit to elenistvr/next.js that referenced this issue Mar 6, 2024
ijjk added a commit that referenced this issue Mar 6, 2024
Closes #62947

This PR fixes the TS Type from the function sitemap.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Related to Next.js' official documentation. good first issue Easy to fix issues, good for newcomers locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants