8000 Use pydata theme and reorganize pages for sphinx docs by kandersolar · Pull Request #1173 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Use pydata theme and reorganize pages for sphinx docs #1173

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

Merged
merged 16 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix "view on github" links
  • Loading branch information
kandersolar committed Jun 29, 2021
commit 15a541fca2bfb56f0fbdee674540bb0488274b3e
26 changes: 0 additions & 26 deletions docs/sphinx/source/_templates/breadcrumbs.html

This file was deleted.

19 changes: 19 additions & 0 deletions docs/sphinx/source/_templates/edit-this-page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{#

Modify the "Edit on Github" links to handle auto-generated pages in the
example gallery and the API reference listings. The GH links that sphinx
generates by default make the assumption that an HTML file comes from an RST
file with the same filepath, which isn't the case for autogenerated files. The
logic to generate the correct URL is in conf.py, but we still have to modify
the template here to change the "Edit this page" text to "View on GitHub".

#}

{% if sourcename is defined and theme_use_edit_page_button==true and page_source_suffix %}
{% set src = sourcename.split('.') %}
<div class="tocsection editthispage">
<a href="{{ get_edit_url() }}">
<i class="fab fa-github-square"></i> {{ _("View on GitHub") }}
</a>
</div>
{% endif %}
29 changes: 14 additions & 15 deletions docs/sphinx/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@
# "external_links": [
# {"url": "https://pandas.pydata.org/pandas-docs/stable/", "name": "Pandas Docs"}
# ],
# "github_url": "https://github.com/pandas-dev/pydata-sphinx-theme",
"github_url": "https://github.com/pvlib/pvlib-python",
# "twitter_url": "https://twitter.com/pandas_dev",
# "use_edit_page_button": True,
"use_edit_page_button": True,
"show_toc_level": 1,
# "navbar_align": "right", # For testing that the navbar items align properly
}
Expand Down Expand Up @@ -399,32 +399,30 @@ def get_linenos(obj):
return start, start + len(lines) - 1


def make_github_url(pagename):
def make_github_url(file_name):
"""
Generate the appropriate GH link for a given docs page. This function
is intended for use in sphinx template files.

The target URL is built differently based on the type of page. Sphinx
provides templates with a built-in `pagename` variable that is the path
at the end of the URL, without the extension. For instance,
https://pvlib-python.rtfd.org/en/stable/auto_examples/plot_singlediode.html
will have pagename = "auto_examples/plot_singlediode".
The target URL is built differently based on the type of page. The pydata
sphinx theme has a built-in `file_name` variable that looks like
"/docs/sphinx/source/api.rst" or "generated/pvlib.atmosphere.alt2pres.rst"
"""

URL_BASE = "https://github.com/pvlib/pvlib-python/blob/master/"

# is it a gallery page?
if any(d in pagename for d in sphinx_gallery_conf['gallery_dirs']):
if pagename.split("/")[-1] == "index":
if any(d in file_name for d in sphinx_gallery_conf['gallery_dirs']):
if file_name.split("/")[-1] == "index":
example_file = "README.rst"
else:
example_file = pagename.split("/")[-1] + ".py"
example_file = file_name.split("/")[-1].replace('.rst', '.py')
target_url = URL_BASE + "docs/examples/" + example_file

# is it an API autogen page?
elif "generated" in pagename:
# pagename looks like "generated/pvlib.location.Location"
qualname = pagename.split("/")[-1]
elif "generated" in file_name:
# pagename looks like "generated/pvlib.atmosphere.alt2pres.rst"
qualname = file_name.split("/")[-1].replace('.rst', '')
obj, module = get_obj_module(qualname)
path = module.__name__.replace(".", "/") + ".py"
target_url = URL_BASE + path
Expand All @@ -435,7 +433,7 @@ def make_github_url(pagename):

# Just a normal source RST page
else:
target_url = URL_BASE + "docs/sphinx/source/" + pagename + ".rst"
target_url = URL_BASE + "docs/sphinx/source/" + file_name

return target_url

Expand All @@ -444,4 +442,5 @@ def make_github_url(pagename):
# _templates/breadcrumbs.html
html_context = {
'make_github_url': make_github_url,
'edit_page_url_template': '{{ make_github_url(file_name) }}',
}
0