govuk_publishing_components 6.6.0 → 6.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba58789467891b5f446dd9487b0984dd34d98ba61582e432a68036b994adcb8b
4
- data.tar.gz: b51a14f8281b3a1e06238b7aa7987a0ef6bea4b4669efdda94b381f20c42a973
3
+ metadata.gz: f88881b02018b9b7cc7e47fcd045799d90ded54098093f95f4481d594b23f9b9
4
+ data.tar.gz: a8e89d46fac1748bfcbc2fd22472ad5a8a124b0ebb062418354aea7f919460a5
5
5
  SHA512:
6
- metadata.gz: 22a327348059ef856523174f4ea4bfdc4cb67af5b57cd5b9a0599daefcd319d8d202a11892273dd1e08c70624219cf17f94db26d5776aee0e8bb2336e069c825
7
- data.tar.gz: 2eccea1e451c11974f6bd94bdce97f070eb3ea97cce2a24bfaf3b51b7a63279707b96695fb093b480905f72e744bd9eb38ec51203bcbf37b81c4d65a1aec285d
6
+ metadata.gz: 11f29247660b10e5628829475e88b63e42a3be0d0d17d6b4a7c10b5920bbefaebf7ad898c93dad40f662a5a50875b61240d5560a3a090231284cfd5ee3f4d77c
7
+ data.tar.gz: eebdd2b04fa3998c304b855c1fa48e4e3cfba93b7ceef353c9676873183ca7f3dcdc5280dccdec15a8c9bd4e97efd22a961d6d5a8d81144077e1379d55595c42
@@ -117,7 +117,7 @@
117
117
  <input type="hidden" name="url" value="<%= request.original_url -%>">
118
118
  <input type="hidden" name="user_agent" value="<%= request.user_agent -%>">
119
119
 
120
- <input name="email_survey_signup[survey_id]" type="hidden" value="user_satisfaction_survey">
120
+ <input name="email_survey_signup[survey_id]" type="hidden" value="footer_satisfaction_survey">
121
121
  <input name="email_survey_signup[survey_source]" type="hidden" value="<%= request.original_url -%>">
122
122
  <input name="email_survey_signup[ga_client_id]" type="hidden" value="1627485790.1515403243">
123
123
 
@@ -0,0 +1,5 @@
1
+ <% meta_tags = GovukPublishingComponents::Presenters::MetaTags.new(content_item, local_assigns).meta_tags %>
2
+
3
+ <% meta_tags.each do |name, content| %>
4
+ <meta name="<%= name %>" content="<%= content %>">
5
+ <% end %>
@@ -0,0 +1,25 @@
1
+ name: Meta Tags
2
+ description: Meta tags to provide analytics information about the current page
3
+ body: |
4
+ This takes a content-store links hash like object which it can then turn into
5
+ the correct analytics identifier metadata tags.
6
+
7
+ The code which reads the meta tags can be found <a href="https://github.com/alphagov/static/blob/master/app/assets/javascripts/analytics/static-analytics.js#L76-L96">in static-analytics.js</a>.
8
+ accessibility_criteria: |
9
+ The analytics meta tags component should not be visible to any users.
10
+ examples:
11
+ with_organisations:
12
+ data:
13
+ content_item:
14
+ links:
15
+ organisations:
16
+ - analytics_identifier: D1
17
+ - analytics_identifier: D3
18
+ worldwide_organisations:
19
+ - analytics_identifier: EO3
20
+ with_world_locations:
21
+ data:
22
+ content_item:
23
+ links:
24
+ world_locations:
25
+ - analytics_identifier: WL3
@@ -7,6 +7,7 @@ require "govuk_publishing_components/presenters/page_with_step_by_step_navigatio
7
7
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_parent"
8
8
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons"
9
9
  require "govuk_publishing_components/presenters/services"
10
+ require "govuk_publishing_components/presenters/meta_tags"
10
11
  require "govuk_publishing_components/presenters/taxonomy_navigation"
11
12
  require "govuk_publishing_components/presenters/rummager_taxonomy_sidebar_links"
12
13
  require "govuk_publishing_components/presenters/curated_taxonomy_sidebar_links"
