Skip to content

Adds option to disable TOC #191

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions changelogs/fragments/190-add-toc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
minor_changes:
- Add a new configuration option ``add_toc`` to the changelog configuration file.
If set to ``false`` (default is ``true``), a table of contents is not added to the top of the changelog.
(https://github.com/ansible-community/antsibull-changelog/pull/191)
5 changes: 5 additions & 0 deletions docs/changelog-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ new configurations.

If set to `false`, the plugin short description is used. If set to `true`, a period is added to the end of the plugin short description if no other end punctuation is present. Setting to `true` complies with the [Ansible changelog format](https://docs.ansible.com/ansible/latest/community/development_process.html#changelogs-how-to-format).

### `add_toc` (boolean)

The default value is `true`.

If set to `true`, a table of contents is added to the top of the changelog.

### `always_refresh` (string)

Expand Down
7 changes: 4 additions & 3 deletions src/antsibull_changelog/changelog_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,16 @@ def generate_to( # pylint: disable=too-many-arguments
if only_latest:
break

def generate(self, only_latest: bool = False) -> str:
def generate(self, only_latest: bool = False, add_toc: bool = True) -> str:
"""
Generate the changelog as reStructuredText.
"""
builder = RstBuilder()

if not only_latest:
builder.set_title(self.get_title())
builder.add_raw_rst(".. contents:: Topics\n")
if add_toc:
builder.add_raw_rst(".. contents:: Topics\n")

if self.changes.ancestor and self.config.mention_ancestor:
builder.add_raw_rst(
Expand Down Expand Up @@ -600,7 +601,7 @@ def generate_changelog( # pylint: disable=too-many-arguments
changelog_path = os.path.join(paths.changelog_dir, changelog_filename)

generator = ChangelogGenerator(config, changes, flatmap=flatmap)
rst = generator.generate(only_latest=only_latest)
rst = generator.generate(only_latest=only_latest, add_toc=config.add_toc)

with open(changelog_path, "wb") as changelog_fd:
changelog_fd.write(rst.encode("utf-8"))
2 changes: 1 addition & 1 deletion src/antsibull_changelog/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _sort_dict_by_key(dictionary: Mapping[str, Any]) -> dict[str, Any]:


def _sort_modules_plugins_objects(
object_list: Sequence[Mapping[str, Any]]
object_list: Sequence[Mapping[str, Any]],
) -> list[dict[str, Any]]:
return sorted(
(_sort_dict_by_key(obj) for obj in object_list), key=lambda obj: obj["name"]
Expand Down
5 changes: 5 additions & 0 deletions src/antsibull_changelog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ class ChangelogConfig:
"alphanumerical",
]
vcs: Literal["none", "auto", "git"]
add_toc: bool

def __init__(
self,
Expand Down Expand Up @@ -480,6 +481,8 @@ def __init__(

self.vcs = self.config.get("vcs", "none")

self.add_toc = self.config.get("add_toc", True)

self._validate_config(ignore_is_other_project)

def _validate_config(self, ignore_is_other_project: bool) -> None:
Expand Down Expand Up @@ -537,6 +540,7 @@ def store(self) -> None: # noqa: C901
"changelog_nice_yaml": self.changelog_nice_yaml,
"changelog_sort": self.changelog_sort,
"vcs": self.vcs,
"add_toc": self.add_toc,
}
if not self.is_collection:
if self.use_semantic_versioning:
Expand Down Expand Up @@ -618,6 +622,7 @@ def default(
"changelog_nice_yaml": False,
"changelog_sort": "alphanumerical",
"vcs": "auto",
"add_toc": True,
}
if title is not None:
config["title"] = title
Expand Down
12 changes: 9 additions & 3 deletions src/antsibull_changelog/rendering/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,19 @@ def generate_to( # pylint: disable=too-many-arguments
if only_latest:
break

def generate(self, renderer: DocumentRenderer, only_latest: bool = False) -> None:
def generate(
self,
renderer: DocumentRenderer,
only_latest: bool = False,
add_toc: bool = True,
) -> None:
"""
Generate the changelog.
"""
if not only_latest:
renderer.set_title(self.get_title())
renderer.add_toc("Topics")
if add_toc:
renderer.add_toc("Topics")

if self.changes.ancestor and self.config.mention_ancestor:
renderer.add_text(
Expand Down Expand Up @@ -413,7 +419,7 @@ def generate_changelog( # pylint: disable=too-many-arguments
renderer = create_document_renderer(
document_format, start_level=1 if only_latest else 0
)
generator.generate(renderer, only_latest=only_latest)
generator.generate(renderer, only_latest=only_latest, add_toc=config.add_toc)

text = renderer.render()
for warning in renderer.get_warnings():
Expand Down