diff --git a/changelog.d/20220314_104614_maxking_add_version_anchors.rst b/changelog.d/20220314_104614_maxking_add_version_anchors.rst new file mode 100644 index 0000000..db693d1 --- /dev/null +++ b/changelog.d/20220314_104614_maxking_add_version_anchors.rst @@ -0,0 +1,36 @@ +.. A new scriv changelog fragment. +.. +.. Uncomment the header that is right (remove the leading dots). +.. +.. Removed +.. ....... +.. +.. - A bullet item for the Removed category. +.. +Added +..... + +- Add an anchor before each version section in ReST output of ``scriv collect`` + so URLs generated by sphinx for the sections are predictable and stable for + each new version. (Fixes #46) +.. +.. Changed +.. ....... +.. +.. - A bullet item for the Changed category. +.. +.. Deprecated +.. .......... +.. +.. - A bullet item for the Deprecated category. +.. +.. Fixed +.. ..... +.. +.. - A bullet item for the Fixed category. +.. +.. Security +.. ........ +.. +.. - A bullet item for the Security category. +.. diff --git a/src/scriv/config.py b/src/scriv/config.py index 68ca226..1dbcac3 100644 --- a/src/scriv/config.py +++ b/src/scriv/config.py @@ -132,8 +132,10 @@ class _Options: entry_title_template = attr.ib( type=str, default=( - "{% if version %}{{ version }} — {% endif %}" - + "{{ date.strftime('%Y-%m-%d') }}" + "{% if version %}.. _changelog-{{version}}:\n\n" + "{{ version }} — " + "{% endif %}" + "{{ date.strftime('%Y-%m-%d') }}" ), metadata={ "doc": """\ diff --git a/src/scriv/format_rst.py b/src/scriv/format_rst.py index 7269d9a..0a933ae 100644 --- a/src/scriv/format_rst.py +++ b/src/scriv/format_rst.py @@ -103,7 +103,7 @@ def format_header( "\n" + text + "\n" - + self.config.rst_header_chars[0] * len(text) + + self.config.rst_header_chars[0] * len(text.split("\n")[-1]) + "\n" ) diff --git a/tests/test_collect.py b/tests/test_collect.py index 5061965..95fe7ee 100644 --- a/tests/test_collect.py +++ b/tests/test_collect.py @@ -341,6 +341,8 @@ def test_collect_version_in_config(cli_invoke, changelog_d, temp_dir): changelog_text = changelog.read_text(encoding="utf-8") expected = ( "\n" + + ".. _changelog-v12.34b:\n" + + "\n" + "v12.34b — 2020-02-26\n" + "====================\n\n" + "- The first change.\n"