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

Render a guide as a single page #1481

Merged
merged 6 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion app/presenters/content_item/parts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def previous_and_next_navigation

def part_link_elements
parts.map do |part|
if part["slug"] != current_part["slug"]
if render_guide_as_single_page?
{ href: "##{part['slug']}", text: part["title"] }
elsif part["slug"] != current_part["slug"]
{ 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
51 changes: 51 additions & 0 deletions app/views/content_items/guide_single.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<% 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_with_index do |part, index| %>
<section class="govuk-!-padding-bottom-9" aria-labelledby="<%= part["slug"] %>">
<%= render "govuk_publishing_components/components/heading", {
text: part["title"],
id: part["slug"],
heading_level: 1,
border_top: index.zero? ? 0 : 2,
padding: true
} %>

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

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

<%= render 'shared/footer_navigation' %>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

get "healthcheck", to: proc { [200, {}, [""]] }

# Testing guides as a single page so we redirect parts to the default page
get "/voting-in-the-uk/:chapter", to: redirect("/voting-in-the-uk#%{chapter}")

get "*path/:variant" => "content_items#show",
constraints: {
variant: /print/,
Expand Down