Skip to content

Commit 5963f20

Browse files
Revathyvenugopal162pyansys-ci-botjorgepiloto
authored
feat: add nerd fonts for autoapi templates icon (#362)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Jorge Martínez <[email protected]>
1 parent f7574dc commit 5963f20

File tree

7 files changed

+50
-16
lines changed

7 files changed

+50
-16
lines changed

doc/changelog.d/362.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat: add nerd fonts for ``autoapi`` templates icon

doc/source/user_guide/autoapi.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ If you are using a ``pyproject.toml`` file, you would define your dependency as
3232
"ansys-sphinx-theme[autoapi]==X.Y.Z",
3333
]
3434
35-
Configuring our Sphinx project
35+
Configuring the Sphinx project
3636
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3737

3838
To use ``sphinx-autoapi`` with the ``ansys-sphinx-theme``, and benefit from the shipped
@@ -71,3 +71,5 @@ do so by modifying the configuration above. The line of code declaring the desir
7171
.. code:: python
7272
7373
autoapi_template_dir = get_autoapi_templates_dir_relative_path(Path(__file__))
74+
75+

doc/styles/config/vocabularies/ANSYS/accept.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ html_context
1212
autoapi
1313
(?i)HTML
1414
CSS
15-
PDF
15+
PDF
16+
namespaces

