From dfe87883253512d424b7eb11d18ed0dc02d83886 Mon Sep 17 00:00:00 2001 From: object-Object Date: Mon, 5 Aug 2024 13:00:02 -0400 Subject: [PATCH] Fix the root-level redirect not being generated in cases where there are no versioned books and no book exists for the default branch --- CHANGELOG.md | 4 ++++ src/hexdoc/cli/app.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3849f5b6..35663b60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/hexdoc/cli/app.py b/src/hexdoc/cli/app.py index 5314ec1b..504716c5 100644 --- a/src/hexdoc/cli/app.py +++ b/src/hexdoc/cli/app.py @@ -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