@@ -0,0 +1,141 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ class MetaTags
4
+ attr_reader :content_item, :details, :links, :local_assigns
5
+
6
+ def initialize(content_item, local_assigns)
7
+ # We have to call deep_symbolize_keys because we're often dealing with a
8
+ # parsed JSON document which will have string keys by default, but our
9
+ # components use symbol keys and we want consistency.
10
+ @content_item = content_item.to_h.deep_symbolize_keys
11
+ @details = @content_item[:details] || {}
12
+ @links = @content_item[:links] || {}
13
+ @local_assigns = local_assigns
14
+ end
15
+
16
+ def meta_tags
17
+ meta_tags = {}
18
+ meta_tags = add_core_tags(meta_tags)
19
+ meta_tags = add_organisation_tags(meta_tags)
20
+ meta_tags = add_political_tags(meta_tags)
21
+ meta_tags = add_taxonomy_tags(meta_tags)
22
+ meta_tags = add_step_by_step_tags(meta_tags)
23
+ meta_tags
24
+ end
25
+
26
+ private
27
+
28
+ def add_core_tags(meta_tags)
29
+ meta_tags["govuk:format"] = content_item[:document_type] if content_item[:document_type]
30
+ meta_tags["govuk:schema-name"] = content_item[:schema_name] if content_item[:schema_name]
31
+
32
+ user_journey_stage = content_item[:user_journey_document_supertype]
33
+ meta_tags["govuk:user-journey-stage"] = user_journey_stage if user_journey_stage
34
+
35
+ navigation_document_type = content_item[:navigation_document_supertype]
36
+ meta_tags["govuk:navigation-document-type"] = navigation_document_type if navigation_document_type
37
+
38
+ meta_tags["govuk:content-id"] = content_item[:content_id] if content_item[:content_id]
39
+ meta_tags["govuk:withdrawn"] = "withdrawn" if content_item[:withdrawn_notice].present?
40
+ meta_tags["govuk:content-has-history"] = "true" if has_content_history?
41
+ meta_tags["govuk:static-analytics:strip-postcodes"] = "true" if should_strip_postcode_pii?(content_item, local_assigns)
42
+
43
+ meta_tags
44
+ end
45
+
46
+ def add_organisation_tags(meta_tags)
47
+ organisations = []
48
+ organisations += links[:organisations] || []
49
+ organisations += links[:worldwide_organisations] || []
50
+ organisations_content = organisations.map { |link| "<#{link[:analytics_identifier]}>" }.uniq.join
51
+ meta_tags["govuk:analytics:organisations"] = organisations_content if organisations.any?
52
+
53
+ world_locations = links[:world_locations] || []
54
+ world_locations_content = world_locations.map { |link| "<#{link[:analytics_identifier]}>" }.join
55
+ meta_tags["govuk:analytics:world-locations"] = world_locations_content if world_locations.any?
56
+
57
+ meta_tags
58
+ end
59
+
60
+ def add_political_tags(meta_tags)
61
+ if details.key?(:political) && details.key?(:government)
62
+ political_status = "non-political"
63
+ if details[:political]
64
+ political_status = details[:government][:current] ? "political" : "historic"
65
+ end
66
+
67
+ meta_tags["govuk:political-status"] = political_status
68
+ meta_tags["govuk:publishing-government"] = details[:government][:slug]
69
+ end
70
+
71
+ meta_tags
72
+ end
73
+
74
+ def add_taxonomy_tags(meta_tags)
75
+ themes = root_taxon_slugs(content_item)
76
+ meta_tags["govuk:themes"] = themes.to_a.sort.join(', ') unless themes.empty?
77
+
78
+ taxons = if content_item[:document_type] == 'taxon'
79
+ [content_item]
80
+ else
81
+ links[:taxons] || []
82
+ end
83
+
84
+ taxons.sort_by! { |taxon| taxon[:title] }
85
+ taxon_slugs_without_theme = taxons.map do |taxon|
86
+ base_path = taxon[:base_path] || ""
87
+ slug_without_theme = base_path[%r{/[^/]+/(.+)}, 1]
88
+ # Return the slug without the theme, or in the special case of a root taxon,
89
+ # just return the full slug (because it doesn't have a slug beneath the theme)
90
+ slug_without_theme || base_path.sub(%r(^/), '')
91
+ end
92
+ taxon_ids = taxons.map { |taxon| taxon[:content_id] }
93
+
94
+ meta_tags["govuk:taxon-id"] = taxon_ids.first unless taxon_ids.empty?
95
+ meta_tags["govuk:taxon-ids"] = taxon_ids.join(',') unless taxon_ids.empty?
96
+ meta_tags["govuk:taxon-slug"] = taxon_slugs_without_theme.first unless taxon_slugs_without_theme.empty?
97
+ meta_tags["govuk:taxon-slugs"] = taxon_slugs_without_theme.join(',') unless taxon_slugs_without_theme.empty?
98
+ meta_tags
99
+ end
100
+
101
+ def add_step_by_step_tags(meta_tags)
102
+ stepnavs = links[:part_of_step_navs] || []
103
+ stepnavs_content = stepnavs.map { |stepnav| stepnav[:content_id] }.join(",")
104
+ meta_tags["govuk:stepnavs"] = stepnavs_content if stepnavs_content.present?
105
+ meta_tags
106
+ end
107
+
108
+ def has_content_history?
109
+ (content_item[:public_updated_at] && details[:first_public_at] && content_item[:public_updated_at] != details[:first_public_at]) ||
110
+ (details[:change_history] && details[:change_history].size > 1)
111
+ end
112
+
113
+ def root_taxon_slugs(content_item)
114
+ root_taxon_set = Set.new
115
+
116
+ links = content_item[:links]
117
+ # Taxons will have :parent_taxons, but content items will have :taxons
118
+ parent_taxons = links[:parent_taxons] || links[:taxons] unless links.nil?
119
+
120
+ if parent_taxons.blank?
121
+ root_taxon_set << content_item[:base_path].sub(%r(^/), '') if content_item[:document_type] == 'taxon'
122
+ else
123
+ parent_taxons.each do |parent_taxon|
124
+ root_taxon_set += root_taxon_slugs(parent_taxon)
125
+ end
126
+ end
127
+
128
+ root_taxon_set
129
+ end
130
+
131
+ def should_strip_postcode_pii?(content_item, local_assigns)
132
+ # allow override if we explicitly want to strip pii (or not) regardless of
133
+ # document_type
134
+ return local_assigns[:strip_postcode_pii] if local_assigns.key?(:strip_postcode_pii)
135
+
136
+ formats_that_might_include_postcodes = %w[smart_answer search]
137
+ formats_that_might_include_postcodes.include?(content_item[:document_type])
138
+ end
139
+ end
140
+ end
141
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = '6.6.0'.freeze
2
+ VERSION = '6.7.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.6.0
4
+ version: 6.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-23 00:00:00.000000000 Z
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -368,6 +368,7 @@ files:
368
368
  - app/views/govuk_publishing_components/components/_input.html.erb
