Skip to content

Commit

Permalink
Add SearchAction for manuals
Browse files Browse the repository at this point in the history
Manuals like [The Highway Code](https://www.gov.uk/guidance/the-highway-code)
have an embedded search box which allows searches scoped to that manual.

By advertising this in our machine readable metadata it's more obvious to
external consumers of the site that these things are available.

This is part of the work to make our search more visible to external consumers
of the site.

https://trello.com/c/4EAytHVV/747-plan-indexing-of-finder-pages
  • Loading branch information
sihugh committed May 22, 2019
1 parent bcaf780 commit d2f27b3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Add contents list heading Welsh translation (PR #881)
* Enable passing data attributes to attachment components (PR #874)
* Add potentialSearchAction to the GovernmentOrganization schema (PR #870)
* Add potentialSearchAction to manuals (PR #879)

## 16.22.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def initialize(page)

def structured_data
# http://schema.org/Article
data = CreativeWorkSchema.new(@page).structured_data.merge(body)
data = CreativeWorkSchema.new(@page).structured_data
.merge(body)
.merge(search_action)
data["@type"] = "Article"
data
end
Expand All @@ -25,6 +27,13 @@ def body
"articleBody" => page.body
}
end

def search_action
return {} unless page.document_type == "manual"

manuals_facet_params = { manual: page.base_path }
PotentialSearchActionSchema.new(manuals_facet_params).structured_data
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def image_placeholders
local_assigns[:image_placeholders]
end

def document_type
content_item["document_type"]
end

def base_path
content_item["base_path"]
end

def content_item
local_assigns[:content_item]
end
Expand Down
27 changes: 27 additions & 0 deletions spec/lib/govuk_publishing_components/presenters/schema_org_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@
expect(structured_data['articleBody']).to eql("Foo")
end

it "generates search info in Articles for manuals" do
content_item = GovukSchemas::RandomExample.for_schema(frontend_schema: "manual") do |random_item|
random_item.merge(
"base_path" => "/guidance/plane-manual",
"details" => {
"body" => "Ensure you have a left phalange before take off."
}
)
end

structured_data = generate_structured_data(
content_item: content_item,
schema: :article,
).structured_data

expect(structured_data['@type']).to eql("Article")
expect(structured_data['mainEntityOfPage']['@id']).to eql("http://www.dev.gov.uk/guidance/plane-manual")
expect(structured_data['articleBody']).to eql("Ensure you have a left phalange before take off.")

search_action = {
"@type": "SearchAction",
"target": "http://www.dev.gov.uk/search/all?keywords={query}&manual=%2Fguidance%2Fplane-manual",
"query": "required"
}
expect(structured_data['potentialAction']).to eql(search_action)
end

it "generates schema.org NewsArticles" do
content_item = GovukSchemas::RandomExample.for_schema(frontend_schema: "answer")

Expand Down

0 comments on commit d2f27b3

Please sign in to comment.