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

fix: Add html extension if build.format is file #11684

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

fjdelarubia
Copy link

@fjdelarubia fjdelarubia commented Aug 12, 2024

Changes

This change adds .html extension to the sitemap urls if the build.format is set to file, this way the urls will match with the canonical url

In the related issue #11575 @ematipico suggest to remove the .html extension from the urls, not sure about it because the extension is forced in core/build/generate (function getUrlForPath), but I can undo this changes and modify that function

Sample project's structure:

image

Before urls:
https://some-site.com/legal/aviso-legal
https://some-site.com/legal/cookies
https://some-site.com/legal/politica-de-privacidad
https://some-site.com/legal/terminos-y-condiciones
https://some-site.com/legal
https://some-site.com/productos/carteles-personalizados/carteles-para-bodas
https://some-site.com/productos/carteles-personalizados/carteles-para-cumplea%C3%B1os
https://some-site.com/productos/natalicios
https://some-site.com/

After urls:
https://some-site.com/legal/aviso-legal.html
https://some-site.com/legal/cookies.html
https://some-site.com/legal/politica-de-privacidad.html
https://some-site.com/legal/terminos-y-condiciones.html
https://some-site.com/legal.html
https://some-site.com/productos/carteles-personalizados/carteles-para-bodas.html
https://some-site.com/productos/carteles-personalizados/carteles-para-cumplea%C3%B1os.html
https://some-site.com/productos/natalicios.html
https://some-site.com/

Testing

I need some help for the test, would be ok to create new fixture for static build with new build format?

Docs

This PR tries to fix the sitemap behaviour to match the canonical url explained in the docs, see #11575

Copy link

changeset-bot bot commented Aug 12, 2024

🦋 Changeset detected

Latest commit: 692d493

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Aug 12, 2024
@florian-lefebvre florian-lefebvre linked an issue Aug 15, 2024 that may be closed by this pull request
1 task
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is the correct fix. You should not add .html to the final URLs.

@matthewp
Copy link
Contributor

Thanks! The build.format option is only for the build, to tell it how to output files. It doesn't signal what URLs are supposed to look like. That's determined by your server. If you want to have .html in your URLs maybe adding an option in the sitemap integration is a better way to go.

@fjdelarubia
Copy link
Author

Thanks! The build.format option is only for the build, to tell it how to output files. It doesn't signal what URLs are supposed to look like. That's determined by your server. If you want to have .html in your URLs maybe adding an option in the sitemap integration is a better way to go.

I think not only in the sitemap integration, but on the build process the .html extension is added here https://github.com/withastro/astro/blob/main/packages/astro/src/core/build/generate.ts#L375

This url is used for creating the request which renders the page, and it adds the .html extension to the pathname, which makes the canonical url to contain the .html extension.

The .html extension were added here:
cd154e4

If the .html extension should not be visible, nor in the canonical url nor the sitemap, just removing it from the default state would fix it

switch (format) {
		case 'directory':
		case 'preserve': {
			ending = trailingSlash === 'never' ? '' : '/';
			break;
		}
		default: {
			ending = '';
			break;
		}
	}
``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sitemap url and Astro.url mismatch with build.format file
3 participants