Skip to content

Commit 33753d3

Browse files
svekarsjaneyx99
andauthored
Enable multi-level nav in the left nav bar (#3125)
* Enable multi-level nav in the left nav bar * Update .lycheeignore * Add beginner_source/introyt/introy_index.html to validate_tutorial_built.py to skip building since there is no code * Add .js to keep left nav expanded * Expand only Learn the Basics * Remember user selection for collapsed/uncollapsed content * emove the bullet from the list --------- Co-authored-by: Jane (Yuan) Xu <[email protected]>
1 parent a551cdf commit 33753d3

File tree

11 files changed

+159
-57
lines changed

11 files changed

+159
-57
lines changed

.jenkins/validate_tutorials_built.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
NOT_RUN = [
1212
"beginner_source/basics/intro", # no code
13+
"beginner_source/introyt/introyt_index", # no code
1314
"beginner_source/onnx/intro_onnx",
1415
"beginner_source/profiler",
1516
"beginner_source/saving_loading_models",

.lycheeignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ file:///f:/libtmp/some_file
66

77
#Ignore links with "file:///" to catch any other example links
88
file:\/\/\/.*
9+
10+
# Ignore colab link in the setting of conf.py
11+
https://pytorch.org/tutorials/beginner/colab/n

_static/css/custom2.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,21 @@
1717
margin-bottom: 5px;
1818
}
1919
}
20+
21+
/* Left nav for 2nd level nav */
22+
23+
.pytorch-left-menu li.toctree-l2 {
24+
padding-left: 10px;
25+
}
26+
27+
.pytorch-left-menu li.toctree-l2.current > a, {
28+
color: #ee4c2c;
29+
}
30+
31+
.pytorch-left-menu li.toctree-l2.current a:link.reference.internal {
32+
color: #ee4c2c;
33+
}
34+
35+
.pytorch-left-menu li.toctree-l1.current > a:before {
36+
content: "";
37+
}

_static/js/custom.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
document.addEventListener("DOMContentLoaded", function() {
2+
// Select all <li> elements with the class "toctree-l1"
3+
var toctreeItems = document.querySelectorAll('li.toctree-l1');
4+
5+
toctreeItems.forEach(function(item) {
6+
// Find the link within the item
7+
var link = item.querySelector('a');
8+
var nestedList = item.querySelector('ul');
9+
10+
if (link && nestedList) {
11+
// Create a span element for the "[+]" or "[-]" sign
12+
var expandSign = document.createElement('span');
13+
expandSign.style.cursor = 'pointer'; // Make it look clickable
14+
15+
// Use the link text as a unique key for localStorage
16+
var sectionKey = 'section_' + link.textContent.trim().replace(/\s+/g, '_');
17+
18+
// Retrieve the saved state from localStorage
19+
var isExpanded = localStorage.getItem(sectionKey);
20+
21+
// If no state is saved, default to expanded for "Learn the Basics" and collapsed for others
22+
if (isExpanded === null) {
23+
isExpanded = (link.textContent.trim() === 'Learn the Basics') ? 'true' : 'false';
24+
localStorage.setItem(sectionKey, isExpanded);
25+
}
26+
27+
if (isExpanded === 'true') {
28+
nestedList.style.display = 'block'; // Expand the section
29+
expandSign.textContent = '[-] '; // Show "[-]" since it's expanded
30+
} else {
31+
nestedList.style.display = 'none'; // Collapse the section
32+
expandSign.textContent = '[+] '; // Show "[+]" since it's collapsed
33+
}
34+
35+
// Add a click event to toggle the nested list
36+
expandSign.addEventListener('click', function() {
37+
if (nestedList.style.display === 'none') {
38+
nestedList.style.display = 'block';
39+
expandSign.textContent = '[-] '; // Change to "[-]" when expanded
40+
localStorage.setItem(sectionKey, 'true'); // Save state
41+
} else {
42+
nestedList.style.display = 'none';
43+
expandSign.textContent = '[+] '; // Change back to "[+]" when collapsed
44+
localStorage.setItem(sectionKey, 'false'); // Save state
45+
}
46+
});
47+
48+
// Insert the sign before the link
49+
link.parentNode.insertBefore(expandSign, link);
50+
}
51+
});
52+
});

_templates/layout.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
{% extends "!layout.html" %}
22

3+
4+
<!-- Overrides needed for the multilevel nav -->
5+
{% block menu %}
6+
{% if 'singlehtml' not in builder %}
7+
{% set global_toc = toctree(collapse=theme_collapse_navigation|tobool,
8+
includehidden=theme_includehidden|tobool,
9+
titles_only=True) %}
10+
{% endif %}
11+
{% if global_toc %}
12+
{{ global_toc }}
13+
{% else %}
14+
<!-- Local TOC -->
15+
<div class="local-toc">{{ toc }}</div>
16+
{% endif %}
17+
{% endblock %}
18+
<!-- End of overrides needed for the multilevel nav -->
19+
20+
321
{%- block content %}
422
{{ super() }}
523
<script>
@@ -29,6 +47,7 @@
2947
</div>
3048
{% endblock %}
3149

