Skip to content
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

🐛 FIX: fixing dirhtml builds #230

Merged
merged 1 commit into from
Oct 7, 2020
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
12 changes: 8 additions & 4 deletions sphinx_book_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ def find_url_relative_to_root(pagename, relative_page, path_docs_source):

# Convert everything to paths for use later
path_rel = Path(relative_page).with_suffix("")
path_parent = Path(pagename) # pagename is relative to docs root
if relative_page.endswith(".html"):
# HTML file Sphinx builder
path_parent = Path(pagename).parent # pagename is .html relative to docs root
else:
# DirHTML Sphinx builder.
path_parent = Path(pagename) # pagename is the parent folder if dirhtml builder

source_dir = Path(path_docs_source)
# This should be the path to `relative_page`, relative to `pagename`
path_rel_from_page_dir = source_dir.joinpath(
path_parent.parent.joinpath(path_rel.parent)
)
path_rel_from_page_dir = source_dir.joinpath(path_parent.joinpath(path_rel.parent))
path_from_page_dir = Path(os.path.abspath(path_rel_from_page_dir))
page_rel_root = path_from_page_dir.relative_to(source_dir).joinpath(path_rel.name)
return page_rel_root
Expand Down
8 changes: 8 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,11 @@ def test_missing_title(sphinx_build_factory):
"""Test building with a book w/ no title on the master page."""
with pytest.raises(ThemeError, match="Landing page missing a title: index"):
sphinx_build_factory("notitle").build()


def test_docs_dirhtml(sphinx_build_factory):
"""Test that builds with dirhtml pass without error."""
sphinx_build = sphinx_build_factory("base", buildername="dirhtml").build(
assert_pass=True
)
assert (sphinx_build.outdir / "index.html").exists(), sphinx_build.outdir.glob("*")