Visitar URL original
Add option for removing trailing slash from the root page · Issue #403 · ekalinin/sitemap.js · GitHub
Skip to content

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

Open

Description

@firstpersoncode

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.

Activity

  1. youssefm commented on Dec 18, 2022

    @youssefm

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

  2. GonzaloHirsch commented on Jan 18, 2023

    @GonzaloHirsch

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

  3. GonzaloHirsch commented on Jan 19, 2023

    @GonzaloHirsch

    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.

  4. whidrubeld commented on Sep 18, 2023

    @whidrubeld
      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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions