Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error building multipage site with :http_prefix #183

Closed
lhokktyn opened this issue Mar 26, 2019 · 2 comments · Fixed by alphagov/tech-docs-gem#79
Closed

Error building multipage site with :http_prefix #183

lhokktyn opened this issue Mar 26, 2019 · 2 comments · Fixed by alphagov/tech-docs-gem#79

Comments

@lhokktyn
Copy link

I'm building a multipage site that will be delivered via Gitlab pages, which requires the site be delivered from a subdirectory, e.g. https://my-docs.test/tech-docs/

After some reading around, :http_prefix seems to be the most appropriate option to enable this, but I've run into some problems when building the site with this flag enabled. It's probably user error, but have got stuck so far ...

Set up

# config.rb
require 'govuk_tech_docs'
GovukTechDocs.configure(self)

configure :build do
  set :build_dir, 'public'
  activate :relative_assets
  set :http_prefix, '/tech-docs'
  page '/tech-docs/*.json', layout: false
end

set :markdown_engine, :kramdown
set :markdown,
  fenced_code_blocks: true,
  tables: true,
  no_intra_emphasis: true
# tech-docs.yml
host: https://my-docs.test/tech-docs
show_govuk_logo: false
service_name: Tech Docs
service_link: /tech-docs
max_toc_heading_level: 2
multipage_nav: true

File layout:

|- source/
|-- index.html.md.erb
|-- page2.html.md.erb
|-- page3.html.md.erb

Expected Outcome

In the nav on the left, I'd expect something along the lines of:

<ul>
  <li>
    <a href="/tech-docs/#tech-docs">Tech Docs</a>
  </li>
  <li>
    <a href="/tech-docs/page2.html#page2">Page 2</a>
  </li>
  <li>
    <a href="/tech-docs/page3.html#page3">Page 3</a>
  </li>
</ul>

Actual Outcome

During build:

No H1 tag found. You have to at least add one H1 heading to the page: /tech-docs/favicon.ico
/project/vendor/ruby/2.3.0/gems/govuk_tech_docs-1.8.0/lib/govuk_tech_docs/table_of_contents/helpers.rb:14:in `single_page_table_of_contents'
/project/vendor/ruby/2.3.0/gems/govuk_tech_docs-1.8.0/lib/govuk_tech_docs/table_of_contents/helpers.rb:58:in `block in render_page_tree'
/project/vendor/ruby/2.3.0/gems/govuk_tech_docs-1.8.0/lib/govuk_tech_docs/table_of_contents/helpers.rb:36:in `each'
/project/vendor/ruby/2.3.0/gems/govuk_tech_docs-1.8.0/lib/govuk_tech_docs/table_of_contents/helpers.rb:36:in `render_page_tree'
/project/vendor/ruby/2.3.0/gems/govuk_tech_docs-1.8.0/lib/govuk_tech_docs/table_of_contents/helpers.rb:54:in `block in render_page_tree'
/project/vendor/ruby/2.3.0/gems/govuk_tech_docs-1.8.0/lib/govuk_tech_docs/table_of_contents/helpers.rb:36:in `each'
/project/vendor/ruby/2.3.0/gems/govuk_tech_docs-1.8.0/lib/govuk_tech_docs/table_of_contents/helpers.rb:36:in `render_page_tree'
/project/vendor/ruby/2.3.0/gems/govuk_tech_docs-1.8.0/lib/govuk_tech_docs/table_of_contents/helpers.rb:28:in `multi_page_table_of_contents'

A similar error occurs - mentioned search.json rather than favicon.ico - if search is enabled with enable_search: true.

timblair added a commit to alphagov/tech-docs-gem that referenced this issue Mar 28, 2019
We need to take any custom prefix set in `config.http_prefix` in to
consideration when generating multipage tables of content. Previously we
were assuming that the root page was at `/`, which is not the case with
the custom prefix set.

Fixes alphagov/tech-docs-template#183.
@timblair
Copy link
Member

timblair commented Apr 1, 2019

Thanks for reporting this, @lhokktyn. Version 1.8.1 of the tech_docs_gem has been released with a fix. Let me know if you have any issues with that version.

@lhokktyn
Copy link
Author

lhokktyn commented Apr 2, 2019

Thanks for the quick turnaround on this @timblair. I've given this a go and it looks like the table of contents isn't being generated as expected when http_prefix = /tech-guides is set ...

I have the following files:

|- source/
|--index.html.md.erb
|--page2.html.md.erb

Within which I've code code like this

---
title: "Page2"
weight: 20
---

# Page2

<%= partial 'documentation/page2/sub-content' %>

But the TOC generated only seems to contain links to the headings present in index.html.md.erb:

<ul>
  <li>
    <a href="/tech-guides/#technical-guides">Technical Guides</a>
    <ul>
      <li>
        <a href="/tech-guides/#subheading1">Sub Heading 1</a>
      </li>
      <li>
        <a href="/tech-guides/#subheading2">Sub heading 2</a>
      </li>
    </ul>
  </li>
</ul>

But I'd expect it to include the page2 stuff too, ie.:

<ul>
  <li>
    <a href="/tech-guides/#technical-guides">Technical Guides</a>
    <ul>
      <li>
        <a href="/tech-guides/#subheading1">Sub Heading 1</a>
      </li>
      <li>
        <a href="/tech-guides/#subheading2">Sub heading 2</a>
      </li>
    </ul>
  </li>
  <li>
    <a href="/tech-guides/page2.html#">Page2</a>
    <ul>
      <li>
        <a href="/tech-guides/page2.html#subcontent">Sub Content</a>
      </li>
    </ul>
  </li>
</ul>

It's probably user error on my part, but does this trigger any indicators as to what might be wrong?

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 a pull request may close this issue.

2 participants