50+
3251
{% block footer %}
3352
{{ super() }}
3453
<script>

beginner_source/basics/intro.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
===================
1414
1515
Authors:
16-
`Suraj Subramanian <https://github.com/suraj813>`_,
16+
`Suraj Subramanian <https://github.com/subramen>`_,
1717
`Seth Juarez <https://github.com/sethjuarez/>`_,
18-
`Cassie Breviu <https://github.com/cassieview/>`_,
18+
`Cassie Breviu <https://github.com/cassiebreviu/>`_,
1919
`Dmitry Soshnikov <https://soshnikov.com/>`_,
2020
`Ari Bornstein <https://github.com/aribornstein/>`_
2121
@@ -49,6 +49,16 @@
4949
.. include:: /beginner_source/basics/qs_toc.txt
5050
5151
.. toctree::
52+
:maxdepth: 2
5253
:hidden:
5354
55+
quickstart_tutorial
56+
tensorqs_tutorial
57+
data_tutorial
58+
transforms_tutorial
59+
buildmodel_tutorial
60+
autogradqs_tutorial
61+
optimization_tutorial
62+
saveloadrun_tutorial
63+
5464
"""

beginner_source/introyt.rst

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
1-
`Introduction <introyt/introyt1_tutorial.html>`_ ||
2-
`Tensors <introyt/tensors_deeper_tutorial.html>`_ ||
3-
`Autograd <introyt/autogradyt_tutorial.html>`_ ||
4-
`Building Models <introyt/modelsyt_tutorial.html>`_ ||
5-
`TensorBoard Support <introyt/tensorboardyt_tutorial.html>`_ ||
6-
`Training Models <introyt/trainingyt.html>`_ ||
7-
`Model Understanding <introyt/captumyt.html>`_
8-
91
Introduction to PyTorch - YouTube Series
102
========================================
113

12-
Authors:
13-
`Brad Heintz <https://github.com/fbbradheintz>`_
14-
15-
This tutorial follows along with the `PyTorch Beginner Series <https://www.youtube.com/playlist?list=PL_lsbAsL_o2CTlGHgMxNrKhzP97BaG9ZN>`_ on YouTube.
16-
17-
`This tutorial assumes a basic familiarity with Python and Deep Learning concepts.`
18-
19-
Running the Tutorial Code
20-
-------------------------
21-
You can run this tutorial in a couple of ways:
4+
This page has been moved.
225

23-
- **In the cloud**: This is the easiest way to get started! Each section has a Colab link at the top, which opens a notebook with the code in a fully-hosted environment. Pro tip: Use Colab with a GPU runtime to speed up operations *Runtime > Change runtime type > GPU*
24-
- **Locally**: This option requires you to setup PyTorch and torchvision first on your local machine (`installation instructions <https://pytorch.org/get-started/locally/>`_). Download the notebook or copy the code into your favorite IDE.
6+
Redirecting now...
257

26-
.. include:: /beginner_source/introyt/tocyt.txt
8+
.. raw:: html
279

28-
.. toctree::
29-
:hidden:
10+
<meta http-equiv="Refresh" content="0; url='https://pytorch.org/tutorials/beginner/introyt/introyt_index.html'" />

beginner_source/introyt/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Introduction to PyTorch on YouTube
22
----------------------------------
33

4-
1. introyt.rst
4+
1. introyt.py
55
Introduction to PyTorch - Youtube Series
66
https://pytorch.org/tutorials/beginner/introyt/introyt.html
77

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
`Introduction <introyt/introyt1_tutorial.html>`_ ||
3+
`Tensors <introyt/tensors_deeper_tutorial.html>`_ ||
4+
`Autograd <introyt/autogradyt_tutorial.html>`_ ||
5+
`Building Models <introyt/modelsyt_tutorial.html>`_ ||
6+
`TensorBoard Support <introyt/tensorboardyt_tutorial.html>`_ ||
7+
`Training Models <introyt/trainingyt.html>`_ ||
8+
`Model Understanding <introyt/captumyt.html>`_
9+
10+
Introduction to PyTorch - YouTube Series
11+
========================================
12+
13+
Authors:
14+
`Brad Heintz <https://github.com/fbbradheintz>`_
15+
16+
This tutorial follows along with the `PyTorch Beginner Series <https://www.youtube.com/playlist?list=PL_lsbAsL_o2CTlGHgMxNrKhzP97BaG9ZN>`_ on YouTube.
17+
18+
`This tutorial assumes a basic familiarity with Python and Deep Learning concepts.`
19+
20+
Running the Tutorial Code
21+
-------------------------
22+
You can run this tutorial in a couple of ways:
23+
24+
- **On the cloud**: This is the easiest way to get started! Each section has a Colab link at the top, which opens a notebook with the code in a fully-hosted environment. Pro tip: Use Colab with a GPU runtime to speed up operations *Runtime > Change runtime type > GPU*
25+
- **Locally**: This option requires you to set up PyTorch and torchvision on your local machine (`installation instructions <https://pytorch.org/get-started/locally/>`_). Download the notebook or copy the code into your favorite IDE.
26+
27+
.. toctree::
28+
:maxdepth: 2
29+
:hidden:
30+
31+
introyt1_tutorial
32+
tensors_deeper_tutorial
33+
autogradyt_tutorial
34+
modelsyt_tutorial
35+
tensorboardyt_tutorial
36+
trainingyt
37+
captumyt
38+
"""

conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ def reset_seeds(gallery_conf, fname):
304304
'css/custom2.css'
305305
]
306306

307+
html_js_files = [
308+
"js/custom.js",
309+
]
310+
307311
def setup(app):
308312
# NOTE: in Sphinx 1.8+ `html_css_files` is an official configuration value
309313
# and can be moved outside of this function (and the setup(app) function

index.rst

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Welcome to PyTorch Tutorials
7171
:header: Introduction to PyTorch on YouTube
7272
:card_description: An introduction to building a complete ML workflow with PyTorch. Follows the PyTorch Beginner Series on YouTube.
7373
:image: _static/img/thumbnails/cropped/generic-pytorch-logo.png
74-
:link: beginner/introyt.html
74+
:link: beginner/introyt/introyt_index.html
7575
:tags: Getting-Started
7676

7777
.. customcarditem::
@@ -906,7 +906,7 @@ Additional Resources
906906
.. Page TOC
907907
.. -----------------------------------------
908908
.. toctree::
909-
:maxdepth: 2
909+
:maxdepth: 1
910910
:hidden:
911911
:includehidden:
912912
:caption: PyTorch Recipes
@@ -915,39 +915,15 @@ Additional Resources
915915
See All Prototype Recipes <prototype/prototype_index>
916916

917917
.. toctree::
918-
:maxdepth: 2
919918
:hidden:
920919
:includehidden:
921920
:caption: Introduction to PyTorch
922921

923922
beginner/basics/intro
924-
beginner/basics/quickstart_tutorial
925-
beginner/basics/tensorqs_tutorial
926-
beginner/basics/data_tutorial
927-
beginner/basics/transforms_tutorial
928-
beginner/basics/buildmodel_tutorial
929-
beginner/basics/autogradqs_tutorial
930-
beginner/basics/optimization_tutorial
931-
beginner/basics/saveloadrun_tutorial
932-
advanced/custom_ops_landing_page
923+
beginner/introyt/introyt_index
933924

934925
.. toctree::
935-
:maxdepth: 2
936-
:hidden:
937-
:includehidden:
938-
:caption: Introduction to PyTorch on YouTube
939-
940-
beginner/introyt
941-
beginner/introyt/introyt1_tutorial
942-
beginner/introyt/tensors_deeper_tutorial
943-
beginner/introyt/autogradyt_tutorial
944-
beginner/introyt/modelsyt_tutorial
945-
beginner/introyt/tensorboardyt_tutorial
946-
beginner/introyt/trainingyt
947-
beginner/introyt/captumyt
948-
949-
.. toctree::
950-
:maxdepth: 2
926+
:maxdepth: 1
951927
:hidden:
952928
:includehidden:
953929
:caption: Learning PyTorch
@@ -960,7 +936,7 @@ Additional Resources
960936
intermediate/pinmem_nonblock
961937

962938
.. toctree::
963-
:maxdepth: 2
939+
:maxdepth: 1
964940
:includehidden:
965941
:hidden:
966942
:caption: Image and Video
@@ -991,7 +967,7 @@ Additional Resources
991967
intermediate/forced_alignment_with_torchaudio_tutorial
992968

993969
.. toctree::
994-
:maxdepth: 2
970+
:maxdepth: 1
995971
:includehidden:
996972
:hidden:
997973
:caption: Backends
@@ -1010,7 +986,7 @@ Additional Resources
1010986
advanced/pendulum
1011987

1012988
.. toctree::
1013-
:maxdepth: 2
989+
:maxdepth: 1
1014990
:includehidden:
1015991
:hidden:
1016992
:caption: Deploying PyTorch Models in Production

0 commit comments

Comments
 (0)