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

Add option for removing trailing slash from the root page #403

Open
firstpersoncode opened this issue Nov 18, 2022 · 4 comments
Open

Add option for removing trailing slash from the root page #403

firstpersoncode opened this issue Nov 18, 2022 · 4 comments

Comments

@firstpersoncode
Copy link

I'd like to be able to remove trailing slash from the root page.

Right now, when I pass https://example.com as URL, the sitemap will be generated with https://example.com/. This trailing slash can affect the SEO, so it would be nice to have a customization option that would allow us to remove trailing slash from root page.

@youssefm
Copy link

Or even better, if you pass in a root URL without a slash, the sitemap should not add a slash for us.

@GonzaloHirsch
Copy link

@firstpersoncode have you found a workaround for this? I have the same problem you are describing.

@GonzaloHirsch
Copy link

I found a workaround for this, at least until this is included. You can do the following:

  1. Install buffer-replace in the project.
  2. Replace the last line of the sitemap generation file, which is something along the lines of:
return streamToPromise(sitemap);

With the following:

// Imports
import replace from 'buffer-replace';
// ...
return streamToPromise(sitemap).then((buffer) =>
        replace(buffer, '<loc>https://example.com/</loc>', '<loc>https://example.com</loc>')
    );
  1. Now anytime the sitemap is built, the line will be replaced from the buffer directly. It is not ideal, but it does work indeed.

I hope this helps anyone with the same requirement.

@WhidRubeld
Copy link

  const stream = new SitemapStream({
    hostname: BASE_URL,
  })

  return streamToPromise(Readable.from(links).pipe(stream)).then((data) => {
    return data.toString().replace(BASE_URL + '/', BASE_URL)
  })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants