Skip to content

Commit ecb84fd

Browse files
committed
Update guides
1 parent 35cdef2 commit ecb84fd

22 files changed

+339
-6
lines changed

docs/.DS_Store

0 Bytes
Binary file not shown.

docs/_static/css/custom.css

+5
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ html[data-theme="light"] {
3333
html[data-theme="dark"] {
3434
--pst-color-primary: rgb(0, 174, 255);
3535
}
36+
37+
/* The default font size is fairly small, so this increases it */
38+
body {
39+
font-size: 1.3em
40+
}

docs/conf.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3232
# ones.
3333
extensions = [
34-
# githubpages just adds a .nojekyll file
35-
"sphinx.ext.githubpages",
34+
"sphinx.ext.githubpages", # used for hosting on GitHub Pages
35+
"sphinx.ext.todo",
36+
"sphinx_copybutton", # adds a copy button to source code blocks
3637
"sphinx_design"
3738
]
3839

@@ -85,6 +86,7 @@
8586
'css/custom.css'
8687
]
8788

89+
todo_include_todos = True
8890

8991
# HTML context:
9092
from os.path import basename, dirname, realpath

docs/guides/.DS_Store

8 KB
Binary file not shown.

docs/guides/guide_installation.rst

+72-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,73 @@
1-
Installation
2-
============
1+
Installing Sphinx
2+
=================
33

4-
This is a subject
4+
5+
Local Installation
6+
==================
7+
8+
.. tip::
9+
When you need to write a lot of documentation, it's a **good idea** to do it all locally.
10+
11+
12+
1. Cloning the Repo
13+
------------------------
14+
Clone the `sphinx-documentation-demo <https://github.com/bioteam/sphinx-documentation-demo>`_ GitHub repository into a local directory:
15+
16+
.. code-block:: bash
17+
18+
git clone [email protected]:bioteam/sphinx-documentation-demo.git
19+
20+
2. Installing Sphinx
21+
---------------------------------
22+
Sphinx, and extensions for Sphinx, are *python packages* that can be installed on your computer.
23+
The packages you need to install are in :code:`requirements.txt` in the :code:`sphinx-documentation-demo` repository.
24+
It's a good idea to install them in a **virtual environment**.
25+
26+
27+
28+
2a. Using :code:`venv` to install
29+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30+
31+
.. code-block:: bash
32+
33+
python -m venv sphinx_venv
34+
source sphinx_venv/bin/activate
35+
pip install -r requirements.txt
36+
37+
38+
39+
3. Building Documentation
40+
-------------------------
41+
The documentation for the :code:`sphinx-documentation-demo` is located in :code:`docs/`.
42+
To build this documentation, while in the project directory, do:
43+
44+
.. code-block:: bash
45+
46+
sphinx-build -M html docs/ _build
47+
48+
This will tell Sphinx to generate static HTML documentation from :term:`rST` files within :code:`docs/` and then place them in :code:`_build`.
49+
You can open the file :code:`docs/index.html` on your computer to view the HTML documentation in your web browser.
50+
51+
52+
53+
3a. Using :code:`sphinx-autobuild`
54+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55+
The :code:`sphinx-autobuild` extension allows us to build local documentation whenever we make changes.
56+
It also refreshes the web browser so you can see the changes "live". This makes it **very convenient for rapid development**.
57+
58+
This extension has already been included in the :code:`requirements.txt` file
59+
60+
While in the virtual environment, run the following command:
61+
62+
.. code-block:: bash
63+
64+
sphinx-autobuild docs _build
65+
66+
This will create a local host instance which you can then access through your web browser (you can just copy/paste the http address you get from :code:`sphinx-autobuild`)
67+
68+
Remote Build on GitHub
69+
======================
70+
71+
.. todo::
72+
73+
Finish the guide for remote building on GitHub.

