Skip to content

Fix select_top_level_html_files ignoring custom http_prefix#438

Draft
inulty-dfe wants to merge 1 commit intoalphagov:mainfrom
inulty-dfe:main
Draft

Fix select_top_level_html_files ignoring custom http_prefix#438
inulty-dfe wants to merge 1 commit intoalphagov:mainfrom
inulty-dfe:main

Conversation

@inulty-dfe
Copy link
Copy Markdown

@inulty-dfe inulty-dfe commented Feb 6, 2026

What’s changed

When we configure a custom http_prefix (e.g. /docs) to serve our tech docs site under a subpath, Middleman sets the parent URL of top-level pages to /docs/ rather than /.

select_top_level_html_files had the parent URL check hardcoded to "/", so it filtered out all our top-level pages — meaning the multi-page table of contents came back empty.

render_page_tree (in the same file) already handled this correctly by computing home_url from config[:http_prefix]. select_top_level_html_files just wasn't updated to match.

Here is where we've had to monkey patch the library

Identifying a user need

  The parent URL check was hardcoded to "/" so top-level pages were filtered out when http_prefix was set to a custom path.
end

def select_top_level_html_files(resources)
def select_top_level_html_files(resources, config)
Copy link
Copy Markdown
Contributor

@jamescarr28 jamescarr28 Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we confident that no-one will currently be calling this function directly in their own implementation? If we can't be sure, should we provide a default value for the config parameter (even if it is just nil)

expect(subject.multi_page_table_of_contents(resources, current_page, config, current_page_html).strip).to eq(expected_multi_page_table_of_contents.strip)
end

it "selects top-level pages whose parent URL matches the http prefix" do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there any other test cases we could add, such as double nesting the path, or someone uses it weirdly (like adding http_prefix to the config, and setting the value to \)?


def select_top_level_html_files(resources)
def select_top_level_html_files(resources, config)
home_url = config[:http_prefix].end_with?("/") ? config[:http_prefix] : "#{config[:http_prefix]}/"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, what happens if the set http_prefix: "/prefix/" - i.e with a trailing slash or if config[:http_prefix] is nil?

@jamescarr28
Copy link
Copy Markdown
Contributor

This looks really good, nice quick fox for a fiddly problem!

All current test pass locally.

Before marking as ready for please rebase with our main branch (if not already done) and resolve the outsanding comments.

@jamescarr28 jamescarr28 marked this pull request as draft March 24, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants