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

[ BUG ] Using 'links' option in an entry breaks sitemap generation #397

Open
martinsilha opened this issue Aug 17, 2022 · 10 comments
Open

Comments

@martinsilha
Copy link

Describe the bug
When adding the 'links' option to a sitemap entry that is already working, it is causing sitemap creation to fail validation. From the 'Options you can pass' example:

links: [
    { lang: 'en', url: 'http://test.com/page-1/' },
    { lang: 'ja', url: 'http://test.com/page-1/ja/' }
  ],

Expected behavior
I expected the sitemap to add the <xhtml:link xmlns:xhtml="http://www.w3.org/1999/xhtml" rel="alternate" hreflang="en" href="https://url.example" /> entry to the sitemap, which it does. The problem is that the entire sheet fails validation after doing so.

Context:

  • Library Version 7.1.1

Additional context
I am currently generating the sitemap with the 'Serve a sitemap from a server and periodically update it' example from this package.

@duxor
Copy link

duxor commented Sep 9, 2022

the same for me...

@daniel-minchev
Copy link

bump

@migbash
Copy link

migbash commented Oct 4, 2022

same for me node 16.17.0

@migbash
Copy link

migbash commented Oct 4, 2022

@martinsilha can you show me your sitemap example ? And how does it fail ? Are you not seeing the proper layout in the browser when navigating to sitemap ?

@thisfiore
Copy link

same here, if I add links I don't get xml anymore but just a string with link sequences without structure

@burakDayRoqos
Copy link

burakDayRoqos commented Feb 21, 2023

same for me.

@martinsilha PS: I had to fix this manually by editing all the links starting here

if (news) {
from http to https. Problem seems to be gone now.

@KasperiP
Copy link

KasperiP commented Feb 4, 2024

Thanks for the comment above. This fixed the issue:

const sitemapXml = (await streamToPromise(smStream)).toString();

// Thanks to this comment:
// https://github.com/ekalinin/sitemap.js/issues/397#issuecomment-1438062056
const sitemapXmlHttps = sitemapXml.replace(
new RegExp('http://', 'g'),
'https://',
);

@huntharo
Copy link
Contributor

Ok, when we say "fails validation" I think people are simply talking about browsers rendering of XML right?

Questions

  1. If we're talking about a browser rendering:
    a. Which browser are we talking about? Chrome? Something else?
    b. Are we opening the file locally or from a web server?
    c. If from a web server, what is the exact value of the Content-Type response header and what is the name of the file (e.g. is it sitemap.html or sitemap.xml)?
  2. If we we're talking about something other than browser rendering
    a. please provide a link to the validator

Note that all the Google docs for sitemaps still show all the xmlns links as http:// in their examples. I'd hesitate to change these to https:// to solve a browser rendering issue when it may actually break the sitemaps for crawlers.

https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap

@derduher
Copy link
Collaborator

right, if you change the xmlns attribute to https it will fail validation by the google crawler (at least as of a couple years ago). xmlns looks like a link but is in fact just a specification token. You can go to that in the browser and it will probably redirect you to https but when this was changed several years ago google would flag it as an invalid sitemap.

And yeah gonna need more info on what "fails validation" is.

@akhlivniukallane
Copy link

akhlivniukallane commented Jun 28, 2024

@derduher, I feel like this is not a bug; you are both correct. The only problem is browser XML rendering, but the sitemap itself is entirely correct.

This rendering issue also confused me, but it is a valid sitemap.

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

10 participants