@x-govuk/nhsuk-eleventy-plugin 1.0.3 → 1.0.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-govuk/nhsuk-eleventy-plugin",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Write documentation using Markdown and publish it using NHS.UK styles",
5
5
  "keywords": [
6
6
  "nhsuk",
@@ -28,13 +28,13 @@
28
28
  "url": "git+https://github.com/x-govuk/nhsuk-eleventy-plugin.git"
29
29
  },
30
30
  "scripts": {
31
- "prebuild": "rimraf _site",
32
- "postbuild": "npm run build:example",
33
31
  "build": "eleventy",
32
+ "postbuild": "npm run build:example",
34
33
  "build:example": "eleventy --config=example.config.js",
35
34
  "predev": "npm run build",
36
35
  "dev": "eleventy --serve --watch",
37
36
  "dev:example": "eleventy --config=example.config.js --serve --watch",
37
+ "prestart": "npm run build",
38
38
  "start": "eleventy --serve",
39
39
  "lint:prettier": "prettier . --check",
40
40
  "lint:prettier:fix": "prettier . --write",
@@ -57,7 +57,7 @@
57
57
  "@rollup/plugin-commonjs": "^28.0.0",
58
58
  "@rollup/plugin-node-resolve": "^16.0.0",
59
59
  "@rollup/plugin-terser": "^0.4.4",
60
- "@x-govuk/govuk-eleventy-plugin": "^8.0.0",
60
+ "@x-govuk/govuk-eleventy-plugin": "^8.0.4",
61
61
  "accessible-autocomplete": "^3.0.1",
62
62
  "deepmerge": "^4.2.2",
63
63
  "markdown-it-abbr": "^2.0.0",
@@ -73,9 +73,8 @@
73
73
  "markdown-it-mark": "^4.0.0",
74
74
  "markdown-it-sub": "^2.0.0",
75
75
  "markdown-it-sup": "^2.0.0",
76
- "markdown-it-table-of-contents": "^0.9.0",
76
+ "markdown-it-table-of-contents": "^1.0.0",
77
77
  "nhsuk-frontend": "^10.0.0",
78
- "rimraf": "^6.0.0",
79
78
  "rollup": "^4.1.0",
80
79
  "sass": "^1.45.1"
81
80
  },
@@ -4,10 +4,21 @@
4
4
  {% if params.items.length > 0 %}
5
5
  <ol class="nhsuk-grid-row nhsuk-card-group{%- if params.classes %} {{ params.classes }}{% endif %}">
6
6
  {% for item in params.items | itemsFromCollection %}
7
+
8
+ {% if item.caption %}
9
+ {% set headingHtml %}
10
+ <div class="nhsuk-caption-m">{{ item.caption }}</div>
11
+ <h2 class="nhsuk-card__heading {{ params.headingClasses or "nhsuk-u-font-size-22" + (" nhsuk-u-margin-bottom-2" if item.descriptionHtml else "") }}">
12
+ <a class="nhsuk-card__link" href="{{ item.href }}">{{ item.heading }}</a>
13
+ </h2>
14
+ {% endset %}
15
+ {% endif %}
16
+
7
17
  <li class="nhsuk-grid-column-full nhsuk-card-group__item">
