govuk_tech_docs 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +35 -1
  5. data/README.md +1 -1
  6. data/Rakefile +5 -1
  7. data/docs/configuration.md +65 -33
  8. data/docs/core-layout.png +0 -0
  9. data/docs/expired-page.png +0 -0
  10. data/docs/frontmatter.md +113 -0
  11. data/docs/layout-layout.png +0 -0
  12. data/docs/not-expired-page.png +0 -0
  13. data/example/config.rb +6 -0
  14. data/example/config/tech-docs.yml +11 -1
  15. data/example/source/core-layout.html.md.erb +12 -0
  16. data/example/source/expired-page-with-owner.html.md +10 -0
  17. data/example/source/expired-page.html.md +9 -0
  18. data/example/source/headings.html.md +11 -0
  19. data/example/source/index.html.md.erb +2 -0
  20. data/example/source/not-expired-page.html.md +9 -0
  21. data/example/source/templates/proxy_template.html.md +8 -0
  22. data/govuk_tech_docs.gemspec +3 -0
  23. data/lib/assets/javascripts/_modules/page-expiry.js +15 -0
  24. data/lib/assets/javascripts/_start-modules.js +1 -0
  25. data/lib/assets/stylesheets/_core.scss +2 -0
  26. data/lib/assets/stylesheets/modules/_contribution-banner.scss +22 -0
  27. data/lib/assets/stylesheets/modules/_page-review.scss +34 -0
  28. data/lib/govuk_tech_docs.rb +28 -0
  29. data/lib/govuk_tech_docs/contribution_banner.rb +52 -0
  30. data/lib/govuk_tech_docs/meta_tags.rb +67 -0
  31. data/lib/govuk_tech_docs/page_review.rb +36 -0
  32. data/lib/govuk_tech_docs/pages.rb +31 -0
  33. data/lib/govuk_tech_docs/redirects.rb +39 -0
  34. data/lib/govuk_tech_docs/table_of_contents/helpers.rb +8 -6
  35. data/lib/govuk_tech_docs/version.rb +1 -1
  36. data/lib/source/api/pages.json.erb +1 -0
  37. data/lib/source/layouts/_page_review.erb +18 -0
  38. data/lib/source/layouts/core.erb +15 -3
  39. metadata +68 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12cf51405932e8a1b1963c5d8141de6c474fd1e0
4
- data.tar.gz: 4c71d9bcfe45396525f7acc05d7d157c15f483be
3
+ metadata.gz: f5e6745794ab18eb8c628384b868c10edaecfe5a
4
+ data.tar.gz: 6d93cae1fd2a09c0addc299fa7b43bceecd6208f
5
5
  SHA512:
6
- metadata.gz: ce6a2aa3153afe322cd76568389fac64338e5772e45cb2459230b4b2bc2021fdcf6af8237d46a1a4030cb72a357c11020e075c866da5c14a58d2b55fb4c623a6
7
- data.tar.gz: 573e40e4ccfd26d6f48e73458db1d26581cdcb0d65fadfd114680a2c13a82fd5edc233203ead0608cb534d1232f6253cc01c23095cdac33c3a885dbc1ef499dc
6
+ metadata.gz: c9a3f2c71458829e25e27d0cf79cea3d19e125bafb8e3c2c28827312e2a6d6a4d28cd9b0e01aa999f051f3b0881a081d1b14dbe250e47d6d055ba48765ec1e02
7
+ data.tar.gz: b77c6acc475897e7423b3067abcc41f339539bd6cd5b4eb85c219fafc6a0cf8de60eec81ce55df3e7469c6a2fecedd0088261edf0c003c860f3935cd03905233
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ Layout/IndentHeredoc:
2
+ Enabled: false
3
+
4
+ Naming/HeredocDelimiterNaming:
5
+ Enabled: false
6
+
7
+ Lint/NestedMethodDefinition:
8
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.2
data/CHANGELOG.md CHANGED
@@ -1,11 +1,45 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### New feature: redirects
6
+
7
+ You can now specify redirects in the frontmatter and `config/tech-docs.yml`.
8
+
9
+ You can use this when you change a page URL.
10
+
11
+ More info:
12
+
13
+ - https://github.com/alphagov/tech-docs-gem/blob/master/docs/configuration.md#redirects
14
+ - https://github.com/alphagov/tech-docs-gem/blob/master/docs/frontmatter.md#old_paths
15
+
16
+ ### New feature: contribution banner
17
+
18
+ You can now show a block at the bottom of the page that links to
19
+ the page source on GitHub, so readers can easily contribute back to the documentation.
20
+
21
+ https://github.com/alphagov/tech-docs-gem/blob/master/docs/configuration.md#show_contribution_banner
22
+
23
+ ### New feature: page review system
24
+
25
+ An optional page review system to make sure documentation stays up to date.
26
+
27
+ More info:
28
+
29
+ - https://github.com/alphagov/tech-docs-gem/blob/master/docs/frontmatter.md#last_reviewed_on
30
+ - https://github.com/alphagov/tech-docs-gem/blob/master/docs/frontmatter.md#owner_slack
31
+
32
+
33
+ ### Better meta tags
34
+
35
+ Pages now include better meta tags for search engines, Twitter, Facebook and Slack to pick up.
36
+
3
37
  ## 1.1.0
