Skip to content

Commit

Permalink
Fix documentation
Browse files Browse the repository at this point in the history
This commit fixes multiple issues with documentation.

1. Duplicated requirejs

The nbsphinx extension introduced in #2393 pulled a requirejs
which caused the initialization script to halt.

As a result, the right side bar was left uninitialized.

2. Undefined variable error

It turned out that PyTorch's theme expected the downstream projects
to define `collapsedSections` variable.

Currently console log shows `collapsedSections is not defined`.
As a result of this fix, we start to see the + symbol on left side.

3. Fix the behavior of default expand

Tweaks the right-side bar initialization behavior
so that expand-all only happens once, not at every resize.

4. Overwrite the link to GitHub

The `GitHub` tab in main-menu always linked PyTorch core.
This commit adds overwrite to torchaudio page
  • Loading branch information
mthrok committed May 21, 2022
1 parent 6776299 commit 5c5b5e5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
60 changes: 37 additions & 23 deletions docs/source/_templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
#}

{%- block footer %}

<script type="text/javascript">
var collapsedSections = []
</script>
{{ super() }}
<script type="text/javascript">
$(document).ready(function() {
Expand All @@ -69,30 +71,42 @@
$(".pytorch-call-to-action-links a[data-response='Run in Google Colab']").attr("href", colabLink);
$(".pytorch-call-to-action-links a[data-response='View on Github']").attr("href", githubLink);
}
});
</script>

{% if 'tutorial' in pagename %}
{#
# Override the right side menu bar behavior so that subsections
# are shown by default in tutorial page.
# Based off of
# https://github.com/pytorch/pytorch_sphinx_theme/blob/b4d00058a48604d8fb63771b513a50450f0ee188/pytorch_sphinx_theme/static/js/theme.js#L568-L579
#}
<script type="text/javascript">
$(window).ready(function() {
var original = window.sideMenus.bind;
window.sideMenus.bind = function() {
original();
$("#pytorch-right-menu a.reference.internal").each(function(i) {
if (this.classList.contains("not-expanded")) {
this.nextElementSibling.style.display = "block";
this.classList.remove("not-expanded");
this.classList.add("expanded");
}
});
};
var overwrite = function(_) {
if ($(this).length > 0) {
$(this)[0].href = "https://github.com/pytorch/audio"
}
}
// PC
$(".main-menu a:contains('GitHub')").each(overwrite);
// Mobile
$(".main-menu a:contains('Github')").each(overwrite);
});

{% if 'tutorial' in pagename %}
{#
# Override the right side menu bar behavior so that subsections
# are shown by default in tutorial page.
# Based off of
# https://github.com/pytorch/pytorch_sphinx_theme/blob/b4d00058a48604d8fb63771b513a50450f0ee188/pytorch_sphinx_theme/static/js/theme.js#L568-L579
#}
$(window).ready(function() {
var original = window.sideMenus.bind;
var startup = true;
window.sideMenus.bind = function() {
original();
if (startup) {
$("#pytorch-right-menu a.reference.internal").each(function(i) {
if (this.classList.contains("not-expanded")) {
this.nextElementSibling.style.display = "block";
this.classList.remove("not-expanded");
this.classList.add("expanded");
}
});
startup = false;
}
};
});
</script>
{% endif %}
{% endblock %}
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"nbsphinx",
]

nbsphinx_requirejs_path = ""

autodoc_member_order = "bysource"

# katex options
Expand Down

0 comments on commit 5c5b5e5

Please sign in to comment.