govuk_tech_docs 5.1.1 → 5.2.1
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 +4 -4
- data/.github/workflows/test.yaml +2 -2
- data/CHANGELOG.md +10 -0
- data/README.md +55 -0
- data/example/config/tech-docs.yml +5 -3
- data/lib/assets/javascripts/_modules/cookie-banner.js +39 -0
- data/lib/assets/javascripts/_start-modules.js +1 -0
- data/lib/assets/stylesheets/_govuk_tech_docs.scss +1 -0
- data/lib/govuk_tech_docs/table_of_contents/helpers.rb +4 -4
- data/lib/govuk_tech_docs/version.rb +1 -1
- data/lib/source/layouts/{_analytics_head.erb → _analytics_ga4_gtag.erb} +1 -1
- data/lib/source/layouts/_analytics_ga4_gtm.erb +18 -0
- data/lib/source/layouts/_cookie_banner.erb +24 -0
- data/lib/source/layouts/core.erb +3 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: de7d09fce9aa71616b0dfdda9e1673fa519b543f998b09e2fb8bb192682183bd
|
|
4
|
+
data.tar.gz: c1caca4ee1f180d09e154384ea2d0b8a741f16138ccf47d4bde89ba314933495
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cb71ae66521601c65cba2bdc7341fe1f42c677a50989c67e3d35aaa5d7c6d2c24d6dc3aac9856f8557e88ed938756058bc0b906d4d6a1516c402258a70a12538
|
|
7
|
+
data.tar.gz: 68cb0b82b20439613af27bf9f798e5dda7c5d44c59200c7db91c62bde6c1be525ae5960ad94464f8cb1bc2f13c6ed27f93adca5be726b5cbcb15d32ef09848bc
|
data/.github/workflows/test.yaml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 5.2.1
|
|
2
|
+
|
|
3
|
+
- [Add option to not render child resources when creating a table of contents](https://github.com/alphagov/tech-docs-gem/pull/439/changes)
|
|
4
|
+
|
|
5
|
+
## 5.2.0
|
|
6
|
+
|
|
7
|
+
### New features
|
|
8
|
+
|
|
9
|
+
- [Support using Google Tag Manager for Google Analytics 4](https://github.com/alphagov/tech-docs-gem/pull/436)
|
|
10
|
+
|
|
1
11
|
## 5.1.1
|
|
2
12
|
|
|
3
13
|
### Fixes
|
data/README.md
CHANGED
|
@@ -17,6 +17,61 @@ This gem uses [GOV.UK Frontend](https://github.com/alphagov/govuk-frontend), par
|
|
|
17
17
|
|
|
18
18
|
We use `npm` to download the govuk-frontend package. To update to a new version, change the version in the [package.json file](package.json) and run `npm update`.
|
|
19
19
|
|
|
20
|
+
## Table of contents helper functions
|
|
21
|
+
|
|
22
|
+
With `Middleman` you can apply layouts to group pages and customise sites. This gem has the following additional helper functions to manage the table of contents (ToC):
|
|
23
|
+
|
|
24
|
+
- `single_page_table_of_contents` to create a ToC from the headings on the current page
|
|
25
|
+
- `multi_page_table_of_contents` to create a ToC for a group of pages, opened at the current page
|
|
26
|
+
|
|
27
|
+
### Single page table of contents
|
|
28
|
+
|
|
29
|
+
The `single_page_table_of_contents` helper has the following parameters:
|
|
30
|
+
|
|
31
|
+
| Parameter | Description |
|
|
32
|
+
|-------------|----------------------------------------------------------------------------------------|
|
|
33
|
+
| `html` | The html of the current page. |
|
|
34
|
+
| `url` | Optional parameter used to override the url of the page heading. Defaults to `""`. |
|
|
35
|
+
| `max_level` | Optional parameter used to set the depth of the table of contents. Defaults to `nil`. |
|
|
36
|
+
|
|
37
|
+
Below is an example of using `single_page_table_of_contents` in a layout file:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
<%
|
|
41
|
+
wrap_layout :core do
|
|
42
|
+
content_for :sidebar do
|
|
43
|
+
<%= single_page_table_of_contents(html, max_level: 2) %>
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
%>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This example will create a ToC containing the current page title, and nested headings to a depth of 2.
|
|
50
|
+
|
|
51
|
+
### Multi page table of contents
|
|
52
|
+
|
|
53
|
+
The `multi_page_table_of_contents` has the following parameters:
|
|
54
|
+
|
|
55
|
+
| Parameter | Description |
|
|
56
|
+
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
57
|
+
| `resources` | An array of middleman site resources for the pages to be included in the ToC. |
|
|
58
|
+
| `current_page` | The resource object found in the [middleman current_page](https://www.rubydoc.info/gems/middleman-core/Middleman/TemplateContext#current_resource-instance_method). |
|
|
59
|
+
| `config` | Site settings defined in `/config/tech-docs.yaml`. |
|
|
60
|
+
| `current_page_html` | Optional html of the current page. Defaults to `nil`. |
|
|
61
|
+
| `include_child_resources` | Optional setting used to include child resources when creating a ToC. Defaults to `true`. |
|
|
62
|
+
Below is an example of using `multi_page_table_of_contents` in a layout file:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
<%
|
|
66
|
+
wrap_layout :core do
|
|
67
|
+
content_for :sidebar do
|
|
68
|
+
<%= multi_page_table_of_contents(sitemap.resources, current_page, config, yield, include_child_resources: true) %>
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
%>
|
|
72
|
+
```
|
|
73
|
+
This example will create a ToC containing the page title of each resource, as a heading. Each heading can be expanded to show nested headings to the depth defined in the site config. If `include_child_resources` is set to `true`, child resources will also be included.
|
|
74
|
+
|
|
20
75
|
## Developing locally
|
|
21
76
|
|
|
22
77
|
There are 2 ways to develop with this gem. You can see your changes on either:
|
|
@@ -19,10 +19,12 @@ footer_links:
|
|
|
19
19
|
Accessibility: /hidden-page.html
|
|
20
20
|
Hidden Page: /hidden-page.html
|
|
21
21
|
|
|
22
|
-
# Tracking
|
|
22
|
+
# Tracking IDs
|
|
23
|
+
# Google Analytics 4 using gtag.js (e.g G-XXXXXX)
|
|
23
24
|
ga4_tracking_id:
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
# Google Analytics 4 using Google Tag Manager (e.g GTM-XXXXXXXX)
|
|
26
|
+
ga4_gtm_tracking_id:
|
|
27
|
+
# Google Universal Analytics (e.g. UA-XXXX-Y)
|
|
26
28
|
ga_tracking_id:
|
|
27
29
|
|
|
28
30
|
# Enable multipage navigation in the sidebar
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
(function ($, Modules) {
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
Modules.CookieBanner = function () {
|
|
5
|
+
let $cookieBanner
|
|
6
|
+
|
|
7
|
+
this.start = function ($element) {
|
|
8
|
+
$cookieBanner = $element
|
|
9
|
+
|
|
10
|
+
if ($cookieBanner && getCookie('cookies_preferences_set') !== 'true') {
|
|
11
|
+
$('#cookie-banner__accept').on('click', acceptCookies)
|
|
12
|
+
$('#cookie-banner__reject').on('click', rejectCookies)
|
|
13
|
+
|
|
14
|
+
$cookieBanner.removeAttr('hidden')
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function acceptCookies () {
|
|
19
|
+
document.cookie = 'cookies_preferences_set=true'
|
|
20
|
+
document.cookie = 'cookies_policy={"usage":true}'
|
|
21
|
+
|
|
22
|
+
$cookieBanner.attr('hidden', 'hidden')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function rejectCookies () {
|
|
26
|
+
document.cookie = 'cookies_preferences_set=true'
|
|
27
|
+
document.cookie = 'cookies_policy={"usage":false}'
|
|
28
|
+
|
|
29
|
+
$cookieBanner.attr('hidden', 'hidden')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getCookie (name) {
|
|
33
|
+
return document.cookie
|
|
34
|
+
.split('; ')
|
|
35
|
+
.find(cookie => cookie.split('=')[0] === name)
|
|
36
|
+
?.split('=')[1]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
})(jQuery, window.GOVUK.Modules)
|
|
@@ -17,6 +17,7 @@ $govuk-new-link-styles: true;
|
|
|
17
17
|
@import "govuk/core/index";
|
|
18
18
|
@import "govuk/objects/index";
|
|
19
19
|
|
|
20
|
+
@import "govuk/components/cookie-banner/index";
|
|
20
21
|
@import "govuk/components/footer/index";
|
|
21
22
|
@import "govuk/components/header/index";
|
|
22
23
|
@import "govuk/components/inset-text/index";
|
|
@@ -35,12 +35,12 @@ module GovukTechDocs
|
|
|
35
35
|
.select { |r| r.path.end_with?(".html") && (r.parent.nil? || r.parent.url == "/") }
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
def multi_page_table_of_contents(resources, current_page, config, current_page_html = nil)
|
|
38
|
+
def multi_page_table_of_contents(resources, current_page, config, current_page_html = nil, include_child_resources: true)
|
|
39
39
|
resources = sort_resources_stably(
|
|
40
40
|
select_top_level_html_files(resources),
|
|
41
41
|
)
|
|
42
42
|
|
|
43
|
-
render_page_tree(resources, current_page, config, current_page_html)
|
|
43
|
+
render_page_tree(resources, current_page, config, current_page_html, include_child_resources:)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def list_items_from_headings(html, url: "", max_level: nil)
|
|
@@ -54,7 +54,7 @@ module GovukTechDocs
|
|
|
54
54
|
HeadingTreeRenderer.new(tree, max_level:).html
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
def render_page_tree(resources, current_page, config, current_page_html)
|
|
57
|
+
def render_page_tree(resources, current_page, config, current_page_html, include_child_resources: true)
|
|
58
58
|
resources = sort_resources_stably(resources)
|
|
59
59
|
|
|
60
60
|
output = "<ul>\n"
|
|
@@ -84,7 +84,7 @@ module GovukTechDocs
|
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
link_value = get_path_to_resource(config, resource, current_page)
|
|
87
|
-
if resource.children.any? && resource.url != home_url
|
|
87
|
+
if resource.children.any? && resource.url != home_url && include_child_resources
|
|
88
88
|
output += %(<li><a href="#{link_value}"><span>#{resource.data.title}</span></a>\n)
|
|
89
89
|
output += render_page_tree(resource.children, current_page, config, current_page_html)
|
|
90
90
|
output += "</li>\n"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<% if config[:tech_docs][:ga4_gtm_tracking_id].is_a?(String) && !config[:tech_docs][:ga4_gtm_tracking_id].empty? %>
|
|
2
|
+
<!-- Google Tag Manager -->
|
|
3
|
+
<script>
|
|
4
|
+
const cookies_policy_cookie = document.cookie
|
|
5
|
+
.split('; ')
|
|
6
|
+
.find(cookie => cookie.split('=')[0] === 'cookies_policy')
|
|
7
|
+
?.split('=')[1]
|
|
8
|
+
|
|
9
|
+
if (cookies_policy_cookie && JSON.parse(cookies_policy_cookie).usage) {
|
|
10
|
+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
|
11
|
+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
|
12
|
+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
|
13
|
+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
|
14
|
+
})(window,document,'script','dataLayer','<%= config[:tech_docs][:ga4_gtm_tracking_id] %>');
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
<!-- End Google Tag Manager -->
|
|
18
|
+
<% end %>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<% if config[:tech_docs][:ga4_gtm_tracking_id].is_a?(String) && !config[:tech_docs][:ga4_gtm_tracking_id].empty? %>
|
|
2
|
+
<div class="govuk-cookie-banner" data-nosnippet role="region" aria-label="Cookies on <%= config[:tech_docs][:service_name] %>" hidden="hidden" data-module="cookie-banner">
|
|
3
|
+
<div class="govuk-cookie-banner__message govuk-width-container">
|
|
4
|
+
<div class="govuk-grid-row">
|
|
5
|
+
<div class="govuk-grid-column-two-thirds">
|
|
6
|
+
<h2 class="govuk-cookie-banner__heading govuk-heading-m">
|
|
7
|
+
Cookies on <%= config[:tech_docs][:service_name] %>
|
|
8
|
+
</h2>
|
|
9
|
+
<div class="govuk-cookie-banner__content">
|
|
10
|
+
<p class="govuk-body">We’d like to use analytics cookies so we can understand how you use the service and make improvements.</p>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
<div class="govuk-button-group">
|
|
15
|
+
<button id="cookie-banner__accept" type="button" class="govuk-button" data-module="govuk-button">
|
|
16
|
+
Accept analytics cookies
|
|
17
|
+
</button>
|
|
18
|
+
<button id="cookie-banner__reject" type="button" class="govuk-button" data-module="govuk-button">
|
|
19
|
+
Reject analytics cookies
|
|
20
|
+
</button>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
<% end %>
|
data/lib/source/layouts/core.erb
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html lang="en" class="govuk-template <%= config[:tech_docs][:show_govuk_logo] ? 'govuk-template--rebranded ' : '' %>no-js">
|
|
3
3
|
<head>
|
|
4
|
-
<%= partial 'layouts/
|
|
4
|
+
<%= partial 'layouts/analytics_ga4_gtag' %>
|
|
5
|
+
<%= partial 'layouts/analytics_ga4_gtm' %>
|
|
5
6
|
|
|
6
7
|
<meta content="IE=edge" http-equiv="X-UA-Compatible">
|
|
7
8
|
<meta charset="utf-8">
|
|
@@ -51,6 +52,7 @@
|
|
|
51
52
|
<script>document.body.className += ' js-enabled' + ('noModule' in HTMLScriptElement.prototype ? ' govuk-frontend-supported' : '');</script>
|
|
52
53
|
|
|
53
54
|
<div class="app-pane">
|
|
55
|
+
<%= partial 'layouts/cookie_banner' %>
|
|
54
56
|
<div class="app-pane__header toc-open-disabled">
|
|
55
57
|
<a href="#content" class="govuk-skip-link" data-module="govuk-skip-link">Skip to main content</a>
|
|
56
58
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: govuk_tech_docs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.
|
|
4
|
+
version: 5.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Government Digital Service
|
|
@@ -417,6 +417,7 @@ files:
|
|
|
417
417
|
- lib/assets/javascripts/_govuk/modules.js
|
|
418
418
|
- lib/assets/javascripts/_modules/anchored-headings.js
|
|
419
419
|
- lib/assets/javascripts/_modules/collapsible-navigation.js
|
|
420
|
+
- lib/assets/javascripts/_modules/cookie-banner.js
|
|
420
421
|
- lib/assets/javascripts/_modules/in-page-navigation.js
|
|
421
422
|
- lib/assets/javascripts/_modules/navigation.js
|
|
422
423
|
- lib/assets/javascripts/_modules/page-expiry.js
|
|
@@ -481,7 +482,9 @@ files:
|
|
|
481
482
|
- lib/source/images/search-button.png
|
|
482
483
|
- lib/source/images/search-result-caret.svg
|
|
483
484
|
- lib/source/layouts/_analytics.erb
|
|
484
|
-
- lib/source/layouts/
|
|
485
|
+
- lib/source/layouts/_analytics_ga4_gtag.erb
|
|
486
|
+
- lib/source/layouts/_analytics_ga4_gtm.erb
|
|
487
|
+
- lib/source/layouts/_cookie_banner.erb
|
|
485
488
|
- lib/source/layouts/_footer.erb
|
|
486
489
|
- lib/source/layouts/_header.erb
|
|
487
490
|
- lib/source/layouts/_page_review.erb
|