From 7b8d7504db7e55db7b2e4056ffa838a79f31e9a5 Mon Sep 17 00:00:00 2001 From: Alex Jurubita Date: Thu, 31 Oct 2019 10:03:53 +0000 Subject: [PATCH] Update multi-page navigation to respect root host Currently if the tech-docs is deployed on a path (e.g. `https://alphagov.github.io/api-catalogue/`) the navigation links are broken as they are generated from root (`/`). One way to avoid this without affecting current single-page or multi-page configuration is to define a `path_prefix` in config that is prepended to each link. --- lib/govuk_tech_docs/table_of_contents/helpers.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/govuk_tech_docs/table_of_contents/helpers.rb b/lib/govuk_tech_docs/table_of_contents/helpers.rb index d05e8ed1..3605312c 100644 --- a/lib/govuk_tech_docs/table_of_contents/helpers.rb +++ b/lib/govuk_tech_docs/table_of_contents/helpers.rb @@ -55,22 +55,18 @@ def render_page_tree(resources, current_page, config, current_page_html) # prefix in to consideration when checking for the root index.html. # The prefix may be set with or without a trailing slash: make sure # it has one for this comparison check. - home_url = - if config[:http_prefix].end_with?("/") - config[:http_prefix] - else - config[:http_prefix] + "/" - end + home_url = config[:http_prefix].end_with?("/") ? config[:http_prefix] : config[:http_prefix] + "/" + resource_url = config[:tech_docs][:path_prefix] ? config[:tech_docs][:path_prefix] + resource.url : resource.url - if resource.children.any? && resource.url != home_url - output += %{