Skip to content

Commit

Permalink
fixing dirhtml builds
Browse files Browse the repository at this point in the history
  • Loading branch information
choldgraf committed Oct 7, 2020
1 parent 307a8cb commit 39180f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 9 additions & 4 deletions sphinx_book_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ 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("*")

0 comments on commit 39180f3

Please sign in to comment.