4
38
 
5
39
  You can now specify `google_site_verification` in tech-docs.yml. You can use
6
40
  this to verify your site in Google Webmaster tools.
7
41
 
8
- https://github.com/alphagov/tech-docs-gem/blob/master/docs/configuration.md#google_site_verification
42
+ https://github.com/alphagov/tech-docs-gem/blob/master/docs/configuration.md#google_site_verification
9
43
 
10
44
  ## 1.0.0
11
45
 
data/README.md CHANGED
@@ -42,6 +42,6 @@ Or, on the command line, run `bundle exec rake jasmine:ci`.
42
42
 
43
43
  ## License
44
44
 
45
- The gem is available as open source under the terms of the [MIT License](LICENSE.md).
45
+ The gem is available as open source under the terms of the [MIT License](LICENSE).
46
46
 
47
47
  [jas]: https://jasmine.github.io/
data/Rakefile CHANGED
@@ -6,4 +6,8 @@ RSpec::Core::RakeTask.new(:spec)
6
6
 
7
7
  load 'jasmine/tasks/jasmine.rake'
8
8
 
9
- task default: ['spec', 'jasmine:ci']
9
+ task :lint do
10
+ sh "govuk-lint-ruby example lib spec Rakefile"
11
+ end
12
+
13
+ task default: ['lint', 'spec', 'jasmine:ci']
@@ -4,44 +4,57 @@ You can configure the site using `config/tech-docs.yml`. [See the PaaS tech docs
4
4
 
5
5
  These are all the available options:
6
6
 
7
- ## `host`
8
-
9
- Host to use for canonical URL generation (without trailing slash).
7
+ ## `ga_tracking_id`
10
8
 
11
- Example:
9
+ Tracking ID from Google Analytics
12
10
 
13
11
  ```yaml
14
- host: https://docs.cloud.service.gov.uk
12
+ ga_tracking_id: UA-XXXX-Y
15
13
  ```
16
14
 
17
- ## `show_govuk_logo`
15
+ ## `github_repo`
18
16
 
19
- Whether to show the GOV.UK crown logo.
17
+ Your repository. Required if [show_contribution_banner](#show-contribution-banner) is true.
20
18
 
21
- default: `true`
19
+ ```yaml
20
+ github_repo: alphagov/example-repo
21
+ ```
22
+
23
+ ## `google_site_verification`
24
+
25
+ Adds a [Google Site Verification code](https://support.google.com/webmasters/answer/35179?hl=en) to the meta tags.
22
26
 
23
27
  ```yaml
24
- show_govuk_logo: true
28
+ google_site_verification: TvDTuyvdstyusadrCSDrctyd
25
29
  ```
26
30
 
27
- ## `service_name`
31
+ ## `header_links`
28
32
 
29
- The service name in the header.
33
+ Right hand side navigation.
30
34
 
31
35
  Example:
32
36
 
33
37
  ```yaml
34
- service_name: "Platform as a Service"
38
+ header_links:
39
+ Documentation: /
35
40
  ```
36
41
 
37
- ## `service_link`
42
+ ## `host`
38
43
 
39
- What the service name in the header links to.
44
+ Host to use for canonical URL generation (without trailing slash).
40
45
 
41
- default: '/'
46
+ Example:
42
47
 
43
48
  ```yaml
44
- service_link: "/"
49
+ host: https://docs.cloud.service.gov.uk
50
+ ```
51
+
52
+ ## `max_toc_heading_level`
53
+
54
+ Table of contents depth – how many levels to include in the table of contents. If your ToC is too long, reduce this number and we'll only show higher-level headings.
55
+
56
+ ```yaml
57
+ max_toc_heading_level: 6
45
58
  ```
46
59
 
47
60
  ## `phase`
@@ -50,45 +63,64 @@ service_link: "/"
50
63
  phase: "Beta"
51
64
  ```
52
65
 
53
- ## `header_links`
66
+ ## `prevent_indexing`
54
67
 
55
- Right hand side navigation.
68
+ Prevent robots from indexing (e.g. whilst in development)
56
69
 
57
- Example:
70
+ ```yaml
71
+ prevent_indexing: false
72
+ ```
73
+
74
+ ## `redirects`
75
+
76
+ A list of redirects, from old to new location. Use this to set up external
77
+ redirects or if [setting `old_paths` in the frontmatter](docs/frontmatter.md#old_paths) doesn't work.
58
78
 
59
79
  ```yaml
60
- header_links:
61
- Documentation: /
80
+ redirects:
81
+ /old-page.html: https://example.org/something-else.html
82
+ /another/old-page.html: /another/new-page.html
62
83
  ```
63
84
 
64
- ## `prevent_indexing`
85
+ ## `service_name`
65
86
 
66
- Prevent robots from indexing (e.g. whilst in development)
87
+ The service name in the header.
88
+
89
+ Example:
67
90
 
68
91
  ```yaml
69
- prevent_indexing: false
92
+ service_name: "Platform as a Service"
70
93
  ```
71
94
 
72
- ## `ga_tracking_id`
95
+ ## `service_link`
73
96
 
74
- Tracking ID from Google Analytics
97
+ What the service name in the header links to.
98
+
99
+ default: '/'
75
100
 
76
101
  ```yaml
77
- ga_tracking_id: UA-XXXX-Y
102
+ service_link: "/"
78
103
  ```
79
104
 
80
- ## `max_toc_heading_level`
105
+ ## `show_contribution_banner`
81
106
 
82
- Table of contents depth how many levels to include in the table of contents. If your ToC is too long, reduce this number and we'll only show higher-level headings.
107
+ Show a block at the bottom of the page that links to the page source, so readers
108
+ can easily contribute back to the documentation. If turned on [github_repo](#github-repo) is
109
+ required.
110
+
111
+ Off by default.
83
112
 
84
113
  ```yaml
85
- max_toc_heading_level: 6
114
+ show_contribution_banner: true
115
+ github_repo: alphagov/example-repo
86
116
  ```
87
117
 
88
- ## `google_site_verification`
118
+ ## `show_govuk_logo`
89
119
 
90
- Adds a [Google Site Verification code](https://support.google.com/webmasters/answer/35179?hl=en) to the meta tags.
120
+ Whether to show the GOV.UK crown logo.
121
+
122
+ default: `true`
91
123
 
92
124
  ```yaml
93
- google_site_verification: TvDTuyvdstyusadrCSDrctyd
125
+ show_govuk_logo: true
94
126
  ```
Binary file
Binary file
@@ -0,0 +1,113 @@
1
+ # Available frontmatter
2
+
3
+ "Frontmatter" allows page-specific variables to be included at the top of a template using YAML. For a general introduction on frontmatter, see the [Middleman frontmatter docs][mm].
4
+
5
+ ## `last_reviewed_on` and `review_in`
6
+
7
+ These attributes determine the date when the page needs to be reviewed next.
8
+
9
+ If the page doesn't need to be reviewed, we show a blue box with the last-reviewed date, when it needs review again, and the owner.
10
+
11
+ ![](not-expired-page.png)
12
+
13
+ If the page needs to be reviewed, we show a red box saying the page might not be accurate.
14
+
15
+ ![](expired-page.png)
16
+
17
+ Example:
18
+
19
+ ```yaml
20
+ ---
21
+ last_reviewed_on: 2018-01-18
22
+ review_in: 6 weeks
23
+ ---
24
+ ```
25
+
26
+ You can use this in combination with [owner_slack](#owner-slack) to set an owner for the page.
27
+
28
+ ## `layout`
29
+
30
+ The layout of the page.
31
+
32
+ ```yaml
33
+ ---
34
+ layout: core
35
+ ---
36
+ ```
37
+
38
+ There are 2 available page layouts.
39
+
40
+ ### The `layout` layout (default)
41
+
42
+ By default, pages will use the `layout` layout. This layout will parse the page and generate a sidebar with a table of contents consisting of each `h2`, `h3`, `h4` heading.
43
+
44
+ ```md
45
+ ---
46
+ layout: layout
47
+ ---
48
+
49
+ # The title
50
+
51
+ ## A subheader
52
+
53
+ ### A h3 subheader
54
+
55
+ ## Another subheader
56
+ ```
57
+
58
+ Will generate a page with the headings from the content in the sidebar.
59
+
60
+ ![](layout-layout.png)
61
+
62
+ ### `core` layout
63
+
64
+ If you want more control about the layout, use `core` layout. This allows you to specify the sidebar manually with a `content_for` block.
65
+
66
+ ```rb
67
+ ---
68
+ layout: core
69
+ ---
70
+
71
+ <% content_for :sidebar do %>
72
+ You can put anything in the sidebar.
73
+ <% end %>
74
+
75
+ This page has a configurable sidebar that is independent of the content.
76
+ ```
77
+
78
+ ![](core-layout.png)
79
+
80
+ ## `old_paths`
81
+
82
+ Any paths of pages that should redirect to this page.
83
+
84
+ Example:
85
+
86
+ ```yaml
87
+ ---
88
+ old_paths:
89
+ - /some-old-page.html
90
+ ---
91
+ ```
92
+
93
+ ## `owner_slack`
94
+
95
+ The Slack username or channel of the page owner. This can be used to appoint an individual or team as responsible for keeping the page up to date.
96
+
97
+ ```yaml
98
+ ---
99
+ owner_slack: "#operations-teams"
100
+ ---
101
+ ```
102
+
103
+ ## `title`
104
+
105
+ The browser title of the page.
106
+
107
+ ```yaml
108
+ ---
109
+ title: My beautiful page
110
+ ---
111
+ ```
112
+
113
+ [mm]: https://middlemanapp.com/basics/frontmatter
Binary file
Binary file
data/example/config.rb CHANGED
@@ -1,3 +1,9 @@
1
1
  require 'govuk_tech_docs'
2
2
 
3
3
  GovukTechDocs.configure(self)
4
+
5
+ ignore 'templates/*'
6
+
7
+ proxy '/a-proxied-page.html', 'templates/proxy_template.html', locals: {
8
+ title: 'I am a title'
9
+ }
@@ -1,5 +1,5 @@
1
1
  # Host to use for canonical URL generation (without trailing slash)
2
- host:
2
+ host: https://docs.example.com
3
3
 
4
4
  # Header-related options
5
5
  show_govuk_logo: true
@@ -10,6 +10,9 @@ phase: Beta
10
10
  # Links to show on right-hand-side of header
11
11
  header_links:
12
12
  Documentation: /
13
+ Expired page: /expired-page.html
14
+ Expired with owner: /expired-page-with-owner.html
15
+ Not expired page: /not-expired-page.html
13
16
 
14
17
  # Tracking ID from Google Analytics (e.g. UA-XXXX-Y)
15
18
  ga_tracking_id:
@@ -23,3 +26,10 @@ max_toc_heading_level: 6
23
26
  prevent_indexing: false
24
27
 
25
28
  google_site_verification: dstbao8TVS^DRVDS&rv76
29
+
30
+ show_contribution_banner: true
31
+
32
+ github_repo: alphagov/example-repo
33
+
34
+ redirects:
35
+ /something/old.html: /index.html
@@ -0,0 +1,12 @@
1
+ ---
2
+ layout: core
3
+ ---
4
+
5
+ <% content_for :sidebar do %>
6
+ You can put anything in the sidebar.
7
+ <% end %>
8
+
9
+
10
+ # Hello!
11
+
12
+ This page has a configurable sidebar that is independent of the content.
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: This is an expired page
3
+ last_reviewed_on: 1983-01-18
4
+ review_in: 18 years
5
+ owner_slack: '@foo'
6
+ ---
7
+
8
+ # This is an expired page with owner
9
+
10
+ See the banner on this page.
@@ -0,0 +1,9 @@
1
+ ---
2
+ title: This is an expired page
3
+ last_reviewed_on: 1983-01-18
4
+ review_in: 18 years
5
+ ---
6
+
7
+ # This is an expired page
8
+
9
+ See the banner on this page.
@@ -0,0 +1,11 @@
1
+ ---
2
+ layout: layout
3
+ ---
4
+
5
+ # The title
6
+
7
+ ## A subheader
8
+
9
+ ### A h3 subheader
10
+
11
+ ## Another subheader
@@ -1,5 +1,7 @@
1
1
  ---
2
2
  title: GOV.UK Documentation Example
3
+ old_paths:
4
+ - /something/old-as-well.html
3
5
  ---
4
6
 
5
7
  # Hello, World!
@@ -0,0 +1,9 @@
1
+ ---
2
+ title: This is an expired page
3
+ last_reviewed_on: 2050-01-18
4
+ review_in: 1 month
5
+ ---
6
+
7
+ # This is not an expired page
8
+
9
+ See the banner on this page.
@@ -0,0 +1,8 @@
1
+ ---
2
+ title: Proxied page
3
+ source_url: http://example.org/source.md
4
+ ---
5
+
6
+ # Proxied page
7
+
8
+ This is a proxied page.
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
+ spec.add_dependency "activesupport"
25
+ spec.add_dependency "chronic", "~> 0.10.2"
24
26
  spec.add_dependency "middleman", "~> 4.0"
25
27
  spec.add_dependency "middleman-autoprefixer", "~> 2.7.0"
26
28
  spec.add_dependency "middleman-compass", ">= 4.0.0"
@@ -33,6 +35,7 @@ Gem::Specification.new do |spec|
33
35
  spec.add_development_dependency "bundler", "~> 1.15"
34
36
  spec.add_development_dependency "rake", "~> 10.0"
35
37
  spec.add_development_dependency "capybara", "~> 2.18.0"
38
+ spec.add_development_dependency "govuk-lint", "~> 3.7.0"
36
39
  spec.add_development_dependency "jasmine", "~> 3.1.0"
37
40
  spec.add_development_dependency "rspec", "~> 3.7.0"
38
41
  end
@@ -0,0 +1,15 @@
1
+ (function($, Modules) {
2
+ 'use strict';
3
+
4
+ Modules.PageExpiry = function PageExpiry() {
5
+ this.start = function start($element) {
6
+ var rawDate = $element.data('last-reviewed-on');
7
+ var isExpired = Date.parse(rawDate) < new Date();
8
+
9
+ if (isExpired) {
10
+ $element.find('.page-expiry--not-expired').hide(0);
11
+ $element.find('.page-expiry--expired').show(0);
12
+ }
13
+ };
14
+ };
15
+ })(jQuery, window.GOVUK.Modules);
@@ -2,6 +2,7 @@
2
2
  //= require _modules/anchored-headings
3
3
  //= require _modules/in-page-navigation
4
4
  //= require _modules/navigation
5
+ //= require _modules/page-expiry
5
6
  //= require _modules/table-of-contents
6
7
 
7
8
  $(document).ready(function() {
@@ -24,8 +24,10 @@ $desktop-breakpoint: 992px !default;
24
24
  @import "modules/footer";
25
25
  @import "modules/govuk-logo";
26
26
  @import "modules/header";
27
+ @import "modules/page-review";
27
28
  @import "modules/phase-banner";
28
29
  @import "modules/skip-link";
30
+ @import "modules/contribution-banner";
29
31
  @import "modules/technical-documentation";
30
32
  @import "modules/toc";
31
33
 
@@ -0,0 +1,22 @@
1
+ .contribution-banner {
2
+ padding: 0;
3
+ max-width: 40em;
4
+ margin-top: $gutter * 2;
5
+ margin-left: $gutter-half;
6
+ margin-right: $gutter-half;
7
+
8
+ @include media(tablet) {
9
+ margin-left: $gutter + 2px;
10
+ margin-right: $gutter + 2px;
11
+ }
12
+
13
+ a {
14
+ margin-right: $gutter-half;
15
+ }
16
+
17
+ li {
18
+ display: inline-block;
19
+ list-style: none;
20
+ margin: 2px 0;
21
+ }
22
+ }
@@ -0,0 +1,34 @@
1
+ .page-expiry--not-expired {
2
+ padding: $gutter-half;
3
+ margin-top: $gutter;
4
+ margin-bottom: $gutter;
5
+ background-color: $govuk-blue;
6
+ color: $page-colour;
7
+
8
+ @include media(tablet) {
9
+ padding: $gutter;
10
+ }
11
+
12
+ a:link,
13
+ a:visited {
14
+ color: inherit;
15
+ }
16
+
17
+ a:hover {
18
+ color: $link-hover-colour;
19
+ }
20
+
21
+ a:active {
22
+ color: $link-active-colour;
23
+ }
24
+ }
25
+
26
+ .page-expiry--expired {
27
+ display: none;
28
+
29
+ padding: $gutter-half;
30
+ margin-top: $gutter * 2;
31
+ background-color: $error-background;
32
+ border: 1px solid $error-colour;
33
+ color: $error-colour;
34
+ }
@@ -7,8 +7,15 @@ require 'middleman-livereload'
7
7
  require 'middleman-syntax'
8
8
 
9
9
  require 'nokogiri'
10
+ require 'chronic'
11
+ require 'active_support/all'
10
12
 
13
+ require 'govuk_tech_docs/redirects'
11
14
  require 'govuk_tech_docs/table_of_contents/helpers'
15
+ require 'govuk_tech_docs/contribution_banner'
16
+ require 'govuk_tech_docs/meta_tags'
17
+ require 'govuk_tech_docs/page_review'
18
+ require 'govuk_tech_docs/pages'
12
19
  require 'govuk_tech_docs/tech_docs_html_renderer'
13
20
  require 'govuk_tech_docs/unique_identifier_extension'
14
21
  require 'govuk_tech_docs/unique_identifier_generator'
@@ -45,10 +52,31 @@ module GovukTechDocs
45
52
 
46
53
  context.helpers do
47
54
  include GovukTechDocs::TableOfContents::Helpers
55
+ include GovukTechDocs::ContributionBanner
56
+
57
+ def meta_tags
58
+ @meta_tags ||= GovukTechDocs::MetaTags.new(config, current_page)
59
+ end
60
+
61
+ def current_page_review
62
+ @current_page_review ||= GovukTechDocs::PageReview.new(current_page)
63
+ end
64
+
65
+ def format_date(date)
66
+ date.strftime('%-e %B %Y')
67
+ end
48
68
  end
49
69
 
50
70
  context.page '/*.xml', layout: false
51
71
  context.page '/*.json', layout: false
52
72
  context.page '/*.txt', layout: false
73
+
74
+ context.ready do
75
+ redirects = GovukTechDocs::Redirects.new(context).redirects
76
+
77
+ redirects.each do |from, to|
78
+ context.redirect from, to
79
+ end
80
+ end
53
81
  end
54
82
  end
@@ -0,0 +1,52 @@
1
+ module GovukTechDocs
2
+ # Helper included
3
+ module ContributionBanner
4
+ def source_urls
5
+ SourceUrls.new(current_page, config)
6
+ end
7
+ end
8
+
9
+ class SourceUrls
10
+ attr_reader :current_page, :config
11
+
12
+ def initialize(current_page, config)
13
+ @current_page = current_page
14
+ @config = config
15
+ end
16
+
17
+ def view_source_url
18
+ override_from_page || source_from_yaml_file || source_from_file
19
+ end
20
+
21
+ def report_issue_url
22
+ "#{repo_url}/issues/new?labels=bug&title=Re: '#{current_page.data.title}'&body=Problem with '#{current_page.data.title}' (#{config[:tech_docs][:host]}#{current_page.url})"
23
+ end
24
+
25
+ def repo_url
26
+ "https://github.com/#{config[:tech_docs][:github_repo]}"
27
+ end
28
+
29
+ private
30
+
31
+ # If a `page` local exists, see if it has a `source_url`. This is used by the
32
+ # pages that are created by the proxy system because they can't use frontmatter
33
+ def override_from_page
34
+ locals.key?(:page) ? locals[:page].try(:source_url) : false
35
+ end
36
+
37
+ # In the frontmatter we can specify a `source_url`. Use this if the actual
38
+ # source of the page is in another GitHub repo.
39
+ def source_from_yaml_file
40
+ current_page.data.source_url
41
+ end
42
+
43
+ # As the last fallback link to the source file in this repository.
44
+ def source_from_file
45
+ "#{repo_url}/blob/master/source/#{current_page.file_descriptor[:relative_path]}"
46
+ end
47
+
48
+ def locals
49
+ current_page.metadata[:locals]
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,67 @@
1
+ module GovukTechDocs
2
+ class MetaTags
3
+ def initialize(config, current_page)
4
+ @config = config
5
+ @current_page = current_page
6
+ end
7
+
8
+ def tags
9
+ all_tags = {
10
+ 'description' => page_description,
11
+ 'og:description' => page_description,
12
+ 'og:image' => page_image,
13
+ 'og:site_name' => site_name,
14
+ 'og:title' => page_title,
15
+ 'og:type' => 'object',
16
+ 'og:url' => canonical_url,
17
+ 'twitter:card' => 'summary',
18
+ 'twitter:domain' => URI.parse(host).host,
19
+ 'twitter:image' => page_image,
20
+ 'twitter:title' => browser_title,
21
+ 'twitter:url' => canonical_url,
22
+ }
23
+
24
+ Hash[all_tags.select { |_k, v| v }]
25
+ end
26
+
27
+ def browser_title
28
+ [page_title, site_name].select(&:present?).uniq.join(' | ')
29
+ end
30
+
31
+ def canonical_url
32
+ "#{host}#{current_page.url}"
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :config, :current_page
38
+
39
+ def page_image
40
+ "#{host}/images/govuk-large.png"
41
+ end
42
+
43
+ def site_name
44
+ config[:tech_docs][:service_name]
45
+ end
46
+
47
+ def page_description
48
+ locals[:description] || frontmatter.description
49
+ end
50
+
51
+ def page_title
52
+ locals[:title] || frontmatter.title
53
+ end
54
+
55
+ def host
56
+ config[:tech_docs][:host]
57
+ end
58
+
59
+ def locals
60
+ current_page.metadata[:locals]
61
+ end
62
+
63
+ def frontmatter
64
+ current_page.data
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,36 @@
1
+ module GovukTechDocs
2
+ class PageReview
3
+ attr_reader :page
4
+
5
+ def initialize(page)
6
+ @page = page
7
+ end
8
+
9
+ def review_by
10
+ return unless last_reviewed_on
11
+
12
+ @review_by ||= Chronic.parse(
13
+ "in #{page.data.review_in}",
14
+ now: last_reviewed_on.to_time
15
+ ).to_date
16
+ end
17
+
18
+ def under_review?
19
+ page.data.review_in.present?
20
+ end
21
+
22
+ def last_reviewed_on
23
+ page.data.last_reviewed_on
24
+ end
25
+
26
+ def owner_slack
27
+ page.data.owner_slack
28
+ end
29
+
30
+ def owner_slack_url
31
+ # Slack URLs don't have the # (channels) or @ (usernames)
32
+ slack_identifier = owner_slack.to_s.delete('#').delete('@')
33
+ "https://govuk.slack.com/messages/#{slack_identifier}"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,31 @@
1
+ module GovukTechDocs
2
+ class Pages
3
+ attr_reader :sitemap
4
+
5
+ def initialize(sitemap, config)
6
+ @sitemap = sitemap
7
+ @config = config
8
+ end
9
+
10
+ def to_json
11
+ as_json.to_json
12
+ end
13
+
14
+ private
15
+
16
+ def as_json
17
+ pages.map do |page|
18
+ {
19
+ title: page.data.title,
20
+ url: "#{@config[:tech_docs][:host]}#{page.url}",
21
+ review_by: PageReview.new(page).review_by,
22
+ owner_slack: page.data.owner_slack,
23
+ }
24
+ end
25
+ end
26
+
27
+ def pages
28
+ sitemap.resources.select { |page| page.url.end_with?('.html') && page.data.title }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,39 @@
1
+ module GovukTechDocs
2
+ class Redirects
3
+ LEADING_SLASH = %r[\A\/]
4
+
5
+ def initialize(context)
6
+ @context = context
7
+ end
8
+
9
+ def redirects
10
+ all_redirects = redirects_from_config + redirects_from_frontmatter
11
+
12
+ all_redirects.map do |from, to|
13
+ # Middleman needs paths without leading slashes
14
+ [from.sub(LEADING_SLASH, ''), to: to.sub(LEADING_SLASH, '')]
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :context
21
+
22
+ def redirects_from_config
23
+ context.config[:tech_docs][:redirects].to_a
24
+ end
25
+
26
+ def redirects_from_frontmatter
27
+ reds = []
28
+ context.sitemap.resources.each do |page|
29
+ next unless page.data.old_paths
30
+
31
+ page.data.old_paths.each do |old_path|
32
+ reds << [old_path, page.path]
33
+ end
34
+ end
35
+
36
+ reds
37
+ end
38
+ end
39
+ end
@@ -8,12 +8,14 @@ module GovukTechDocs
8
8
  module TableOfContents
9
9
  module Helpers
10
10
  def table_of_contents(html, max_level: nil)
11
- HeadingTreeRenderer.new(
12
- HeadingTreeBuilder.new(
13
- HeadingsBuilder.new(html).headings
14
- ).tree,
15
- max_level: max_level
16
- ).html
11
+ headings = HeadingsBuilder.new(html).headings
12
+
13
+ if headings.none? { |heading| heading.size == 1 }
14
+ raise "No H1 tag found. You have to at least add one H1 heading to the page."
15
+ end
16
+
17
+ tree = HeadingTreeBuilder.new(headings).tree
18
+ HeadingTreeRenderer.new(tree, max_level: max_level).html
17
19
  end
18
20
  end
19
21
  end
@@ -1,3 +1,3 @@
1
1
  module GovukTechDocs
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0".freeze
3
3
  end
@@ -0,0 +1 @@
1
+ <%= GovukTechDocs::Pages.new(sitemap, config).to_json %>
@@ -0,0 +1,18 @@
1
+ <% if current_page_review.under_review? %>
2
+ <div data-module='page-expiry' data-last-reviewed-on="<%= current_page_review.review_by %>">
3
+ <div class='page-expiry--not-expired'>
4
+ This page was last reviewed on <%= format_date current_page_review.last_reviewed_on %>.
5
+
6
+ It needs to be reviewed again on <%= format_date current_page_review.review_by %>
7
+ <% if current_page_review.owner_slack %>
8
+ by the page owner <%= link_to current_page_review.owner_slack, current_page_review.owner_slack_url %>
9
+ <% end %>.
10
+ </div>
11
+
12
+ <div class='page-expiry--expired'>
13
+ This page was set to be reviewed before <%= format_date current_page_review.review_by %><% if current_page_review.owner_slack %>
14
+ by the page owner <%= link_to current_page_review.owner_slack, current_page_review.owner_slack_url %><% end %>.
15
+ This might mean the content is out of date.
16
+ </div>
17
+ </div>
18
+ <% end %>
@@ -8,13 +8,12 @@
8
8
  <meta name="robots" content="noindex">
9
9
  <% end %>
10
10
 
11
- <!-- Use title if it's in the page YAML frontmatter -->
12
- <title><%= current_page.data.title || "GOV.UK Documentation" %></title>
11
+ <title><%= meta_tags.browser_title %></title>
13
12
 
14
13
  <!--[if gt IE 8]><!--><%= stylesheet_link_tag :screen, media: 'screen' %><!--<![endif]-->
15
14
  <!--[if lte IE 8]><%= stylesheet_link_tag 'screen-old-ie', media: 'screen' %><![endif]-->
16
15
 
17
- <link rel="canonical" href="<%= config[:tech_docs][:host] %><%= current_page.url %>">
16
+ <link rel="canonical" href="<%= meta_tags.canonical_url %>">
18
17
 
19
18
  <% if config[:tech_docs][:google_site_verification] %>
20
19
  <meta name="google-site-verification" content="<%= config[:tech_docs][:google_site_verification] %>" />
@@ -22,6 +21,10 @@
22
21
 
23
22
  <%= stylesheet_link_tag :print, media: 'print' %>
24
23
  <%= javascript_include_tag :application %>
24
+
25
+ <% meta_tags.tags.each do |property, content| %>
26
+ <%= tag :meta, property: property, content: content %>
27
+ <% end %>
25
28
  </head>
26
29
 
27
30
  <body>
@@ -51,8 +54,17 @@
51
54
  <div class="app-pane__content toc-open-disabled">
52
55
  <main id="content" class="technical-documentation" data-module="anchored-headings">
53
56
  <%= yield %>
57
+ <%= partial "layouts/page_review" %>
54
58
  </main>
55
59
 
60
+ <% if config[:tech_docs][:show_contribution_banner] %>
61
+ <ul class="contribution-banner">
62
+ <li><%= link_to "View source", source_urls.view_source_url %></li>
63
+ <li><%= link_to "Report problem", source_urls.report_issue_url %></li>
64
+ <li><%= link_to "GitHub Repo", source_urls.repo_url %></li>
65
+ </ul>
66
+ <% end %>
67
+
56
68
  <%= partial "layouts/footer" %>
57
69
  </div>
58
70
  </div>
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_tech_docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2018-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chronic
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.2
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: middleman
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +192,20 @@ dependencies:
164
192
  - - "~>"
165
193
  - !ruby/object:Gem::Version
166
194
  version: 2.18.0
195
+ - !ruby/object:Gem::Dependency
196
+ name: govuk-lint
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 3.7.0
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 3.7.0
167
209
  - !ruby/object:Gem::Dependency
168
210
  name: jasmine
169
211
  requirement: !ruby/object:Gem::Requirement
@@ -203,6 +245,8 @@ files:
203
245
  - ".editorconfig"
204
246
  - ".gitignore"
205
247
  - ".rspec"
248
+ - ".rubocop.yml"
249
+ - ".ruby-version"
206
250
  - ".travis.yml"
207
251
  - CHANGELOG.md
208
252
  - Gemfile
@@ -210,21 +254,33 @@ files:
210
254
  - README.md
211
255
  - Rakefile
212
256
  - docs/configuration.md
257
+ - docs/core-layout.png
258
+ - docs/expired-page.png
259
+ - docs/frontmatter.md
260
+ - docs/layout-layout.png
261
+ - docs/not-expired-page.png
213
262
  - example/.ruby-version
214
263
  - example/Gemfile
215
264
  - example/config.rb
216
265
  - example/config/tech-docs.yml
266
+ - example/source/core-layout.html.md.erb
267
+ - example/source/expired-page-with-owner.html.md
268
+ - example/source/expired-page.html.md
269
+ - example/source/headings.html.md
217
270
  - example/source/index.html.md.erb
218
271
  - example/source/javascripts/application.js
272
+ - example/source/not-expired-page.html.md
219
273
  - example/source/stylesheets/print.css.scss
220
274
  - example/source/stylesheets/screen-old-ie.css.scss
221
275
  - example/source/stylesheets/screen.css.scss
276
+ - example/source/templates/proxy_template.html.md
222
277
  - govuk_tech_docs.gemspec
223
278
  - lib/assets/javascripts/_analytics.js
224
279
  - lib/assets/javascripts/_govuk/modules.js
225
280
  - lib/assets/javascripts/_modules/anchored-headings.js
226
281
  - lib/assets/javascripts/_modules/in-page-navigation.js
227
282
  - lib/assets/javascripts/_modules/navigation.js
283
+ - lib/assets/javascripts/_modules/page-expiry.js
228
284
  - lib/assets/javascripts/_modules/table-of-contents.js
229
285
  - lib/assets/javascripts/_start-modules.js
230
286
  - lib/assets/javascripts/_vendor/fixedsticky.js
@@ -256,9 +312,11 @@ files:
256
312
  - lib/assets/stylesheets/govuk_frontend_toolkit/design-patterns/_media-player.scss
257
313
  - lib/assets/stylesheets/modules/_anchored-heading.scss
258
314
  - lib/assets/stylesheets/modules/_app-pane.scss
315
+ - lib/assets/stylesheets/modules/_contribution-banner.scss
259
316
  - lib/assets/stylesheets/modules/_footer.scss
260
317
  - lib/assets/stylesheets/modules/_govuk-logo.scss
261
318
  - lib/assets/stylesheets/modules/_header.scss
319
+ - lib/assets/stylesheets/modules/_page-review.scss
262
320
  - lib/assets/stylesheets/modules/_phase-banner.scss
263
321
  - lib/assets/stylesheets/modules/_skip-link.scss
264
322
  - lib/assets/stylesheets/modules/_technical-documentation.scss
@@ -268,6 +326,11 @@ files:
268
326
  - lib/assets/stylesheets/utilities/_printable.scss
269
327
  - lib/assets/stylesheets/vendor/_fixedsticky.scss
270
328
  - lib/govuk_tech_docs.rb
329
+ - lib/govuk_tech_docs/contribution_banner.rb
330
+ - lib/govuk_tech_docs/meta_tags.rb
331
+ - lib/govuk_tech_docs/page_review.rb
332
+ - lib/govuk_tech_docs/pages.rb
333
+ - lib/govuk_tech_docs/redirects.rb
271
334
  - lib/govuk_tech_docs/table_of_contents/heading.rb
272
335
  - lib/govuk_tech_docs/table_of_contents/heading_tree.rb
273
336
  - lib/govuk_tech_docs/table_of_contents/heading_tree_builder.rb
@@ -278,6 +341,7 @@ files:
278
341
  - lib/govuk_tech_docs/unique_identifier_extension.rb
279
342
  - lib/govuk_tech_docs/unique_identifier_generator.rb
280
343
  - lib/govuk_tech_docs/version.rb
344
+ - lib/source/api/pages.json.erb
281
345
  - lib/source/favicon.ico
282
346
  - lib/source/images/anchored-heading-icon-2x.png
283
347
  - lib/source/images/anchored-heading-icon.png
@@ -295,6 +359,7 @@ files:
295
359
  - lib/source/layouts/_analytics.erb
296
360
  - lib/source/layouts/_footer.erb
297
361
  - lib/source/layouts/_header.erb
362
+ - lib/source/layouts/_page_review.erb
298
363
  - lib/source/layouts/core.erb
299
364
  - lib/source/layouts/layout.erb
300
365
  homepage: https://github.com/alphagov/tech-docs-gem
@@ -317,7 +382,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
317
382
  version: '0'
318
383
  requirements: []
319
384
  rubyforge_project:
320
- rubygems_version: 2.5.1
385
+ rubygems_version: 2.6.13
321
386
  signing_key:
322
387
  specification_version: 4
323
388
  summary: Gem to distribute the GOV.UK Tech Docs Template