src/ansys_sphinx_theme/__init__.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,10 @@ def get_autoapi_templates_dir_relative_path(path: pathlib.Path) -> str:
103103
----------
104104
path : pathlib.Path
105105
Path to the desired file.
106-
107106
Returns
108107
-------
109108
str
110109
A string rerpesenting the relative path to the autoapi templates.
111-
112110
"""
113111
return os.path.relpath(
114112
str(AUTOAPI_TEMPLATES_PATH.absolute()), start=str(path.parent.absolute())
@@ -372,6 +370,36 @@ def download_file(url: str, directory: pathlib.Path) -> None:
372370
file.write(response.content)
373371

374372

373+
def replace_html_tag(app, exception):
374+
"""Replace HTML tags in the generated HTML files.
375+
376+
Parameters
377+
----------
378+
app : ~sphinx.application.Sphinx
379+
Application instance for rendering the documentation.
380+
exception : Exception
381+
Exception that occurred during the build process.
382+
"""
383+
if exception is not None:
384+
return
385+
386+
build_dir = pathlib.Path(app.builder.outdir).resolve()
387+
if app.config["extensions"] and "autoapi.extension" not in app.config["extensions"]:
388+
return
389+
api_dir = app.config["autoapi_root"]
390+
api_path = build_dir / api_dir
391+
if not api_path.exists():
392+
return
393+
394+
file_names = list(api_path.rglob("*.html"))
395+
for file_name in file_names:
396+
with open(api_dir / file_name, "r", encoding="utf-8") as file:
397+
content = file.read()
398+
with open(api_dir / file_name, "w", encoding="utf-8") as file:
399+
modified_content = content.replace("&lt;", "<").replace("&gt;", ">")
400+
file.write(modified_content)
401+
402+
375403
def setup(app: Sphinx) -> Dict:
376404
"""Connect to the Sphinx theme app.
377405
@@ -399,12 +427,14 @@ def setup(app: Sphinx) -> Dict:
399427
raise FileNotFoundError(f"Unable to locate ansys-sphinx theme at {CSS_PATH.absolute()}")
400428
app.add_css_file(str(CSS_PATH.relative_to(STATIC_PATH)))
401429
app.add_js_file(str(JS_FILE.relative_to(STATIC_PATH)))
430+
app.config.templates_path.append(str(TEMPLATES_PATH))
402431
app.add_js_file("https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js")
403432
app.add_css_file("https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css")
404433
app.connect("html-page-context", update_footer_theme)
405434
app.connect("html-page-context", fix_edit_html_page_context)
406435
app.connect("html-page-context", add_cheat_sheet)
407-
app.config.templates_path.append(str(TEMPLATES_PATH))
436+
app.add_css_file("https://www.nerdfonts.com/assets/css/webfont.css")
437+
app.connect("build-finished", replace_html_tag)
408438
return {
409439
"version": __version__,
410440
"parallel_read_safe": True,

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/_templates/autoapi/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ to interact with them programmatically.
1010

1111
{% for page in pages %}
1212
{% if (page.top_level_object or page.name.split('.') | length == 3) and page.display %}
13-
🖿 {{ page.name }}<{{ page.include_path }}>
13+
<span class="nf nf-md-package"></span> {{ page.name }}<{{ page.include_path }}>
1414
{% endif %}
1515
{% endfor %}

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/_templates/autoapi/python/module.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
:hidden:
3030

3131
{% for obj in objects_list %}
32-
{{ icon }} {{ obj.short_name }}<{{ obj.include_path }}>
32+
<span class="{{ icon }}"></span> {{ obj.short_name }}<{{ obj.include_path }}>
3333
{% endfor %}
3434
{%- endmacro %}
3535

@@ -165,45 +165,45 @@ Summary
165165

166166
{% block subpackages %}
167167
{% if visible_subpackages %}
168-
{{ toctree_from_objects_list(visible_subpackages, "🖿") }}
168+
{{ toctree_from_objects_list(visible_subpackages, "nf nf-md-package") }}
169169
{% endif %}
170170
{% endblock %}
171171

172172
{% block submodules %}
173173
{% if visible_submodules %}
174-
{{ toctree_from_objects_list(visible_submodules, "🗎") }}
174+
{{ toctree_from_objects_list(visible_submodules, "nf nf-fa-file") }}
175175
{% endif %}
176176
{% endblock %}
177177

178178
{% block class %}
179179
{% if own_page_types and "class" in own_page_types %}
180180
{% if visible_interfaces %}
181-
{{ toctree_from_objects_list(visible_interfaces, "🝆") }}
181+
{{ toctree_from_objects_list(visible_interfaces, "nf nf-cod-symbol_interface") }}
182182
{% endif %}
183183

184184
{% if visible_classes %}
185-
{{ toctree_from_objects_list(visible_classes, "🝆") }}
185+
{{ toctree_from_objects_list(visible_classes, "nf nf-cod-symbol_class") }}
186186
{% endif %}
187187

188188
{% if visible_enums %}
189-
{{ toctree_from_objects_list(visible_enums, "") }}
189+
{{ toctree_from_objects_list(visible_enums, "nf nf-cod-symbol_enum") }}
190190
{% endif %}
191191

192192
{% if visible_exceptions %}
193-
{{ toctree_from_objects_list(visible_exceptions, "🗲") }}
193+
{{ toctree_from_objects_list(visible_exceptions, "nf nf-md-lightning_bolt") }}
194194
{% endif %}
195195
{% endif %}
196196
{% endblock %}
197197

198198
{% block functions %}
199199
{% if own_page_types and visible_functions and "function" in own_page_types %}
200-
{{ toctree_from_objects_list(visible_functions, "𝑓(x)") }}
200+
{{ toctree_from_objects_list(visible_functions, "nf nf-md-function_variant") }}
201201
{% endif %}
202202
{% endblock %}
203203

204204
{% block constants %}
205205
{% if own_page_types and visible_constants and "constant" in own_page_types %}
206-
{{ toctree_from_objects_list(visible_constants, "π") }}
206+
{{ toctree_from_objects_list(visible_constants, "nf nf-cod-symbol_constant") }}
207207
{% endif %}
208208
{% endblock %}
209209

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/theme.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ article_header_start = breadcrumbs.html
1616
footer_end = theme-version.html
1717
pygment_light_style = friendly
1818
pygment_dark_style = monokai
19-
cheatsheet =
19+
cheatsheet =

0 commit comments

Comments
 (0)