Building navigation list with Nokogiri from page content and content of partials

I’m trying to use Nokogiri to build a navigation list based on html headers from partials.

https://gist.github.com/bc-AlyssNoland/1ca7dfd0040755ddbe2ad0b009e68044

Currently, I have a mostly working version but page_content only yields the header from index.html and not the markdown files that follow it after the build process.

I tried using current_page.content, but that appeared to be a mistake since it wouldn’t be defined for the config file to parse. I’m wondering if I should use the ready helper similar to how you build a sitemap and then capture_html output helper to join then parse the content, but I’m not sure how to define this and examples are pretty sparse.

Does this approach seem like it will work or are there better alternatives?