Skip to content

Commit

Permalink
Add hook for changing 'Edit on GitHub' links (#10)
Browse files Browse the repository at this point in the history
These links are fine by default for normal `.rst` pages, but for sphinx
gallery pages the link ends up being the `.rst` that was generated from
the original `.py`. This adds a hook function that TVM can specify in
its `docs/conf.py` to change the URLs to match the repo structure (in
this case a 1 line regex replace)
  • Loading branch information
driazati authored Oct 25, 2022
1 parent c585046 commit 768ec1d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tlcpack_sphinx_addon/_templates/breadcrumbs.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
{% endfor %}
<li>{{ title }}</li>
{% endblock %}
{% if suffix %}
{% set _edit_url = 'https://github.com/' + github_user + '/' + github_repo + '/' + theme_vcs_pageview_mode + '/' + github_version + pagename + suffix %}
{% if edit_link_hook_fn %}
{% set _edit_url = edit_link_hook_fn(_edit_url) %}
{% endif %}
{% endif %}
{% block breadcrumbs_aside %}
<li class="wy-breadcrumbs-aside">
{% if hasdoc(pagename) %}
Expand All @@ -52,7 +58,7 @@
<!-- User defined GitHub URL -->
<a href="{{ meta['github_url'] }}" class="fa fa-github"> {{ _('Edit on GitHub') }}</a>
{% else %}
<a href="https://{{ github_host|default("github.com") }}/{{ github_user }}/{{ github_repo }}/{{ theme_vcs_pageview_mode|default("blob") }}/{{ github_version }}{{ conf_py_path }}{{ pagename }}{{ suffix }}" class="fa fa-github"> {{ _('Edit on GitHub') }}</a>
<a href="{{ _edit_url }}" class="fa fa-github"> {{ _('Edit on GitHub') }}</a>
{% endif %}
{% elif display_bitbucket %}
{% if check_meta and 'bitbucket_url' in meta %}
Expand Down

0 comments on commit 768ec1d

Please sign in to comment.