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

Add stable anchors for sections with versions. #47

Merged
merged 3 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
36 changes: 36 additions & 0 deletions changelog.d/20220314_104614_maxking_add_version_anchors.rst
Original file line number Diff line number Diff line change
@@ -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.
..
6 changes: 4 additions & 2 deletions src/scriv/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": """\
Expand Down
2 changes: 1 addition & 1 deletion src/scriv/format_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
nedbat marked this conversation as resolved.
Show resolved Hide resolved
+ "\n"
)

Expand Down
2 changes: 2 additions & 0 deletions tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down