docs/guides/guide_what_is_sphinx.rst

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
What is Sphinx?
2+
===============
3+
4+
Sphinx lets you generate static web pages that can be hosted on sites such as `Github Pages <https://pages.github.com/>`_ and `Read the Docs <https://about.readthedocs.com/?ref=readthedocs.com>`_.
5+
While there are other tools that can be used to generate documentation, Sphinx is **open source**, popular, and well-supported.
6+
7+
Some use cases for Sphinx include:
8+
9+
10+
.. grid:: 2
11+
:gutter: 4
12+
13+
.. grid-item-card::
14+
:class-header: `sd-bg-secondary sd-text-white sd-text-center`
15+
16+
:material-regular:`dvr;2em` Documenting Code
17+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
Sphinx can be used to generate documentation from `docstrings <https://peps.python.org/pep-0257/>`_. For example: Python's `code documentation <https://docs.python.org/3/library/functions.html#print>`_.
19+
20+
21+
.. grid-item-card::
22+
:class-header: `sd-bg-secondary sd-text-white sd-text-center`
23+
24+
:material-regular:`auto_stories;2em` Knowledge Base
25+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
Sphinx can also be used more like a wiki, where reference documents can be hosted in an accessible location.
27+
28+
.. grid-item-card::
29+
:class-header: `sd-bg-secondary sd-text-white sd-text-center`
30+
31+
:material-regular:`rss_feed;2em` Blogging
32+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
"Blog-style" posts can be integrated into any Sphinx project using the `ABlog extension <https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/ablog.html>`_.
34+
35+
.. grid-item-card::
36+
:class-header: `sd-bg-secondary sd-text-white sd-text-center`
37+
38+
:material-regular:`visibility;2em` Data Visualization
39+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40+
Jupyter notebook visualizations can be embedded into Sphinx documentation using the `nbsphinx <https://nbsphinx.readthedocs.io/en/0.9.3/index.html>`_ extension.
41+
42+
.. grid-item-card::
43+
:margin: 4 2 auto auto
44+
:class-header: `sd-bg-secondary sd-text-white sd-text-center`
45+
:text-align: center
46+
47+
:material-regular:`image;2em` Gallery
48+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
You can easily throw together a gallery of cards to highlight important features, links, or images. For example, `this site <https://sphinx-extensions.readthedocs.io/en/latest/>`_.
50+
51+
How do I use Sphinx?
52+
====================
53+
.. admonition:: Why reStructuredText (rST)?
54+
:class: sidebar note
55+
56+
This demo assumes you'll be using rST to write documentation.
57+
While there is `support for Markdown <https://myst-parser.readthedocs.io/en/v0.17.1/sphinx/intro.html>`_, the grammar can be cumbersome when writing complicated :term:`directives<directive>`.
58+
59+
Sphinx can be run locally on your laptop to generate HTML files from source code, `Markdown <https://en.wikipedia.org/wiki/Markdown>`_, or `reStructredText (rST) <https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html>`_.
60+
You can also run it remotely on GitHub by adding a post-commit hook to build documentation pushed to a repository. This will be expanded upon in a later tutorial.
61+
62+
.. todo::
63+
64+
Add link to tutorial to build docs in GitHub
65+

docs/guides/index.rst

+4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ Guides
66
:maxdepth: 1
77
:caption: Starting Out
88

9+
guide_what_is_sphinx
910
guide_installation
11+
layout/index
1012

1113
.. toctree::
1214
:maxdepth: 1
1315
:caption: References
1416

1517
reference_directives
18+
reference_glossary
19+
reference_todo
1620

1721
.. toctree::
1822
:maxdepth: 1

docs/guides/layout/.DS_Store

6 KB
Binary file not shown.

docs/guides/layout/images/.DS_Store

6 KB
Binary file not shown.
110 KB
Loading
110 KB
Loading
110 KB
Loading
110 KB
Loading
9.78 KB
Loading
23.9 KB
Loading

docs/guides/layout/images/tabs.png

5.33 KB
Loading

docs/guides/layout/images/top_bar.png

22.9 KB
Loading

docs/guides/layout/index.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Documentation Layout
2+
====================
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
7+
layout_basic

docs/guides/layout/layout_basic.rst

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
Layout Overview
2+
=============================
3+
.. note::
4+
:class: sidebar
5+
6+
The Sphinx theme (`PyData <https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html>`_ in our case) can also affect how documents are shown in the layout.
7+
8+
The documentation you see on this website is built from the `docs <https://github.com/bioteam/sphinx-documentation-demo/tree/main/docs>`_ directory located in the project.
9+
10+
Sphinx compiles the :term:`rST` files inside of this directory and generates static HTML files.
11+
The file layout of the :code:`docs/` directory, along with "toctrees" (which we will cover this later), will **determine the website layout of the documentation**.
12+
13+
Therefore it's important to understand how to organize files within the :code:`docs/` directory so that Sphinx knows where to display them.
14+
We'll cover this over the course of several short tutorials so that you can learn how to:
15+
16+
..
17+
.. list-table::
18+
:header-rows: 1
19+
20+
* - **Add a new...**
21+
* - Tab to the top navigation bar
22+
* - Page to the left navigation bar
23+
* - Section to the left navigation bar
24+
25+
* Add a new tab to the top navigation bar
26+
* Add a new page to the left navigation bar
27+
* Add a new section to the left navigation bar
28+
29+
Before that, we review each of the major layout components in the sections below.
30+
31+
Top Navigation Bar
32+
==================
33+
34+
.. figure:: images/layout_top.png
35+
:class: sd-border-2
36+
37+
The top navigation bar (highlighted in red)
38+
39+
40+
Logo
41+
----
42+
43+
The "logo" is located in the upper-left-hand corner of the page.
44+
Typically this is just text, but you can also add an icon.
45+
To change the text that you see:
46+
47+
1. Go into :code:`docs/conf.py`
48+
2. In html_theme_options...
49+
3. Change the text stored in the "logo" key:
50+
51+
.. image:: images/logo_loc.png
52+
:class: sd-border-2
53+
54+
55+
56+
.. seealso::
57+
58+
`PyData's guide on changing the logo <https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/branding.html>`_
59+
60+
61+
62+
Tabs
63+
----
64+
.. figure:: images/tabs.png
65+
:class: sd-border-2
66+
67+
This project has three tabs, although two of them are for demonstration purposes.
68+
69+
70+
71+
You can organize content into different "tabs".
72+
For example, a code project could be partitioned into a "Tutorials" tab (for in-depth documentation) and an "API" tab (for documenting specific functions)
73+
74+
A tab is created for each "toctree" in the root index file :code:`docs/index.rst`.
75+
This will be covered in a later tutorial.
76+
77+
.. todo::
78+
79+
Link to the tabs tutorial
80+
81+
82+
Search Bar
83+
----------
84+
.. warning::
85+
:class: sidebar
86+
87+
The search bar doesn't work well when you are viewing documentation **locally** on your computer.
88+
89+
Sphinx comes with built-in search functionality.
90+
Users that enter text into the search bar in the upper-right-hand corner can search across multiple documentation pages.
91+
92+
Left Navigation Bar
93+
===================
94+
.. figure:: images/layout_left.png
95+
:class: sd-border-2
96+
97+
The left navigation bar (highlighted in red)
98+
99+
100+
The left navigation bar allows users to navigate between documents that have been indexed within a "toctree" (more on this later).
101+
Each tab will have its own left navigation bar, allowing you to organize :term:`rST` files into one "folder" per tab.
102+
103+
Right Navigation Bar
104+
===================
105+
.. figure:: images/layout_right.png
106+
:class: sd-border-2
107+
108+
The right navigation bar (highlighted in red)
109+
110+
111+
The right navigation bar allows users to navigation between **different sections within the current page**.
112+
This is automatically generated based on section headers specified within the page's :term:'rST' file.
113+
114+
..
115+
.. image:: images/tab2_top.png
116+
:class: sd-border-2
117+
118+
|
119+
120+

docs/guides/reference_glossary.rst

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Glossary
2+
========
3+
4+
.. Glossary::
5+
6+
Directive
7+
Directives are special commands that can be embedded as text into an rST document.
8+
They can be used to dictate how content in the document gets formatted by Sphinx.
9+
10+
For example, having this in a document:
11+
12+
.. code-block:: rst
13+
14+
.. admonition:: title
15+
16+
content
17+
18+
... would generate this:
19+
20+
.. admonition:: title
21+
22+
content
23+
24+
25+
rST
26+
reStructuredText is a plaintext markup language that Sphinx can use to generate documentation.
27+
This will be the standard way we write documentation in this project. Mardown is an alternative langauge.
28+
29+
See this `cheat sheet <https://github.com/ralsina/rst-cheatsheet/blob/master/rst-cheatsheet.rst>`_ for the common markup used in rST files.

docs/guides/reference_todo.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Todo List
2+
=================
3+
4+
This will generate a list of todo entries when todo_include_todos is set to "True" in config.py
5+
6+
7+
.. todolist::

docs/tab_2/subject_1.rst

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
Subject_1
22
==========
33

4-
This is a subject
4+
This is a long page to test out some of the features of Sphinx.
5+
6+
7+
Section 1
8+
=========
9+
10+
Subsection 1
11+
------------
12+
13+
Sub-Subsection 1
14+
~~~~~~~~~~~~~~~~
15+
16+
Sub-Subsection 2
17+
~~~~~~~~~~~~~~~~
18+
19+
Sub-Subsection 3
20+
~~~~~~~~~~~~~~~~
21+
22+
Subsection 2
23+
------------
24+
25+
Section 2
26+
============
27+
28+
Subsection 3
29+
------------

0 commit comments

Comments
 (0)