Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f360156

Browse files
committedJan 21, 2025··
require whatsnew & changelog file names and sidebar pages
1 parent ec2a109 commit f360156

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed
 

‎doc/source/user-guide/options.rst

+15-14
Original file line numberDiff line numberDiff line change
@@ -309,26 +309,27 @@ to the ``html_theme_options`` dictionary:
309309
html_theme_options = (
310310
{
311311
"whatsnew": {
312-
"no_of_headers": 3,
313-
"no_of_contents": 3,
314-
"whatsnew_file": "whatsnew", # Name of yaml file containing what's new content
315-
"changelog_file": "changelog", # Name of changelog file (rst)
316-
"pages": ["changelog", ...],
312+
"whatsnew_file_name": "whatsnew",
313+
"changelog_file_name": "changelog",
314+
"sidebar_pages": ["changelog"],
315+
"sidebar_no_of_headers": 3, # Optional
316+
"sidebar_no_of_contents": 3, # Optional
317317
},
318318
},
319319
)
320320
321321
The dictionary contains the following keys:
322322

323-
- ``no_of_headers``: Number of minor version sections to display in the what's new sidebar.
324-
By default, it is set to 3.
325-
- ``no_of_contents``: Number of what's new content to display under each minor version in the
326-
what's new sidebar. By default, it displays all dropdowns.
327-
- ``whatsnew_file``: Name of the YAML file containing what's new content. The YAML file should be
328-
in the ``doc/source`` directory.
329-
- ``changelog_file``: Name of the changelog file (RST) located in the ``doc/source`` directory.
330-
- ``pages``: List of names for the pages to include the what's new sidebar on. If no value is
331-
provided, the what's new sidebar is only displayed in the changelog file.
323+
- ``whatsnew_file_name``: Name of the YAML file containing what's new content. The YAML file should be
324+
in the ``doc/source`` directory. If not provided, the what's new section will not be generated.
325+
- ``changelog_file_name``: Name of the changelog file (RST) located in the ``doc/source`` directory.
326+
If not provided, the what's new section will not be generated.
327+
- ``sidebar_pages``: List of names for the pages to include the what's new sidebar on. If not
328+
provided, the what's new sidebar is not displayed.
329+
- ``sidebar_no_of_headers``: Number of minor version sections to display in the what's new sidebar.
330+
By default, it displays three version sections in the sidebar.
331+
- ``sidebar_no_of_contents``: Number of what's new content to display under each minor version in the
332+
what's new sidebar. If not provided, it displays all dropdowns by default.
332333

333334
The following images show a sample "What's new" section and sidebar in the changelog file:
334335

‎src/ansys_sphinx_theme/__init__.py

+28-15
Original file line numberDiff line numberDiff line change
@@ -564,30 +564,30 @@ def retrieve_whatsnew_input(app: Sphinx) -> tuple:
564564
# The source directory of the documentation: {repository_root}/doc/source
565565
doc_src_dir = app.env.srcdir
566566

567-
# Get the number of headers to display in the what's new section in the sidebar
568-
# By default, it's 3
569-
no_of_headers = whatsnew_options.get("no_of_headers", 3)
570-
# Get the number of what's new content to display under each minor version in the sidebar.
571-
# By default, it's 3
572-
no_of_contents = whatsnew_options.get("no_of_contents", None)
573-
574-
# Get the name of the whatsnew.yml file in doc/source. By default, it's "whatsnew"
575-
whatsnew_file = whatsnew_options.get("whatsnew_file", "whatsnew")
567+
# Get the name of the whatsnew.yml file in doc/source
568+
whatsnew_file = whatsnew_options.get("whatsnew_file_name", None)
576569
whatsnew_file = pathlib.Path(doc_src_dir) / f"{whatsnew_file}.yml"
577570

578-
# Get the name of the changelog file in doc/source. By default, it's "changelog"
579-
changelog_file = whatsnew_options.get("changelog_file", "changelog")
571+
# Get the name of the changelog file in doc/source
572+
changelog_file = whatsnew_options.get("changelog_file_name", None)
580573
changelog_file = pathlib.Path(doc_src_dir) / f"{changelog_file}.rst"
581574

582-
# Get the pages the whatsnew section should be displayed on. By default, it's changelog
583-
pages = whatsnew_options.get("pages", ["changelog"])
575+
# Get the pages the whatsnew section should be displayed on
576+
pages = whatsnew_options.get("sidebar_pages", None)
577+
578+
# Get the number of headers to display in the what's new section in the sidebar
579+
# By default, it displays the first three minor versions
580+
no_of_headers = whatsnew_options.get("sidebar_no_of_headers", 3)
581+
# Get the number of what's new content to display under each minor version in the sidebar.
582+
# By default, it displays all what's new dropdown titles
583+
no_of_contents = whatsnew_options.get("sidebar_no_of_contents", None)
584584

585585
whatsnew_config = {
586-
"no_of_headers": no_of_headers,
587-
"no_of_contents": no_of_contents,
588586
"whatsnew_file": whatsnew_file,
589587
"changelog_file": changelog_file,
590588
"pages": pages,
589+
"no_of_headers": no_of_headers,
590+
"no_of_contents": no_of_contents,
591591
}
592592

593593
return whatsnew_config
@@ -601,6 +601,10 @@ def add_whatsnew_changelog(app, doctree):
601601
if not whatsnew_config:
602602
return
603603

604+
# Skip this function if the what's new file or changelog file were not provided
605+
if not whatsnew_config["whatsnew_file"] or not whatsnew_config["changelog_file"]:
606+
return
607+
604608
# Read the file and get the sections from the file as a list. For example,
605609
# sections = [<document: <target...><section "getting started; ref-getting-starte ...>]
606610
sections = doctree.traverse(nodes.document)
@@ -934,6 +938,15 @@ def extract_whatsnew(app, doctree, docname):
934938
if not whatsnew_config:
935939
return
936940

941+
# Skip this function if the what's new file or changelog file were not provided
942+
if not whatsnew_config["whatsnew_file"] or not whatsnew_config["changelog_file"]:
943+
return
944+
945+
# Skip this function if the "sidebar_pages" list is not provided in the whatsnew config
946+
if not whatsnew_config["pages"]:
947+
return
948+
949+
# Skip this function if the docname is not in the "sidebar_pages" list
937950
if docname not in whatsnew_config["pages"]:
938951
return
939952

0 commit comments

Comments
 (0)
Please sign in to comment.