govuk_publishing_components 5.1.3 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss +49 -0
- data/app/views/govuk_publishing_components/components/_related_navigation.html.erb +77 -0
- data/app/views/govuk_publishing_components/components/docs/related_navigation.yml +168 -0
- data/config/locales/en.yml +13 -2
- data/lib/govuk_publishing_components.rb +1 -0
- data/lib/govuk_publishing_components/components/related_navigation_helper.rb +245 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03f20110c0dabc04645577702eafe2331de4c0f0e29f451c3f3c2afff0224564
|
4
|
+
data.tar.gz: 96066fa35b68926dfde283d683563c504b59beb723a563c4d2157c45415d6b32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48b785e1fb91b2d41359f540b03e82f871f8cb403fbe1953936a25dc6ae2ee2ec9c4752800d53f11841a74a7d5ea2dd97eadc92391c79d9fe727c8f20295cbc5
|
7
|
+
data.tar.gz: 9a9ddfbef2158e78e8aeb1e321798869a15373197b189c9cd4f220240050bbab23e0a41ead74808ab282133999576ca3c47e48db0083a60ae7a84db773e59409
|
@@ -13,6 +13,7 @@
|
|
13
13
|
@import "components/input";
|
14
14
|
@import "components/label";
|
15
15
|
@import "components/radio";
|
16
|
+
@import "components/related-navigation";
|
16
17
|
@import "components/step-by-step-nav";
|
17
18
|
@import "components/step-by-step-nav-header";
|
18
19
|
@import "components/step-by-step-nav-related";
|
@@ -0,0 +1,49 @@
|
|
1
|
+
.gem-c-related-navigation {
|
2
|
+
border-top: 2px solid $govuk-blue;
|
3
|
+
}
|
4
|
+
|
5
|
+
.gem-c-related-navigation__main-heading {
|
6
|
+
margin-top: $gutter-half;
|
7
|
+
margin-bottom: $gutter-one-third;
|
8
|
+
@include bold-19;
|
9
|
+
}
|
10
|
+
|
11
|
+
.gem-c-related-navigation__sub-heading {
|
12
|
+
border-top: 1px solid $border-colour;
|
13
|
+
padding-top: $gutter-half;
|
14
|
+
}
|
15
|
+
|
16
|
+
.gem-c-related-navigation__main-heading + .gem-c-related-navigation__sub-heading {
|
17
|
+
border-top: none;
|
18
|
+
padding-top: 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.gem-c-related-navigation__sub-heading--other {
|
22
|
+
@include bold-19;
|
23
|
+
}
|
24
|
+
|
25
|
+
.gem-c-related-navigation__nav-section {
|
26
|
+
margin-bottom: $gutter;
|
27
|
+
}
|
28
|
+
|
29
|
+
.gem-c-related-navigation__link {
|
30
|
+
list-style-type: none;
|
31
|
+
margin-bottom: $gutter-one-third;
|
32
|
+
}
|
33
|
+
|
34
|
+
.gem-c-related-navigation__section-link {
|
35
|
+
text-decoration: none;
|
36
|
+
@include bold-19;
|
37
|
+
}
|
38
|
+
|
39
|
+
.gem-c-related-navigation__section-link--other {
|
40
|
+
text-decoration: none;
|
41
|
+
}
|
42
|
+
|
43
|
+
// reset the default browser styles
|
44
|
+
.gem-c-related-navigation__link-list {
|
45
|
+
padding: 0;
|
46
|
+
margin: 0;
|
47
|
+
list-style: none;
|
48
|
+
margin-bottom: 1.25em;
|
49
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
<% related_nav_helper = RelatedNavigationHelper.new(local_assigns) %>
|
2
|
+
<% related_content = related_nav_helper.related_navigation %>
|
3
|
+
<% if related_content.map(&:values).flatten.any? || related_nav_helper.other.flatten.any? %>
|
4
|
+
<% random = SecureRandom.hex(4) %>
|
5
|
+
<aside class="gem-c-related-navigation" role="complementary">
|
6
|
+
<h2 id="related-nav-related_items-<%= random %>"
|
7
|
+
class="gem-c-related-navigation__main-heading"
|
8
|
+
data-track-count="sidebarRelatedItemSection" >
|
9
|
+
<%= t('components.related_navigation.related_content') %>
|
10
|
+
</h2>
|
11
|
+
<% section_index = 0 %>
|
12
|
+
<% related_content.each do |section| %>
|
13
|
+
<% section.each do |section_title, links| %>
|
14
|
+
<% if links.any? %>
|
15
|
+
<% section_index += 1 %>
|
16
|
+
<% unless section_title === "related_items" %>
|
17
|
+
<h3 id="related-nav-<%= section_title %>-<%= random %>"
|
18
|
+
data-track-count="sidebarRelatedItemSection"
|
19
|
+
class="<%= related_nav_helper.section_css_class("gem-c-related-navigation__sub-heading", section_title) %>">
|
20
|
+
<%= related_nav_helper.construct_section_heading(section_title) %>
|
21
|
+
</h3>
|
22
|
+
<% end %>
|
23
|
+
<nav role="navigation"
|
24
|
+
class="gem-c-related-navigation__nav-section"
|
25
|
+
aria-labelledby="related-nav-<%= section_title %>-<%= random %>"
|
26
|
+
data-module="toggle">
|
27
|
+
<ul class="gem-c-related-navigation_link-list" data-module="track-click">
|
28
|
+
<% constructed_link_array = [] %>
|
29
|
+
<% section_link_limit = related_nav_helper.calculate_section_link_limit(links) %>
|
30
|
+
<% links.each.with_index(1) do |link, index| %>
|
31
|
+
<%
|
32
|
+
link_element = link_to(
|
33
|
+
link[:text],
|
34
|
+
link[:path],
|
35
|
+
class: related_nav_helper.section_css_class("gem-c-related-navigation__section-link", section_title, link),
|
36
|
+
rel: link[:rel],
|
37
|
+
data: {
|
38
|
+
track_category: 'relatedLinkClicked',
|
39
|
+
track_action: "#{section_index}.#{index} #{related_nav_helper.construct_section_heading(section_title) || t('components.related_navigation.related_content')}",
|
40
|
+
track_label: link[:path],
|
41
|
+
track_options: {
|
42
|
+
dimension28: links.length.to_s,
|
43
|
+
dimension29: link[:text]
|
44
|
+
}
|
45
|
+
}
|
46
|
+
)
|
47
|
+
%>
|
48
|
+
<% if index <= section_link_limit %>
|
49
|
+
<li class="gem-c-related-navigation__link"><%= link_element %></li>
|
50
|
+
<% else %>
|
51
|
+
<% constructed_link_array.push(link_element) %>
|
52
|
+
<% end %>
|
53
|
+
<% end %>
|
54
|
+
<% if links.length > section_link_limit %>
|
55
|
+
<li class="gem-c-related-navigation__link toggle-wrap">
|
56
|
+
<a href="#"
|
57
|
+
data-controls="toggle_<%= section_title %>"
|
58
|
+
data-expanded="false"
|
59
|
+
data-toggled-text="<%= t("govuk_component.metadata.toggle_less", default: "Show fewer") %>">
|
60
|
+
<%= t("govuk_component.metadata.toggle_more",
|
61
|
+
number: related_nav_helper.remaining_link_count(links),
|
62
|
+
default: "+ #{related_nav_helper.remaining_link_count(links)} more") %>
|
63
|
+
</a>
|
64
|
+
</li>
|
65
|
+
<li class="gem-c-related-navigation__link">
|
66
|
+
<span id="toggle_<%= section_title %>" class="js-hidden">
|
67
|
+
<%= constructed_link_array.to_sentence.html_safe %>
|
68
|
+
</span>
|
69
|
+
</li>
|
70
|
+
<% end %>
|
71
|
+
</ul>
|
72
|
+
</nav>
|
73
|
+
<% end %>
|
74
|
+
<% end %>
|
75
|
+
<% end %>
|
76
|
+
</aside>
|
77
|
+
<% end %>
|
@@ -0,0 +1,168 @@
|
|
1
|
+
name: Related Navigation
|
2
|
+
description: Component showing related content, including topics, guidance, collections and policies (where applicable)
|
3
|
+
accessibility_criteria: |
|
4
|
+
- Should have a role of 'complementary' as it complements the main page content
|
5
|
+
- Should have a role of 'navigation' on any navigation elements inside the component
|
6
|
+
shared_accessibility_criteria:
|
7
|
+
- link
|
8
|
+
accessibility_excluded_rules:
|
9
|
+
- duplicate-id
|
10
|
+
examples:
|
11
|
+
default:
|
12
|
+
data:
|
13
|
+
links:
|
14
|
+
ordered_related_items:
|
15
|
+
- title: Find an apprenticeship
|
16
|
+
base_path: /apply-apprenticeship
|
17
|
+
- title: Training and study at work
|
18
|
+
base_path: /training-study-work-your-rights
|
19
|
+
- title: Careers helpline for teenagers
|
20
|
+
base_path: /careers-helpline-for-teenagers
|
21
|
+
with_curated_topics:
|
22
|
+
data:
|
23
|
+
links:
|
24
|
+
topics:
|
25
|
+
- title: Apprenticeships, 14 to 19 education and training for work
|
26
|
+
base_path: /browse/education/find-course
|
27
|
+
document_type: topic
|
28
|
+
- title: Finding a job
|
29
|
+
base_path: /browse/working/finding-job
|
30
|
+
document_type: topic
|
31
|
+
- title: Apprenticeships
|
32
|
+
base_path: /topic/further-education-skills/apprenticeships
|
33
|
+
document_type: topic
|
34
|
+
with_collections:
|
35
|
+
data:
|
36
|
+
links:
|
37
|
+
document_collections:
|
38
|
+
- title: Recruit an apprentice (formerly apprenticeship vacancies)
|
39
|
+
base_path: /government/collections/apprenticeship-vacancies
|
40
|
+
document_type: document_collection
|
41
|
+
- title: The future of jobs and skills
|
42
|
+
base_path: /government/collections/the-future-of-jobs-and-skills
|
43
|
+
document_type: document_collection
|
44
|
+
with_policies:
|
45
|
+
data:
|
46
|
+
links:
|
47
|
+
related_policies:
|
48
|
+
- title: Further education and training
|
49
|
+
base_path: /government/policies/further-education-and-training
|
50
|
+
document_type: policy
|
51
|
+
- title: Primary school education
|
52
|
+
base_path: /government/policies/primary-school-education
|
53
|
+
document_type: policy
|
54
|
+
with_topical_events:
|
55
|
+
data:
|
56
|
+
links:
|
57
|
+
topical_events:
|
58
|
+
- title: UK-China High-Level People to People Dialogue 2017
|
59
|
+
base_path: /government/topical-events/uk-china-high-level-people-to-people-dialogue-2017
|
60
|
+
document_type: topical_event
|
61
|
+
with_world_locations:
|
62
|
+
data:
|
63
|
+
links:
|
64
|
+
world_locations:
|
65
|
+
- title: South Sudan
|
66
|
+
base_path: /world/south-sudan/news
|
67
|
+
- title: USA
|
68
|
+
base_path: /world/usa/news
|
69
|
+
with_external_related_links:
|
70
|
+
description: The component can accept other related links, such as external links or other contacts.
|
71
|
+
data:
|
72
|
+
details:
|
73
|
+
external_related_links:
|
74
|
+
- url: "http://media.slc.co.uk/sfe/1718/ft/sfe_terms_and_conditions_guide_1718_d.pdf"
|
75
|
+
title: "Student loans: terms and conditions 2017 to 2018 (PDF, 136KB)"
|
76
|
+
- url: "https://www.thestudentroom.co.uk/content.php?r=5967-Repaying-your-student-loan"
|
77
|
+
title: "The Student Room: repaying your student loan"
|
78
|
+
with_extensive_world_locations:
|
79
|
+
description: The component handles having a long list of content passed to it, by only showing the first few items and hiding the rest behind a Show More toggle.
|
80
|
+
data:
|
81
|
+
links:
|
82
|
+
world_locations:
|
83
|
+
- title: Algeria
|
84
|
+
base_path: /world/algeria/news
|
85
|
+
- title: Austria
|
86
|
+
base_path: /world/austria/news
|
87
|
+
- title: Belarus
|
88
|
+
base_path: /world/belarus/news
|
89
|
+
- title: Belgium
|
90
|
+
base_path: /world/belgium/news
|
91
|
+
- title: Bolivia
|
92
|
+
base_path: /world/bolivia/news
|
93
|
+
- title: Brazil
|
94
|
+
base_path: /world/brazil/news
|
95
|
+
- title: Canada
|
96
|
+
base_path: /world/canada/news
|
97
|
+
- title: Chile
|
98
|
+
base_path: /world/chile/news
|
99
|
+
- title: China
|
100
|
+
base_path: /world/China/news
|
101
|
+
- title: Cuba
|
102
|
+
base_path: /world/cuba/news
|
103
|
+
- title: Denmark
|
104
|
+
base_path: /world/denmark/news
|
105
|
+
- title: Egypt
|
106
|
+
base_path: /world/egypt/news
|
107
|
+
- title: Fiji
|
108
|
+
base_path: /world/fiji/news
|
109
|
+
- title: Finland
|
110
|
+
base_path: /world/finland/news
|
111
|
+
- title: France
|
112
|
+
base_path: /world/france/news
|
113
|
+
- title: Germany
|
114
|
+
base_path: /world/germany/news
|
115
|
+
- title: Greece
|
116
|
+
base_path: /world/greece/news
|
117
|
+
- title: Norway
|
118
|
+
base_path: /world/norway/news
|
119
|
+
- title: Russia
|
120
|
+
base_path: /world/russia/news
|
121
|
+
- title: Sweden
|
122
|
+
base_path: /world/sweden/news
|
123
|
+
- title: United Kingdom
|
124
|
+
base_path: /world/united-kingdom/news
|
125
|
+
- title: USA
|
126
|
+
base_path: /world/usa/news
|
127
|
+
with_all_related-content:
|
128
|
+
data:
|
129
|
+
links:
|
130
|
+
ordered_related_items:
|
131
|
+
- title: Find an apprenticeship
|
132
|
+
base_path: /apply-apprenticeship
|
133
|
+
- title: Training and study at work
|
134
|
+
base_path: /training-study-work-your-rights
|
135
|
+
- title: Careers helpline for teenagers
|
136
|
+
base_path: /careers-helpline-for-teenagers
|
137
|
+
topics:
|
138
|
+
- title: Apprenticeships, 14 to 19 education and training for work
|
139
|
+
base_path: /browse/education/find-course
|
140
|
+
document_type: topic
|
141
|
+
- title: Finding a job
|
142
|
+
base_path: /browse/working/finding-job
|
143
|
+
document_type: topic
|
144
|
+
- title: Apprenticeships
|
145
|
+
base_path: /topic/further-education-skills/apprenticeships
|
146
|
+
document_type: topic
|
147
|
+
document_collections:
|
148
|
+
- title: Recruit an apprentice (formerly apprenticeship vacancies)
|
149
|
+
base_path: /government/collections/apprenticeship-vacancies
|
150
|
+
document_type: document_collection
|
151
|
+
- title: The future of jobs and skills
|
152
|
+
base_path: /government/collections/the-future-of-jobs-and-skills
|
153
|
+
document_type: document_collection
|
154
|
+
related_policies:
|
155
|
+
- title: Further education and training
|
156
|
+
base_path: /government/policies/further-education-and-training
|
157
|
+
document_type: policy
|
158
|
+
world_locations:
|
159
|
+
- title: South Sudan
|
160
|
+
base_path: /world/south-sudan/news
|
161
|
+
- title: USA
|
162
|
+
base_path: /world/usa/news
|
163
|
+
details:
|
164
|
+
external_related_links:
|
165
|
+
- url: "http://media.slc.co.uk/sfe/1718/ft/sfe_terms_and_conditions_guide_1718_d.pdf"
|
166
|
+
title: "Student loans: terms and conditions 2017 to 2018 (PDF, 136KB)"
|
167
|
+
- title: The Student Room repaying your student loan
|
168
|
+
url: https://www.thestudentroom.co.uk/content.php?r=5967-Repaying-your-student-loan
|
data/config/locales/en.yml
CHANGED
@@ -21,9 +21,20 @@
|
|
21
21
|
|
22
22
|
en:
|
23
23
|
components:
|
24
|
-
radio:
|
25
|
-
or: 'or'
|
26
24
|
back_link:
|
27
25
|
back: 'Back'
|
26
|
+
radio:
|
27
|
+
or: 'or'
|
28
|
+
related_navigation:
|
29
|
+
collections: "Collection"
|
30
|
+
external_links: "Elsewhere on the web"
|
31
|
+
policies: "Policy"
|
32
|
+
publishers: "Published by"
|
33
|
+
related_content: "Related content"
|
34
|
+
related_guides: "Detailed guidance"
|
35
|
+
statistical_data_sets: "Statistical data set"
|
36
|
+
topics: "Explore the topic"
|
37
|
+
topical_events: "Topical event"
|
38
|
+
world_locations: "World locations"
|
28
39
|
step_by_step_nav_related:
|
29
40
|
part_of: "Part of"
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "govuk_publishing_components/config"
|
2
2
|
require "govuk_publishing_components/engine"
|
3
3
|
require "govuk_publishing_components/components/step_by_step_nav_helper"
|
4
|
+
require "govuk_publishing_components/components/related_navigation_helper"
|
4
5
|
|
5
6
|
module GovukPublishingComponents
|
6
7
|
end
|
@@ -0,0 +1,245 @@
|
|
1
|
+
class RelatedNavigationHelper
|
2
|
+
MAX_SECTION_LENGTH = 5
|
3
|
+
DEFINED_SECTIONS = %w(
|
4
|
+
related_guides
|
5
|
+
topics
|
6
|
+
collections
|
7
|
+
policies
|
8
|
+
topical_events
|
9
|
+
world_locations
|
10
|
+
statistical_data_sets
|
11
|
+
).freeze
|
12
|
+
|
13
|
+
def initialize(content_item)
|
14
|
+
@content_item = content_item
|
15
|
+
end
|
16
|
+
|
17
|
+
def related_navigation
|
18
|
+
@related_content ||= [
|
19
|
+
{ "related_items" => related_items },
|
20
|
+
{ "related_guides" => related_guides },
|
21
|
+
{ "collections" => related_collections },
|
22
|
+
{ "topics" => related_topics },
|
23
|
+
{ "policies" => related_policies },
|
24
|
+
{ "topical_events" => related_topical_events },
|
25
|
+
{ "world_locations" => related_world_locations },
|
26
|
+
{ "statistical_data_sets" => related_statistical_data_sets },
|
27
|
+
{ "worldwide_organisations" => related_worldwide_organisations },
|
28
|
+
]
|
29
|
+
|
30
|
+
other = [related_external_links, related_contacts] || []
|
31
|
+
other.each do |sections|
|
32
|
+
sections.each do |section|
|
33
|
+
@related_content.push(
|
34
|
+
section["title"].tr(' ', '_') => section["links"]
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
@related_content
|
40
|
+
end
|
41
|
+
|
42
|
+
def other
|
43
|
+
@other ||= []
|
44
|
+
end
|
45
|
+
|
46
|
+
def construct_section_heading(section_title)
|
47
|
+
unless section_title === "related_items"
|
48
|
+
I18n.t('components.related_navigation.' + section_title, default: section_title.tr('_', ' '))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def section_css_class(css_class, section_title, link = {})
|
53
|
+
unless DEFINED_SECTIONS.include?(section_title) || link.fetch(:finder, false)
|
54
|
+
css_class += "--other"
|
55
|
+
end
|
56
|
+
css_class
|
57
|
+
end
|
58
|
+
|
59
|
+
def calculate_section_link_limit(links)
|
60
|
+
links.length == MAX_SECTION_LENGTH + 1 ? MAX_SECTION_LENGTH + 1 : MAX_SECTION_LENGTH
|
61
|
+
end
|
62
|
+
|
63
|
+
def remaining_link_count(links)
|
64
|
+
links.length - MAX_SECTION_LENGTH
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def build_links_for_sidebar(collection, path_key = "base_path", additional_attr = {})
|
70
|
+
collection.map do |link|
|
71
|
+
{
|
72
|
+
path: link[path_key],
|
73
|
+
text: link["title"]
|
74
|
+
}.merge(additional_attr)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def world_location_base_path(title)
|
79
|
+
"/world/#{parameterise(title)}/news"
|
80
|
+
end
|
81
|
+
|
82
|
+
def related_items
|
83
|
+
links = build_links_for_sidebar(quick_links, "url")
|
84
|
+
mainstream_links = related_mainstream_content
|
85
|
+
related_ordered_items = link_group("ordered_related_items")
|
86
|
+
if links.any?
|
87
|
+
links + mainstream_links
|
88
|
+
else
|
89
|
+
build_links_for_sidebar(related_ordered_items) + mainstream_links
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def quick_links
|
94
|
+
@content_item.dig("details", "quick_links").to_a
|
95
|
+
end
|
96
|
+
|
97
|
+
def related_world_locations
|
98
|
+
locations = link_group("world_locations")
|
99
|
+
locations.map! { |link| link.merge("base_path" => world_location_base_path(link["title"])) }
|
100
|
+
build_links_for_sidebar(locations)
|
101
|
+
end
|
102
|
+
|
103
|
+
def related_worldwide_organisations
|
104
|
+
organisations = filter_link_type("worldwide_organisations", "worldwide_organisation")
|
105
|
+
build_links_for_sidebar(organisations)
|
106
|
+
end
|
107
|
+
|
108
|
+
def related_collections
|
109
|
+
collections = filter_link_type("document_collections", "document_collection")
|
110
|
+
build_links_for_sidebar(collections)
|
111
|
+
end
|
112
|
+
|
113
|
+
def filter_link_type(group, type)
|
114
|
+
links = link_group(group)
|
115
|
+
links.select do |link|
|
116
|
+
link["document_type"] == type
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def related_policies
|
121
|
+
policies = filter_link_type("related_policies", "policy")
|
122
|
+
build_links_for_sidebar(policies)
|
123
|
+
end
|
124
|
+
|
125
|
+
def related_statistical_data_sets
|
126
|
+
statistical_data_sets = filter_link_type("related_statistical_data_sets", "statistical_data_set")
|
127
|
+
build_links_for_sidebar(statistical_data_sets)
|
128
|
+
end
|
129
|
+
|
130
|
+
def related_topics
|
131
|
+
topics = filter_link_type("topics", "topic")
|
132
|
+
links = build_links_for_sidebar(topics)
|
133
|
+
links << related_mainstream_topic << related_mainstream_parent_topic
|
134
|
+
deduplicate_topics_by_title(links.compact)
|
135
|
+
end
|
136
|
+
|
137
|
+
def related_topical_events
|
138
|
+
topical_events = filter_link_type("topical_events", "topical_event")
|
139
|
+
build_links_for_sidebar(topical_events)
|
140
|
+
end
|
141
|
+
|
142
|
+
def related_contacts
|
143
|
+
contacts = filter_link_type("related", "contact")
|
144
|
+
return [] unless contacts.any?
|
145
|
+
[
|
146
|
+
title: "Other contacts",
|
147
|
+
links: build_links_for_sidebar(contacts).map
|
148
|
+
]
|
149
|
+
end
|
150
|
+
|
151
|
+
def related_external_links
|
152
|
+
external_links = @content_item.dig("details", "external_related_links").to_a
|
153
|
+
return [] unless external_links.any?
|
154
|
+
[
|
155
|
+
"title" => "Elsewhere on the web",
|
156
|
+
"links" => build_links_for_sidebar(external_links, "url", rel: 'external')
|
157
|
+
]
|
158
|
+
end
|
159
|
+
|
160
|
+
def related_mainstream_topic
|
161
|
+
return unless tagged_to_same_mainstream_browse_page.any?
|
162
|
+
{ text: parent["title"], path: parent["base_path"] }
|
163
|
+
end
|
164
|
+
|
165
|
+
def related_mainstream_parent_topic
|
166
|
+
return unless parents_tagged_to_same_mainstream_browse_page.any?
|
167
|
+
{ text: grandparent["title"], path: grandparent["base_path"] }
|
168
|
+
end
|
169
|
+
|
170
|
+
def parent
|
171
|
+
link_group("parent").first
|
172
|
+
end
|
173
|
+
|
174
|
+
def grandparent
|
175
|
+
parent.dig("parent", 0)
|
176
|
+
end
|
177
|
+
|
178
|
+
# This method post-processes the topics collated by the helper.
|
179
|
+
# We add mainstream browse page links if they are present, however
|
180
|
+
# if these have the same title as an existing topic we should prefer
|
181
|
+
# the mainstream version and remove the existing topic.
|
182
|
+
# @see spec/related_navigation_helper_spec.rb for test coverage.
|
183
|
+
def deduplicate_topics_by_title(topics)
|
184
|
+
is_dupe = lambda { |a, b| a && a != b && a[:text] == b[:text] }
|
185
|
+
|
186
|
+
topics.delete_if do |t|
|
187
|
+
is_dupe.call(related_mainstream_topic, t) ||
|
188
|
+
is_dupe.call(related_mainstream_parent_topic, t)
|
189
|
+
end
|
190
|
+
|
191
|
+
topics
|
192
|
+
end
|
193
|
+
|
194
|
+
def parameterise(str, sep = "-")
|
195
|
+
parameterised_str = str.gsub(/[^\w\-]+/, sep)
|
196
|
+
unless sep.nil? || sep.empty?
|
197
|
+
re_sep = Regexp.escape(sep)
|
198
|
+
# No more than one of the separator in a row.
|
199
|
+
parameterised_str.gsub!(/#{re_sep}{2,}/, sep)
|
200
|
+
# Remove leading/trailing separator.
|
201
|
+
parameterised_str.gsub!(/^#{re_sep}|#{re_sep}$/, '')
|
202
|
+
end
|
203
|
+
parameterised_str.downcase
|
204
|
+
end
|
205
|
+
|
206
|
+
def tagged_to_same_mainstream_browse_page
|
207
|
+
return [] unless parent
|
208
|
+
@tagged_to_same_mainstream_browse_page ||= related_links.select do |related_item|
|
209
|
+
links = related_item.dig("links", "mainstream_browse_pages") || []
|
210
|
+
content_ids = links.any? ? links.map { |page| page["content_id"] } : []
|
211
|
+
content_ids.include?(parent["content_id"])
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def parents_tagged_to_same_mainstream_browse_page
|
216
|
+
return [] unless parent && grandparent
|
217
|
+
|
218
|
+
common_parent_content_ids = tagged_to_same_mainstream_browse_page.map(&:content_id)
|
219
|
+
|
220
|
+
@parents_tagged_to_same_mainstream_browse_page ||= related_links.select do |related_item|
|
221
|
+
next if common_parent_content_ids.include?(related_item["content_id"])
|
222
|
+
related_item.dig("links", "mainstream_browse_pages").map(&:parent).map(&:content_id).include?(grandparent["content_id"])
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def related_links
|
227
|
+
link_group("ordered_related_items")
|
228
|
+
end
|
229
|
+
|
230
|
+
def related_mainstream_content
|
231
|
+
return [] unless @content_item["document_type"] == "detailed_guide"
|
232
|
+
content = link_group("related_mainstream_content")
|
233
|
+
build_links_for_sidebar(content)
|
234
|
+
end
|
235
|
+
|
236
|
+
def related_guides
|
237
|
+
return [] unless @content_item["document_type"] == "detailed_guide"
|
238
|
+
guides = link_group("related_guides")
|
239
|
+
build_links_for_sidebar(guides)
|
240
|
+
end
|
241
|
+
|
242
|
+
def link_group(type)
|
243
|
+
@content_item.dig("links", type).to_a
|
244
|
+
end
|
245
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_publishing_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0.64'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: govuk_schemas
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '1.0'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '1.0'
|
223
237
|
- !ruby/object:Gem::Dependency
|
224
238
|
name: webmock
|
225
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -265,6 +279,7 @@ files:
|
|
265
279
|
- app/assets/stylesheets/govuk_publishing_components/components/_input.scss
|
266
280
|
- app/assets/stylesheets/govuk_publishing_components/components/_label.scss
|
267
281
|
- app/assets/stylesheets/govuk_publishing_components/components/_radio.scss
|
282
|
+
- app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss
|
268
283
|
- app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss
|
269
284
|
- app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss
|
270
285
|
- app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss
|
@@ -295,6 +310,7 @@ files:
|
|
295
310
|
- app/views/govuk_publishing_components/components/_input.html.erb
|
296
311
|
- app/views/govuk_publishing_components/components/_label.html.erb
|
297
312
|
- app/views/govuk_publishing_components/components/_radio.html.erb
|
313
|
+
- app/views/govuk_publishing_components/components/_related_navigation.html.erb
|
298
314
|
- app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb
|
299
315
|
- app/views/govuk_publishing_components/components/_step_by_step_nav_header.html.erb
|
300
316
|
- app/views/govuk_publishing_components/components/_step_by_step_nav_related.html.erb
|
@@ -305,6 +321,7 @@ files:
|
|
305
321
|
- app/views/govuk_publishing_components/components/docs/input.yml
|
306
322
|
- app/views/govuk_publishing_components/components/docs/label.yml
|
307
323
|
- app/views/govuk_publishing_components/components/docs/radio.yml
|
324
|
+
- app/views/govuk_publishing_components/components/docs/related_navigation.yml
|
308
325
|
- app/views/govuk_publishing_components/components/docs/step_by_step_nav.yml
|
309
326
|
- app/views/govuk_publishing_components/components/docs/step_by_step_nav_header.yml
|
310
327
|
- app/views/govuk_publishing_components/components/docs/step_by_step_nav_related.yml
|
@@ -319,6 +336,7 @@ files:
|
|
319
336
|
- lib/generators/govuk_publishing_components/templates/_component.scss
|
320
337
|
- lib/generators/govuk_publishing_components/templates/component.yml.erb
|
321
338
|
- lib/govuk_publishing_components.rb
|
339
|
+
- lib/govuk_publishing_components/components/related_navigation_helper.rb
|
322
340
|
- lib/govuk_publishing_components/components/step_by_step_nav_helper.rb
|
323
341
|
- lib/govuk_publishing_components/config.rb
|
324
342
|
- lib/govuk_publishing_components/engine.rb
|