diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dd29ea5..43c2da4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ exclude: > repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.5.0 hooks: - id: check-json - id: check-yaml @@ -24,17 +24,17 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 23.10.0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 - rev: 5.0.2 + rev: 6.1.0 hooks: - id: flake8 additional_dependencies: [flake8-bugbear~=22.7] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.971 + rev: v1.6.1 hooks: - id: mypy diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..4bca864 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,15 @@ +# Contributing + +`sphinx-external-toc` is part of the executablebooks project, who also are responsible for `jupyter-book`. + +We're excited you're here and want to contribute. + +The Jupyter Book project is run by a community of people like you, we'd love to have you +help out! + +Please take a look at the [Jupyter Book contributor guide](https://jupyterbook.org/en/stable/contribute/intro.html) +which steps you through the codebase and how to contribute to this project. +If you have any questions that aren't answered there, please let us know by +[opening an issue][link_issues]! + +Thank you for you interest in contributing ✨ diff --git a/sphinx_external_toc/events.py b/sphinx_external_toc/events.py index 522b7b8..dc57ea1 100644 --- a/sphinx_external_toc/events.py +++ b/sphinx_external_toc/events.py @@ -220,7 +220,6 @@ def insert_toctrees(app: Sphinx, doctree: nodes.document) -> None: node_list: List[nodes.Element] = [] for toctree in doc_item.subtrees: - subnode = toctree_node() subnode["parent"] = app.env.docname subnode.source = doctree["source"] @@ -245,13 +244,10 @@ def insert_toctrees(app: Sphinx, doctree: nodes.document) -> None: wrappernode.append(subnode) for entry in toctree.items: - if isinstance(entry, UrlItem): - subnode["entries"].append((entry.title, entry.url)) elif isinstance(entry, FileItem): - child_doc_item = site_map[entry] docname = str(entry) title = child_doc_item.title @@ -326,13 +322,18 @@ def ensure_index_file(app: Sphinx, exception: Optional[Exception]) -> None: exception is not None or "html" not in app.builder.format or app.config.master_doc == "index" - # TODO rewrite the redirect if master_doc has changed since last build + # TODO: rewrite the redirect if master_doc has changed since last build or index_path.exists() ): return + root_name = remove_suffix(app.config.master_doc, app.config.source_suffix) - # TODO the other way to do this would be to - # simply copy the contents of the root file? (this method was taken from jupyter-book) - redirect_text = f'\n' + + if app.builder.name == "html": + redirect_url = f"{root_name}.html" + elif app.builder.name == "dirhtml": + redirect_url = f"{root_name}/index.html" + + redirect_text = f'\n' index_path.write_text(redirect_text, encoding="utf8") logger.info("[etoc] missing index.html written as redirect to '%s.html'", root_name) diff --git a/sphinx_external_toc/parsing.py b/sphinx_external_toc/parsing.py index 8e313a1..717b9fa 100644 --- a/sphinx_external_toc/parsing.py +++ b/sphinx_external_toc/parsing.py @@ -193,7 +193,6 @@ def _parse_doc_item( toctrees = [] for toc_idx, toc_data in enumerate(subtrees_data): - toc_path = path if shorthand_used else f"{path}{toc_idx}/" if not (isinstance(toc_data, Mapping) and items_key in toc_data): @@ -209,7 +208,6 @@ def _parse_doc_item( # generate items list items: List[Union[GlobItem, FileItem, UrlItem]] = [] for item_idx, item_data in enumerate(items_data): - if not isinstance(item_data, Mapping): raise MalformedError( f"entry not a mapping type @ '{toc_path}{items_key}/{item_idx}'" diff --git a/sphinx_external_toc/tools.py b/sphinx_external_toc/tools.py index 0d77ae6..d3b9e1a 100644 --- a/sphinx_external_toc/tools.py +++ b/sphinx_external_toc/tools.py @@ -59,7 +59,6 @@ def create_site_from_toc( # create files for docname in chain(site_map, additional_files): - # create document filename = docname if not any(docname.endswith(ext) for ext in {".rst", ".md"}): diff --git a/tests/test_tools.py b/tests/test_tools.py index 4d77673..c335ceb 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -26,7 +26,6 @@ def test_file_to_sitemap(path: Path, tmp_path: Path, data_regression): def test_create_site_map_from_path(tmp_path: Path, data_regression): - # create project files files = [ "index.rst",