Skip to main content

Sitemap generator for Sphinx

Project description

A Sphinx extension to silently generate multiversion and multilanguage sitemaps.org compliant sitemaps for the HTML version of your Sphinx documentation.

Build Status PyPI version Downloads License: MIT

Installing

Directly install via pip by using:

pip install sphinx-sitemap

Add sphinx_sitemap to the extensions array in your Sphinx conf.py. For example:

extensions = ['sphinx_sitemap']

Set the value of html_baseurl in your Sphinx conf.py to the current base URL of your documentation. For example:

html_baseurl = 'https://my-site.com/docs/'

After the HTML build is done, sphinx-sitemap will output the location of the sitemap:

sitemap.xml was generated for URL https://my-site.com/docs/ in /path/to/_build/sitemap.xml

Note: Make sure to confirm the accuracy of the sitemap after installs and upgrades.

Versioning Configuration

For multiversion sitemaps, you have to generate a sitemap per version and then manually add their locations to a sitemapindex file.

The extension will look at the version config value for the current version being built, so make sure that is set.

Note: When using multiple versions, it is best practice to set the canonical URL in the theme layout of all versions to the latest version of that page:

<link rel="canonical" href="https://my-site.com/docs/latest/index.html"/>

Multilingual Configuration

For multilingual sitemaps, you have to generate a sitemap per language/locale and then manually add their locations to a sitemapindex file.

The extension will look at the language config value for the current language being built, and the locale_dirs value for the directory for alternate languages, so make sure those are set.

The end result is something like the following for each language/version build:

<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <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/en/about.html</loc>
    <xhtml:link href="https://my-site.com/docs/es/about.html" hreflang="es" rel="alternate"/>
    <xhtml:link href="https://my-site.com/docs/fr/about.html" hreflang="fr" rel="alternate"/>
    <xhtml:link href="https://my-site.com/docs/en/about.html" hreflang="en" rel="alternate"/>
  </url>
</urlset>

Customizing the URL scheme

If you have both language and version set, the default URL format is {version}{lang}{link}. To change the default behavior, set the value of sitemap_url_scheme in your Sphinx conf.py to the desired format. For example:

sitemap_url_scheme = "{lang}{version}subdir/{link}"

Note: The extension is currently opinionated, in that it automatically appends trailing slashes to both the language and version values. You can also omit values from the scheme for desired behavior.

Getting the Most out of the Sitemap

  1. Add a robots.txt file in the source directory which contains a link to the sitemap or sitemapindex. For example:

    User-agent: *
    
    Sitemap: https://my-site.com/docs/sitemap.xml

    Then, add robots.txt to the html_extra_path config value:

    html_extra_path = ['robots.txt']
  2. Submit the sitemap or sitemapindex to the appropriate search engine tools.

See Who Is Using It

You can use GitHub search or libraries.io to see who is using sphinx-sitemap.

Contributing

Pull Requests welcome! See CONTRIBUTING for instructions on how best to contribute.

License

sphinx-sitemap is made available under a MIT license; see LICENSE for details.

Originally based on the sitemap generator in the guzzle_sphinx_theme project, also licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx-sitemap-2.1.0.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file sphinx-sitemap-2.1.0.tar.gz.

File metadata

  • Download URL: sphinx-sitemap-2.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.9.1 setuptools/20.7.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.5.2

File hashes

Hashes for sphinx-sitemap-2.1.0.tar.gz
Algorithm Hash digest
SHA256 ba3576f38e8d1cabde483dabed2cc2b958af85ff97f2a4442f990b02e967d6a5
MD5 9fc30222274e4f99c0911f71fec8ef46
BLAKE2b-256 d36a081a3b78328957eb9adcfc993cd6165261cdcadd1693d1dd92c8422159cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page