Skip to content

Commit

Permalink
Render a guide as a single page
Browse files Browse the repository at this point in the history
We think it might really help our SEO to have guide content on one
page.  The how to vote page is particularly interesting because we have some
data about searching intents that might bring people to this page.  We also
think that amending this format to a single page might benefit voice answers.

There are some existing issues with guides having multiple h1 tags on a page.
This PR doesn't attempt to fix it (and in a way makes it worse) because we
have more h1s on the page than we used to.  I'm led to believe that this is
not relevant to WCAG by this [trello card on the GOV.UK accessibility backlog](https://trello.com/c/LzxvPjUz/117-fix-multiple-h1-heading-structure).

Other than that, this has been mostly stolen from the existing guide layout,
only including all of the parts.
  • Loading branch information
sihugh committed Oct 25, 2019
1 parent cef2c6c commit 981efdb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def format_banner_links(links, type)
end

def content_item_template
return "guide_single" if @content_item.render_guide_as_single_page?

@content_item.schema_name
end

Expand Down
2 changes: 1 addition & 1 deletion app/presenters/content_item/parts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def previous_and_next_navigation

def part_link_elements
parts.map do |part|
if part["slug"] != current_part["slug"]
if part["slug"] != current_part["slug"] || render_guide_as_single_page?
{ href: part["full_path"], text: part["title"] }
else
{ href: part["full_path"], text: part["title"], active: true }
Expand Down
5 changes: 5 additions & 0 deletions app/presenters/content_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def cache_control_public?
!content_item.cache_control.private?
end

def render_guide_as_single_page?
# /voting-in-the-uk
content_id == "9315bc67-33e7-42e9-8dea-e022f56dabfa"
end

private

def display_date(timestamp, format = "%-d %B %Y")
Expand Down
47 changes: 47 additions & 0 deletions app/views/content_items/guide_single.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<% content_for :extra_head_content do %>
<%= machine_readable_metadata(
schema: :article,
canonical_url: @content_item.canonical_url,
body: @content_item.current_part_body
) %>
<% end %>

<script type="application/ld+json">
<%= raw MachineReadable::GuideFaqPageSchemaPresenter.new(@content_item).structured_data.to_json %>
</script>

<% content_for :simple_header, true %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render 'govuk_publishing_components/components/title', { title: @content_item.content_title } %>

<% if @content_item.show_guide_navigation? %>
<aside class="part-navigation-container" role="complementary">
<%= render "govuk_publishing_components/components/contents_list", aria_label: 'Pages in this guide', contents: @content_item.part_link_elements, underline_links: true %>
</aside>
<% end %>
</div>

<div class="govuk-grid-column-two-thirds">
<% if @content_item.has_parts? %>

<% @content_item.parts.each do |part| %>
<h1 id=<%= part["slug"] %> class="part-title">
<%= part["title"] %>
</h1>

<%= render 'govuk_publishing_components/components/govspeak',
content: part["body"].html_safe,
direction: page_text_direction,
disable_youtube_expansions: true %>

<% end %>
<%= render 'components/print-link', href: @content_item.print_link, link_text: t("multi_page.print_entire_guide") %>
<% end %>
</div>

<%= render 'shared/sidebar_navigation' %>
</div>

<%= render 'shared/footer_navigation' %>

0 comments on commit 981efdb

Please sign in to comment.