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

✨ NEW: Add sitemap_excludes configuration #91

Merged
merged 20 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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']
sphinx-version: ['']
include:
- python-version: '3.11'
Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
Changelog
=========

2.5.2
2.6.0
-----

*Release date: TBD*

* |:wrench:| MAINT: Fix deprecated sphinx.testing.path
`#83 <https://github.com/jdillard/sphinx-sitemap/pull/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 <https://github.com/jdillard/sphinx-sitemap/pull/91>`_

2.5.1
-----
Expand Down
15 changes: 15 additions & 0 deletions docs/source/advanced-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@

html_baseurl = "https://sphinx-sitemap.readthedocs.org/"


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
Expand Down
14 changes: 8 additions & 6 deletions docs/source/configuration-values.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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}``.
Expand All @@ -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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions sphinx_sitemap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
33 changes: 33 additions & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}
13 changes: 6 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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}-sphinx{5,6,7,last}
jdillard marked this conversation as resolved.
Show resolved Hide resolved

[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

Expand Down