8
18
  {{ nhsukCard({
9
19
  secondary: true,
10
- heading: item.heading,
20
+ heading: item.heading if not item.caption,
21
+ headingHtml: headingHtml if item.caption,
11
22
  headingClasses: params.headingClasses or "nhsuk-u-font-size-22" + (" nhsuk-u-margin-bottom-2" if item.descriptionHtml else ""),
12
23
  headingLevel: params.headingLevel or 2,
13
24
  href: item.href,
@@ -2,11 +2,11 @@
2
2
  {% set size = params.size or "xl" %}
3
3
  {% if params.caption %}
4
4
  <span class="nhsuk-caption-{{ size }}">
5
- {{- params.caption -}}
5
+ {{- params.caption | smart -}}
6
6
  </span>
7
7
  {% endif %}
8
8
  <h{{level}} class="nhsuk-heading-{{ size }}{%- if params.classes %} {{ params.classes }}{% endif %}">
9
- {{- params.title | safe -}}
9
+ {{- params.title | smart | safe -}}
10
10
  </h{{level}}>
11
11
  {% if params.description -%}
12
12
  <p class="{{ "nhsuk-lede-text" if level == 1 else "nhsuk-body nhsuk-u-reading-width" }}">
@@ -12,6 +12,10 @@ const defaults = {
12
12
  shortcut: '/assets/images/favicon.ico',
13
13
  touch: '/assets/images/nhsuk-icon-180.png'
14
14
  },
15
+ markdown: {
16
+ headingPermalinks: false,
17
+ headingsStartWith: 'xl'
18
+ },
15
19
  opengraphImageUrl: '/assets/images/nhsuk-opengraph-image.png',
16
20
  stylesheets: [],
17
21
  titleSuffix: 'NHS',
@@ -46,5 +50,17 @@ export function defaultPluginOptions(options, pathPrefix) {
46
50
  options._feedPath = options.templates?.feed?.permalink || '/feed.xml'
47
51
  }
48
52
 
53
+ // Show message if using deprecated headingPermalinks option
54
+ if (options?.headingPermalinks) {
55
+ console.warn(
56
+ 'The `headingPermalinks` option is deprecated and will be removed in a future version. Use `markdown.headingPermalinks` option instead.'
57
+ )
58
+
59
+ options.markdown = {
60
+ headingPermalinks: options.headingPermalinks,
61
+ ...options.markdown
62
+ }
63
+ }
64
+
49
65
  return deepmerge(defaults, options)
50
66
  }
@@ -13,6 +13,7 @@ export {
13
13
  noOrphans,
14
14
  pretty,
15
15
  sliceFromCollection,
16
+ sortCollection,
16
17
  smart,
17
18
  tokenize
18
19
  } from '@x-govuk/govuk-eleventy-plugin/filters'
@@ -3,6 +3,7 @@ import {
3
3
  markdown,
4
4
  nhsukDate,
5
5
  sliceFromCollection,
6
+ sortCollection,
6
7
  smart
7
8
  } from './index.js'
8
9
 
@@ -50,10 +51,13 @@ function getDescriptionHtml(item) {
50
51
  */
51
52
  export function itemsFromCollection(array, n) {
52
53
  if (isCollectionData(array)) {
54
+ array = sortCollection(array, true)
55
+
53
56
  array = array.map((item) => {
54
57
  return {
55
58
  href: item.url,
56
59
  date: item.data.date,
60
+ caption: item.data.caption,
57
61
  title: item.data.title,
58
62
  description: item.data.description,
59
63
  image: item.data.image
@@ -63,6 +67,7 @@ export function itemsFromCollection(array, n) {
63
67
 
64
68
  array = array.map((item) => ({
65
69
  href: item.href,
70
+ ...(item.caption && { caption: item.caption }),
66
71
  heading: smart(item.title),
67
72
  descriptionHtml: getDescriptionHtml(item),
68
73
  ...(item.image && { imgURL: item.image.src }),
package/src/index.js CHANGED
@@ -45,7 +45,7 @@ export async function nhsukEleventyPlugin(eleventyConfig, pluginOptions = {}) {
45
45
  const options = defaultPluginOptions(pluginOptions, pathPrefix)
46
46
 
47
47
  // Libraries
48
- eleventyConfig.setLibrary('md', md(options))
48
+ eleventyConfig.setLibrary('md', md(options.markdown))
49
49
  eleventyConfig.setLibrary('njk', nunjucksConfig(eleventyConfig))
50
50
 
51
51
  // Collections
@@ -27,11 +27,13 @@
27
27
  }) }}
28
28
 
29
29
  {{ nhsukPagination({
30
- classes: "nhsuk-u-reading-width",
31
- previousUrl: pagination.href.previous,
32
- previousPage: pagination.page.previous | length + " items",
33
- nextUrl: pagination.href.next,
34
- nextPage: pagination.page.next | length + " items"
30
+ previous: {
31
+ href: pagination.href.previous
32
+ },
33
+ next: {
34
+ href: pagination.href.next
35
+ },
36
+ items: pagination | itemsFromPagination
35
37
  }) if pagination.pages.length > 1 }}
36
38
 
37
39
  {{ appRelated(related) if related }}
@@ -9,7 +9,7 @@
9
9
 
10
10
  {{ appProseScope(content) if content }}
11
11
 
12
- {% for item in collections.sitemap | eleventyNavigation(options.homeKey) %}
12
+ {% for item in collections.sitemap | sortCollection(true) | eleventyNavigation(options.homeKey) %}
13
13
  <nav class="nhsuk-contents-list">
14
14
  <h2 class="nhsuk-heading-m nhsuk-u-margin-bottom-2">
15
15
  <a class="nhsuk-link" href="{{ item.url | canonicalUrl | pretty }}">{{ item.title | smart }}</a>
@@ -19,7 +19,7 @@
19
19
  {% endif %}
20
20
  {{ collections.sitemap | eleventyNavigation(item.key) | eleventyNavigationToHtml({
21
21
  listElement: "ol"
22
- }) | safe }}
22
+ }) | smart | safe }}
23
23
  </nav>
24
24
  {% endfor %}
25
25
  {% endblock %}
@@ -26,27 +26,28 @@ import { tableRules } from './markdown-it/table.js'
26
26
  * Configure markdown-it
27
27
  *
28
28
  * @see {@link https://markdown-it.github.io/markdown-it/}
29
- * @param {object} [options] - Plugin options
29
+ * @param {object} [markdownOptions] - Plugin Markdown options
30
30
  * @returns {Function} markdown-it instance
31
31
  */
32
- export function md(options = {}) {
32
+ export function md(markdownOptions = {}) {
33
33
  const opts = {
34
34
  breaks: true,
35
35
  highlight,
36
36
  html: true,
37
37
  linkify: false,
38
- typographer: true
38
+ typographer: true,
39
+ ...markdownOptions
39
40
  }
40
41
 
41
42
  const md = new MarkdownIt(opts)
42
43
  .use(markdownItGovuk, {
43
44
  brand: 'nhsuk',
44
45
  calvert: true,
45
- headingsStartWith: 'xl'
46
+ headingsStartWith: markdownOptions.headingsStartWith
46
47
  })
47
48
  .use(markdownItAbbr)
48
49
  .use(markdownItAnchor, {
49
- permalink: options.headingPermalinks
50
+ permalink: markdownOptions.headingPermalinks
50
51
  ? markdownItAnchor.permalink.headerLink({
51
52
  class: 'app-link--heading',
52
53
  safariReaderFix: true