Skip to content

Commit

Permalink
Switch from top_line to render_title (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ConorMacBride authored Aug 31, 2022
1 parent 1720dbd commit bc25fc2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
7 changes: 3 additions & 4 deletions changelog/template.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{% if top_line %}

{{ top_underline * ((top_line)|length)}}
{% elif versiondata.name %}
{% if render_title %}
{% if versiondata.name %}
{{ versiondata.name }} {{ versiondata.version }} ({{ versiondata.date }})
{{ top_underline * ((versiondata.name + versiondata.version + versiondata.date)|length + 4)}}
{% else %}
{{ versiondata.version }} ({{ versiondata.date }})
{{ top_underline * ((versiondata.version + versiondata.date)|length + 3)}}
{% endif %}
{% endif %}
{% for section, _ in sections.items() %}
{% set underline = underlines[0] %}{% if section %}{{section}}
{{ underline * section|length }}{% set underline = underlines[1] %}
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ python_requires = >=3.6
setup_requires = setuptools_scm
install_requires =
sphinx
towncrier>=21.3.0
towncrier>=22.8.0

[options.extras_require]
all =
Expand Down
22 changes: 12 additions & 10 deletions sphinx_changelog/towncrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,32 @@ def generate_changelog_for_docs(directory, skip_if_empty=True, underline=1):

project_date = _get_date().strip()

title_format = config["title_format"] or "{name} {version} ({project_date})"
top_line = title_format.format(
name=project_name, version=project_version, project_date=project_date
)
# Custom title formats can only be added after rendering
render_title = False if config["title_format"] else True

rendered = render_fragments(
template,
config["issue_format"],
top_line,
fragments,
definitions,
config["underlines"][underline+1:],
config["wrap"],
{"name": project_name, "version": project_version, "date": project_date},
top_underline=config["underlines"][underline],
all_bullets=config["all_bullets"],
render_title=render_title,
)

os.chdir(curdir)

# To work around https://github.com/twisted/towncrier/issues/346 we check
# to see if the template is going to write the top_line, and if it isn't
# then we write it.
if "{{ top_line }}" not in template:
rendered = top_line + rendered
if not render_title: # Prepend the custom title format
top_line = config["title_format"].format(
name=project_name, version=project_version, project_date=project_date
)
rendered = "\n".join([
top_line,
config["underlines"][underline] * len(top_line),
rendered,
])

return rendered

0 comments on commit bc25fc2

Please sign in to comment.