-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Sitemap url and Astro.url mismatch with build.format file #11575
Comments
Thanks! PR would be appreciated in this case. |
I'll try it!, but which one is the good url? with or without file extension? 😅 |
The one without |
I've been investigating and, from what I've discovered (it's my first time delving into the inner workings of Astro), the URL generated during the build process adds the .html extension if build.format is set to "file" https://github.com/withastro/astro/blob/main/packages/astro/src/core/build/generate.ts#L402. This makes me question whether the correct URL should indeed exclude the .html, since it seems to be intentionally included. |
That's the correct URL during the build, but you want to generate a URL that users want to navigate to, and usually users want to have a URL without the html extension |
But AFAIK the URL during the build is the one used by Astro.url.pathname, that's why the canonical url in the build has the .html extension, should the canonical url be formed without the pathname? |
I believe this is caused by this change. It makes the URLs in the sitemap use the format That PR also also makes it difficult to migrate to |
The logic for generating the URL is scattered across different places, and in the end, that's what's causing problems:
I think we could create a utility that generates the URLs (or paths) based on the Astro configuration, and that it should be used everywhere |
I ended up with simple fix, I would like to create that useful but I don't have the knowledge yet for doing it right 😞 |
In my case, with version 4.15.4 of Astro, both the sitemap URLs and the canonical URLs are wrong. They both use the directory-style even though I'm using preserve-style with named files. I've also noticed that the terminal output when running
Even though it actually generates |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When build.format is set to file (or preserve) and Astro builds the html files for each page file, the canonical url generated in build time with Astro.url using:
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
contains the file extension, in the stackblitz example, for page2.astro we have:
<link rel="canonical" href="https://astro.build/page2.html">
But in the sitemap, the location for that page is:
<url><loc>https://astro.build/page2</loc></url>
What's the expected result?
Sitemap urls to be the same as canonical urls build with
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-3v2ky8-nbjmmy?file=src%2Fpages%2Fpage2.astro
Participation
The text was updated successfully, but these errors were encountered: