Skip to content

♻️ REFACTOR: Delegate ToC logic to sphinx-external-toc #1293

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 20 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
*_build
_build


# Translations
Expand Down
13 changes: 9 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/mgedmin/check-manifest
rev: "0.39"
rev: "0.44"
hooks:
- id: check-manifest

- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
- repo: https://github.com/pycqa/isort
rev: 5.8.0
hooks:
- id: flake8
- id: isort

- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ recursive-exclude scripts *

exclude .pre-commit-config.yaml
exclude .readthedocs.yml
exclude .flake8
exclude tox.ini
exclude codecov.yml
exclude RELEASES.md
Expand Down
36 changes: 15 additions & 21 deletions docs/_toc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- file: intro

- part: Tutorials
format: jb-book
root: intro
parts:
- caption: Tutorials
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we wanna call this title: rather than caption:? I know that Sphinx calls it caption but I feel like "title" will be more intuitive for people

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eurgh maybe, but it will mean additonal code/complexity needs to be implemented in sphinx-external-toc, to map toctree options to different keys

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah i thought it would already work, in that case let's leave this to a future enhancement to discuss

chapters:
- file: start/your-first-book
sections:
Expand All @@ -10,8 +11,7 @@
- file: start/publish
- file: tutorials/references
- file: basics/questions

- part: Create your book
- caption: Create your book
chapters:
- file: customize/toc
- file: basics/create
Expand All @@ -28,13 +28,12 @@
- file: interactive/hiding
- file: file-types/index
sections:
- file: file-types/markdown
- file: file-types/notebooks
- file: file-types/myst-notebooks
- file: file-types/jupytext
- file: file-types/restructuredtext

- part: Build your book
- file: file-types/markdown
- file: file-types/notebooks
- file: file-types/myst-notebooks
- file: file-types/jupytext
- file: file-types/restructuredtext
- caption: Build your book
chapters:
- file: basics/build
- file: execute/index
Expand All @@ -43,8 +42,7 @@
- file: content/execute
- file: interactive/interactive
- file: basics/page

- part: Publish your book
- caption: Publish your book
chapters:
- file: publish/web
sections:
Expand All @@ -56,24 +54,20 @@
sections:
- file: interactive/comments/hypothesis
- file: interactive/comments/utterances

- file: advanced/html
- file: advanced/pdf

- part: Advanced usage
- caption: Advanced usage
chapters:
- file: advanced/sphinx
- file: advanced/windows
- file: explain/sphinx

- part: Reference
- caption: Reference
chapters:
- file: customize/config
- file: reference/cheatsheet
- file: reference/cli
- file: reference/glossary

- part: About Jupyter Book
- caption: About Jupyter Book
chapters:
- url: https://executablebooks.org/en/latest/gallery.html
title: Gallery of Jupyter Books
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ For example: `jupyter-book build mybook/` is equivalent to ``jb build mybook/``.
**See below for the full command-line reference**

```{eval-rst}
.. click:: jupyter_book.commands:main
.. click:: jupyter_book.cli.main:main
:prog: jupyter-book
:nested: full
```
20 changes: 1 addition & 19 deletions jupyter_book/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
"""Build a book with Jupyter Notebooks and Sphinx."""
from pathlib import Path

from .toc import add_toc_to_sphinx, add_toctree
from .directive.toc import TableofContents, SwapTableOfContents
from sphinx.util import logging


__version__ = "0.10.2"
__version__ = "0.11.0a1"

logger = logging.getLogger(__name__)

Expand All @@ -25,25 +22,10 @@ def add_static_files(app, config):
# We connect this function to the step after the builder is initialized
def setup(app):

# Updates `master_doc` using the first item of `_toc.yml`
app.connect("config-inited", add_toc_to_sphinx)

# Add toctrees to each content page using `_toc.yml`
app.connect("source-read", add_toctree)

# Path for `_toc.yml`
app.add_config_value("globaltoc_path", "toc.yml", "env")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all this red is a beautiful thing

app.add_config_value("use_jupyterbook_latex", True, "env")

# Add custom static files to the sphinx build
app.connect("config-inited", add_static_files)

# Directives
app.add_directive("tableofcontents", TableofContents)

# Transforms
app.add_post_transform(SwapTableOfContents)

# Extensions
return {
"version": __version__,
Expand Down
4 changes: 3 additions & 1 deletion jupyter_book/book_template/_toc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Table of contents
# Learn more at https://jupyterbook.org/customize/toc.html

- file: intro
format: jb-article
root: intro
sections:
- file: markdown
- file: notebooks
File renamed without changes.
Loading