diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 7515900..7f5bff3 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -20,15 +20,17 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] sphinx-version: [''] include: - - python-version: '3.11' + - python-version: '3.12' sphinx-version: 'dev' - - python-version: '3.10' + - python-version: '3.11' sphinx-version: '7' - - python-version: '3.9' + - python-version: '3.10' sphinx-version: '6' + - python-version: '3.9' + sphinx-version: '5' - python-version: '3.8' sphinx-version: '5' steps: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1ea7a09..335e192 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,14 +3,16 @@ Changelog ========= -2.5.2 +2.6.0 ----- *Release date: TBD* * |:wrench:| MAINT: Fix deprecated sphinx.testing.path `#83 `_ -* Drop test support for Sphinx 2, 3, and 4. +* Drop test support for Python 3.7 and Sphinx 2, 3, and 4. +* |:sparkles:| NEW: Add sitemap_excludes configuration + `#91 `_ 2.5.1 ----- diff --git a/docs/source/advanced-configuration.rst b/docs/source/advanced-configuration.rst index 0aa0f8d..a3cd8c1 100644 --- a/docs/source/advanced-configuration.rst +++ b/docs/source/advanced-configuration.rst @@ -125,5 +125,20 @@ To generate the primary language with no alternatives, set :confval:`sitemap_loc For multilingual sitemaps, generate a sitemap per language and then manually add each to a `sitemapindex.xml`_ file. +.. _configuration_excluding_pages: + +Excluding Pages +^^^^^^^^^^^^^^^ + +To exclude a set of pages, add each page's path to ``sitemap_exclude``: + +.. code-block:: python + + sitemap_excludes = [ + "search.html", + "genindex.html", + ] + + .. _sitemapindex.xml: https://support.google.com/webmasters/answer/75712?hl=en .. _sitemaps.org: https://www.sitemaps.org/protocol.html diff --git a/docs/source/conf.py b/docs/source/conf.py index fda7d90..29ae58f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -115,6 +115,7 @@ html_baseurl = "https://sphinx-sitemap.readthedocs.org/" + # -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. diff --git a/docs/source/configuration-values.rst b/docs/source/configuration-values.rst index 12cc37b..3cf4be7 100644 --- a/docs/source/configuration-values.rst +++ b/docs/source/configuration-values.rst @@ -3,12 +3,6 @@ Project Configuration Values A list of of possible configuration values to configure in **conf.py**: -Another line to :math:`test two two` - -.. math:: - - test two two - .. confval:: sitemap_url_scheme The scheme used for URL structure. Default is ``{lang}{version}{link}``. @@ -32,3 +26,11 @@ Another line to :math:`test two two` See :ref:`configuration_supporting_multiple_languages` for more information. .. versionadded:: 2.2.0 + +.. confval:: sitemap_excludes + + The list of pages to exclude from the sitemap. + + See :ref:`configuration_excluding_pages` for more information. + + .. versionadded:: 2.6.0 diff --git a/pyproject.toml b/pyproject.toml index 57c4ae6..ac5034e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,6 @@ maintainers = [ classifiers = [ "License :: OSI Approved :: MIT License", "Topic :: Documentation :: Sphinx", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", diff --git a/sphinx_sitemap/__init__.py b/sphinx_sitemap/__init__.py index 0668fbb..7779093 100644 --- a/sphinx_sitemap/__init__.py +++ b/sphinx_sitemap/__init__.py @@ -21,7 +21,7 @@ from sphinx.application import Sphinx from sphinx.util.logging import getLogger -__version__ = "2.5.1" +__version__ = "2.6.0" logger = getLogger(__name__) @@ -42,6 +42,8 @@ def setup(app: Sphinx) -> Dict[str, Any]: app.add_config_value("sitemap_filename", default="sitemap.xml", rebuild="") + app.add_config_value("sitemap_excludes", default=[], rebuild="") + try: app.add_config_value("html_baseurl", default=None, rebuild="") except BaseException: @@ -143,7 +145,8 @@ def add_html_link(app: Sphinx, pagename: str, templatename, context, doctree): else: sitemap_link = pagename + file_suffix - env.app.sitemap_links.put(sitemap_link) # type: ignore + if sitemap_link not in app.builder.config.sitemap_excludes: + env.app.sitemap_links.put(sitemap_link) # type: ignore def create_sitemap(app: Sphinx, exception): diff --git a/tests/test_simple.py b/tests/test_simple.py index eb83a56..a27f4d2 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -99,3 +99,36 @@ def test_simple_dirhtml(app, status, warning): "search/", ] } + + +@pytest.mark.sphinx( + "html", + freshenv=True, + confoverrides={ + "html_baseurl": "https://example.org/docs/", + "language": "en", + "sitemap_excludes": ["search.html", "genindex.html"], + }, +) +def test_simple_excludes(app, status, warning): + app.warningiserror = True + app.build() + assert "sitemap.xml" in os.listdir(app.outdir) + doc = etree.parse(app.outdir / "sitemap.xml") + urls = { + e.text + for e in doc.findall(".//{http://www.sitemaps.org/schemas/sitemap/0.9}loc") + } + + assert urls == { + f"https://example.org/docs/en/{d}.html" + for d in [ + "index", + "foo", + "bar", + "lorem", + "ipsum", + "dolor", + "elitr", + ] + } diff --git a/tox.ini b/tox.ini index 97f473a..ff201c2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,18 +1,17 @@ [tox] envlist = - py37-sphinx5 - # Python 3.7 unsupported above Sphinx 6 - py3{8,9}-sphinx{5,6,last} + py3{8,9}-sphinx{5,6,7,last} # Python 3.10 is unsupported below Sphinx4 # See https://github.com/sphinx-doc/sphinx/issues/9816 - py3{10,11}-sphinx{5,6,last} + py3{10,11,12}-sphinx{5,6,7,last} [testenv] deps = pytest - sphinx5: Sphinx~=5.0 - sphinx6: Sphinx~=6.0 - sphinxlast: Sphinx + sphinx5: Sphinx[test]~=5.0 + sphinx6: Sphinx[test]~=6.0 + sphinx7: Sphinx[test]~=7.0 + sphinxlast: Sphinx[test] commands = pytest -W ignore::DeprecationWarning