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

sitemap_locales option #25

Merged
merged 1 commit into from
Aug 6, 2020
Merged

sitemap_locales option #25

merged 1 commit into from
Aug 6, 2020

Conversation

liborjelinek
Copy link
Contributor

I propose to add the sitemap_locales configuration option to manually set locales that will show in the sitemap as alternates to page.

I've started to use sphinx-sitemap for my blog at https://blog.documatt.com. It's a single language and likely will stay. It's Sphinx with Ablog extension for blogging. It's a great extension that comes with many supported locales like Chinese, Korean, Spain, etc.

Unfortunately, it means that if another extension like sphinx-sitemap asks for app.builder.config.locale_dirs, the result is a long list of locale_dirs. Former get_locales() will then result in the same long list of locales. But they come from third-party extension!

So I add the sitemap_locales option to manually override locales which I need/want to list in sitemaps. By default, nothing changed (autodetection will take place).

But I can limit alternate URLs (e.g. sitemap_locales = ['es', 'fr']) or completely turn them off (sitemap_locales = [None])

@jdillard
Copy link
Owner

This makes sense, thanks for the pull request! I'm going to try to test this out and merge this week.

Copy link
Owner

@jdillard jdillard left a comment

Choose a reason for hiding this comment

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

This looks good! I'm tempted to change the README example as it seems having the primary language mixed in with the alternatives is "best practice" and I wouldn't want persuade against that: https://en.wikipedia.org/wiki/Sitemaps#Multilingual_and_multinational_Sitemaps

I might use the example of having incomplete translations that you don't want to publish yet instead, as I've run into that with another project that supports translations and we wouldn't actually "turn them on" until they hit a certain percentage of completion. In the end, I think the example you provided works, so don't worry about changing that part.

sphinx_sitemap/__init__.py Show resolved Hide resolved
@liborjelinek
Copy link
Contributor Author

To a multilingual sitemaps: I really dislike this style - primary language in, all languages in xhtml:link including primary, and repeat and xhtml:link for all languages. But it looks it's official way how to describe multilingual website.

Do I understand it correctly that if I have three pages - en/index.html, and alternatives es/index.html and fr/index.html - the following monster is the way how to say it in sitemap?

<url>
          <loc>https://my-site.com/docs/en/index.html</loc>
          <xhtml:link href="https://my-site.com/docs/es/index.html" hreflang="es" rel="alternate"/>
          <xhtml:link href="https://my-site.com/docs/fr/index.html" hreflang="fr" rel="alternate"/>
          <xhtml:link href="https://my-site.com/docs/en/index.html" hreflang="en" rel="alternate"/>
</url>
<url>
          <loc>https://my-site.com/docs/es/index.html</loc>
          <xhtml:link href="https://my-site.com/docs/fr/index.html" hreflang="es" rel="alternate"/>
          <xhtml:link href="https://my-site.com/docs/en/index.html" hreflang="fr" rel="alternate"/>
          <xhtml:link href="https://my-site.com/docs/es/index.html" hreflang="en" rel="alternate"/>
</url>
<url>
          <loc>https://my-site.com/docs/fr/index.html</loc>
          <xhtml:link href="https://my-site.com/docs/en/index.html" hreflang="es" rel="alternate"/>
          <xhtml:link href="https://my-site.com/docs/es/index.html" hreflang="fr" rel="alternate"/>
          <xhtml:link href="https://my-site.com/docs/fr/index.html" hreflang="en" rel="alternate"/>
</url>

@jdillard
Copy link
Owner

jdillard commented Aug 3, 2020

I agree, but I can only assume it is for making the sitemap easier to digest by machines. On this page, under Methods for indicating your alternate pages, it gives a sitemap example (as a dropdown) and states as the first guideline:

Each language version must list itself as well as all other language versions.

https://support.google.com/webmasters/answer/189077

@jdillard jdillard self-assigned this Aug 3, 2020
@jdillard jdillard merged commit 80661d0 into jdillard:master Aug 6, 2020
@jdillard
Copy link
Owner

jdillard commented Aug 6, 2020

Thanks again for this addition!

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

Successfully merging this pull request may close these issues.

2 participants