Skip to content

Commit

Permalink
Fix the root-level redirect not being generated in cases where there …
Browse files Browse the repository at this point in the history
…are no versioned books and no book exists for the default branch
  • Loading branch information
object-Object committed Aug 5, 2024
1 parent 4e05ad7 commit dfe8788
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)

* A GitHub link is now added to the navbar by default (fixes [#26](https://github.com/hexdoc-dev/hexdoc/issues/26)). See the [docs](https://hexdoc.hexxy.media/docs/guides/template/#navbar) for more info.

### Fixed

* Fix the root-level redirect not being generated in cases where there are no versioned books and no book exists for the default branch.

## `1!0.1.0a19`

### Added
Expand Down
9 changes: 9 additions & 0 deletions src/hexdoc/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,17 @@ def merge(

if root_redirect is None:
# TODO: use plugin to build this path
# TODO: refactor
if item := sitemap.get(f"latest/{props.default_branch}"):
root_redirect = item.default_marker.redirect_contents
elif sitemap:
key = sorted(sitemap.keys())[0]
root_redirect = sitemap[key].default_marker.redirect_contents
logger.warning(
f"No book exists for the default branch `{props.default_branch}`, generating root redirect to `{key}` (check the value of `default_branch` in hexdoc.toml)"
)
else:
logger.error("No books found, skipping root redirect")

if root_redirect is not None:
redirects[Path()] = root_redirect
Expand Down

0 comments on commit dfe8788

Please sign in to comment.