369
369
  - app/views/govuk_publishing_components/components/_inverse_header.html.erb
370
370
  - app/views/govuk_publishing_components/components/_label.html.erb
371
+ - app/views/govuk_publishing_components/components/_meta_tags.html.erb
371
372
  - app/views/govuk_publishing_components/components/_radio.html.erb
372
373
  - app/views/govuk_publishing_components/components/_related_navigation.html.erb
373
374
  - app/views/govuk_publishing_components/components/_search.html.erb
@@ -387,6 +388,7 @@ files:
387
388
  - app/views/govuk_publishing_components/components/docs/input.yml
388
389
  - app/views/govuk_publishing_components/components/docs/inverse_header.yml
389
390
  - app/views/govuk_publishing_components/components/docs/label.yml
391
+ - app/views/govuk_publishing_components/components/docs/meta_tags.yml
390
392
  - app/views/govuk_publishing_components/components/docs/radio.yml
391
393
  - app/views/govuk_publishing_components/components/docs/related_navigation.yml
392
394
  - app/views/govuk_publishing_components/components/docs/search.yml
@@ -416,6 +418,7 @@ files:
416
418
  - lib/govuk_publishing_components/presenters/content_item.rb
417
419
  - lib/govuk_publishing_components/presenters/contextual_navigation.rb
418
420
  - lib/govuk_publishing_components/presenters/curated_taxonomy_sidebar_links.rb
421
+ - lib/govuk_publishing_components/presenters/meta_tags.rb
419
422
  - lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb
420
423
  - lib/govuk_publishing_components/presenters/related_navigation_helper.rb
421
424
  - lib/govuk_publishing_components/presenters/rummager_taxonomy_sidebar_links.rb