Skip to content

Commit fc5b96a

Browse files
committed
Add guide for tabs
1 parent f5ab07f commit fc5b96a

12 files changed

+214
-3
lines changed

docs/guides/guide_installation.rst

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Local Installation
66
==================
77

88
.. tip::
9-
When you need to write a lot of documentation, it's a **good idea** to do it all locally.
9+
When you need to write a lot of documentation, it's a **good idea to do it all locally.**
1010

1111

1212
1. Cloning the Repo
@@ -77,6 +77,7 @@ You can open the file :code:`docs/index.html` on your computer to view the HTML
7777
.. tip::
7878

7979
This option is probably the one you want.
80+
8081
The :code:`sphinx-autobuild` extension allows us to build local documentation whenever we make changes.
8182
It also refreshes the web browser so you can see the changes "live". This makes it **very convenient for rapid development**.
8283

@@ -137,7 +138,7 @@ We will be reviewing the workflow that :code:`sphinx-documentation-demo` uses.
137138

138139
You can find the workflow in :code:`sphinx-documentation-demo/.github/workflows/documentation.yml`
139140

140-
.. code-block:: yml
141+
.. code-block::
141142
:emphasize-lines: 16,19,24,26
142143
:linenos:
143144
@@ -180,3 +181,29 @@ You can find the workflow in :code:`sphinx-documentation-demo/.github/workflows/
180181
* **Note**: this needs to be the same branch that GitHub Pages is set to publish with.
181182
* **Line 26.** Specify directory to publish
182183
* This informs GitHub Pages where the static HTML documentation (built by :code:`sphinx-build`) is located.
184+
185+
186+
3. Verifying GitHub Workflow Actions
187+
------------------------------------
188+
Using the previously mentioned workflow, a GitHub Action will be triggered whenever a commit is pushed to the repo.
189+
You can monitor running jobs from your GitHub Repository.
190+
191+
.. figure:: images/guide_install_github_actions_tab.png
192+
:class: sd-border-2
193+
194+
Click on the :code:`Actions` tab.
195+
196+
.. figure:: images/guide_install_actions_build.png
197+
:class: sd-border-2
198+
199+
Current and previous workflow runs are listed in the Actions tab.
200+
The color of the icon indicates the current status of the run.
201+
You may notice a :code:`pages build and deployment` job running. This is reponsible for building the docs.
202+
203+
.. figure:: images/guide_install_actions_error.png
204+
:class: sd-border-2
205+
206+
A red icon indicates that the run has failed. You can click on a run to get debug info for each step.
207+
Featured in this figure is a very common error: sphinx is missing an extension because it was not installed in the :code:`documentation.yml` workflow.
208+
209+
To fix this, :code:`sphinx-copybutton` had to be added to line 16 in :code:`documentation.yml` (see :ref:`2a. Example Workflow`)

docs/guides/images/.DS_Store

0 Bytes
Binary file not shown.
149 KB
Loading
Loading
Loading
Loading

docs/guides/images/layout_top.png

110 KB
Loading

docs/guides/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ Guides
1010
guide_installation
1111
layout/index
1212

13+
.. toctree::
14+
:maxdepth: 1
15+
:caption: Walkthroughs
16+
17+
walkthrough_adding_new_tab
18+
1319
.. toctree::
1420
:maxdepth: 1
1521
:caption: References
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
Adding New Tab
2+
==============
3+
4+
.. figure:: images/layout_top.png
5+
:class: sd-border-2
6+
7+
This walkthrough will cover how to add new tabs to the top bar (highlighted in red).
8+
9+
Find the Root Index
10+
-------------------
11+
The :code:`index.rst` files contain :code:`toctrees` that specify what rST documents should be included in the layout.
12+
13+
In this walkthrough, we will need to edit the **root index**, which is the first **index.rst** file you find in the docs folder located within the project directory:
14+
15+
.. code-block::
16+
17+
📦sphinx-documentation-demo
18+
┗ 📂docs
19+
┗ 📜index.rst ← this is the root index
20+
21+
22+
23+
Explore the Root Index
24+
----------------------
25+
If you open up :code:`sphinx-documentation-demo/index.rst`, you will notice a :code:`tocree` containing the following:
26+
27+
.. code-block::
28+
29+
.. toctree::
30+
:maxdepth: 1
31+
32+
guides/index
33+
tab_2/index
34+
tab_3/index
35+
36+
|
37+
38+
.. admonition:: Why don't we add .rst?
39+
:class: sidebar note
40+
41+
When we add :code:`guides/index` to the toctree in :code:`docs/index.rst`, Sphinx infers it's an rST and looks for a file called :code:`docs/guides/index.rst`
42+
43+
This tells Sphinx to add three tabs.
44+
Like the root index, each tab will need to have their own :code:`index.rst`, as these indices will tell Sphinx what documents to include in each tab.
45+
46+
It's good idea to keep the contents of each tab in a separate directory in :code:`docs/`
47+
48+
|
49+
50+
51+
Index File Layout for Tabs
52+
--------------------------
53+
The following is a quick sketch of where Sphinx would expect files to be based on the :code:`toctree` in :code:`docs/index.rst`:
54+
55+
.. code-block::
56+
57+
📦sphinx-documentation-demo
58+
┗ 📂docs
59+
┣ 📂guides
60+
┃ ┗ 📜index.rst ← index for tab "guides"
61+
┣ 📂tab_2
62+
┃ ┗ 📜index.rst ← index for tab "tab_2"
63+
┣ 📂tab_3
64+
┃ ┗ 📜index.rst ← index for tab "tab_3"
65+
┗ 📜index.rst ← root index
66+
67+
Creating "test" tab folder and empty index
68+
------------------------------------------
69+
We will now try to add a new tab to Sphinx.
70+
It will be called "test_tab" and will be next to the other tabs already in our documentation.
71+
72+
73+
.. admonition:: Remember to build!
74+
:class: sidebar warning
75+
76+
You need to use :code:`sphinx-build` or :code:`sphinx-autobuild` to build documentation before you notice any changes in the following steps.
77+
78+
1. Create a new empty directory called "test" at: :code:`docs/test_tab/`
79+
2. Create a new empty "index.rst" file at: :code:`docs/test_tab/index.rst`
80+
3. Inside :code:`docs/index.rst`, in the indented :code:`toctree`, append the line :code:`test_tab/index`. It should look like the following:
81+
82+
83+
.. code-block::
84+
85+
.. toctree::
86+
:maxdepth: 1
87+
88+
guides/index
89+
tab_2/index
90+
tab_3/index
91+
test_tab/index
92+
93+
Creating a "test document"
94+
--------------------------
95+
To make our new "test_tab" meaningful, we need to also add a document that can be viewed while within that tab.
96+
We will do this now:
97+
98+
1. Create an empty "test" doc at :code:`docs/test_tab/test_doc.rst`
99+
2. Add the following text to the "test_doc" document:
100+
101+
.. code-block::
102+
103+
Test Document
104+
=============
105+
106+
Hi there! This document is just a stub.
107+
108+
Note that :code:`Test Document` above refers to the title of the document.
109+
This will be displayed when viewing the document, and it will also **be the name that will appear in the navigation bar to the left when we add this document to the tab**.
110+
111+
Add "test document" to "test tab" index
112+
------------------------------------------
113+
Now we need to tell Sphinx that the "test document" will be located in our new "test_tab".
114+
115+
Add the following to :code:`docs/test_tab/index.rst` (if you mouse over the following code block, you can copy it by clicking the **copy button**):
116+
117+
.. code-block::
118+
119+
Test_Tab
120+
========
121+
122+
This is the index for the "Test Tab".
123+
124+
.. toctree::
125+
:maxdepth: 1
126+
127+
test_doc
128+
129+
Remember that this is the index file at :code:`docs/test_tab/index.rst`.
130+
This means that when we point to documents in this index's toctree, the path is relative to the :code:`docs/test_tab` directory.
131+
132+
So when we added :code:`test_doc` to the previous toctree, it's assuming that the file structure looks like this:
133+
134+
.. code-block::
135+
136+
📦sphinx-documentation-demo
137+
┗ 📂docs
138+
┗ 📂test_tab
139+
┣ 📜index.rst
140+
┗ 📜test_doc.rst
141+
142+
Build docs and explore the "test_tab"
143+
------------------------------------------
144+
Make sure to build your documentation using :code:`sphinx-build` or :code:`sphinx-autobuild`.
145+
146+
.. figure:: images/guide_add_tab_final.png
147+
:class: sd-border-2
148+
149+
Once the documentation is built, you should see something like this.
150+
151+
152+
You should see a new "Test_Tab" at the top navigation bar.
153+
This name comes from the title of the :code:`docs/test_tab/index.rst` document.
154+
Click on it to see the contents of the new tab.
155+
156+
In the left sidebar, you should see "Test Document".
157+
This name comes from the title of the :code:`docs/test_tab/test_doc.rst` document.
158+
Click on it to view the contents (it should contain the text :code:`Hi there! This document is just a stub.`)
159+
160+
161+
162+
163+
164+
165+

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ This is the root directory.
66
:maxdepth: 1
77

88
guides/index
9-
autoapi/testpackage/index
109
tab_2/index
1110
tab_3/index
11+
test_tab/index
1212

1313

1414

0 commit comments

Comments
 (0)