diff --git a/lib/render-example.js b/lib/render-example.js index d80a09db54..430e659f79 100644 --- a/lib/render-example.js +++ b/lib/render-example.js @@ -1,6 +1,7 @@ import frontMatter from 'front-matter'; import fs from 'fs'; import nunjucks from 'nunjucks'; +import { minify } from 'html-minifier'; export default function renderExample(templatePath, nunjucksEnvironment) { try { @@ -24,11 +25,22 @@ export default function renderExample(templatePath, nunjucksEnvironment) { } const compiledTemplate = nunjucks.compile(template, nunjucksEnvironment, templatePath); - let html = compiledTemplate.render(templatePath); + html = minify(html, { + removeComments: true, + collapseWhitespace: true, + }); + //console.log(html); + return html; + + // let html = compiledTemplate.render(templatePath); + // html = minify(html, { + // removeComments: true, + // collapseWhitespace: true, + // }); - //removes whitespace and linebreaks before svg tags. - return html.replace(/\s*({{ item.text }} - {{ + {{- onsIcon({ "iconType": "chevron" }) - }} + -}} {% endfor %} diff --git a/src/components/button/_macro.njk b/src/components/button/_macro.njk index d15fc07624..fd39c0036d 100644 --- a/src/components/button/_macro.njk +++ b/src/components/button/_macro.njk @@ -84,28 +84,28 @@ {%- if iconPosition == "before" or iconPosition == "after" %} {%- if iconPosition == "before" %} - {{ + {{- onsIcon({ "iconType": iconType, "classes": 'ons-u-mr-xs' }) - }} + -}} {% endif -%} {{- params.html | safe if params.html else params.text -}} {%- if iconPosition == "after" %} - {{ + {{- onsIcon({ "iconType": iconType, "classes": 'ons-u-ml-xs' }) - }} + -}} {% endif -%} {% elif iconPosition == "only" -%} - {{ + {{- onsIcon({ "iconType": iconType }) - }} + -}} {{- params.html | safe if params.html else params.text -}} {% else -%} {{- params.html | safe if params.html else params.text -}} diff --git a/src/components/content-pagination/_macro.njk b/src/components/content-pagination/_macro.njk index 04a6e7661c..cb9db3d4c8 100644 --- a/src/components/content-pagination/_macro.njk +++ b/src/components/content-pagination/_macro.njk @@ -7,20 +7,20 @@ {% if contentPaginationItem.rel == 'prev' %} {% from "components/icon/_macro.njk" import onsIcon %} - {{ + {{- onsIcon({ "iconType": 'arrow-previous', "iconSize": 'm' }) - }} + -}} {% else %} {% from "components/icon/_macro.njk" import onsIcon %} - {{ + {{- onsIcon({ "iconType": 'arrow-next', "iconSize": 'm' }) - }} + -}} {% endif %} {{ contentPaginationItem.text }} diff --git a/src/components/details/_macro.njk b/src/components/details/_macro.njk index 7e5fe5fd7a..0b2b5fcabe 100644 --- a/src/components/details/_macro.njk +++ b/src/components/details/_macro.njk @@ -15,11 +15,11 @@ <{{ titleTag }} class="ons-details__title">{{ params.title }} {% from "components/icon/_macro.njk" import onsIcon %} - {{ + {{- onsIcon({ "iconType": "chevron" }) - }} + -}}
diff --git a/src/components/header/_macro.njk b/src/components/header/_macro.njk index d3dcff87e4..004ae9c6f1 100644 --- a/src/components/header/_macro.njk +++ b/src/components/header/_macro.njk @@ -41,12 +41,12 @@ {% if params.mastheadLogo.large %} {{ params.mastheadLogo.large | safe }} {% else %} - {{ + {{- onsIcon({ "iconType": 'ons-logo-' + currentLanguageISOCode, "altText": 'Office for National Statistics logo' }) - }} + -}} {% endif %}
{% if params.mastheadLogoUrl %} @@ -91,11 +91,11 @@ {% for item in params.serviceLinks.itemsList %}
  • {% if item.iconType %} - {{ + {{- onsIcon({ "iconType": item.iconType }) - }} + -}} {% endif %} {% if item.url %} {% if item.iconType %} - {{ + {{- onsIcon({ "iconType": item.iconType }) - }} + -}} {% endif %} {% if item.url %}
  • @@ -70,11 +70,11 @@
  • {% endif %} diff --git a/src/components/panel/_macro.njk b/src/components/panel/_macro.njk index 4453bd387a..0fd5fd95fc 100644 --- a/src/components/panel/_macro.njk +++ b/src/components/panel/_macro.njk @@ -41,11 +41,11 @@ {% if params.type == "announcement" %} {% from "components/icon/_macro.njk" import onsIcon %} {{ params.assistiveTextPrefix | default("Announcement: ") }} {% endif %} @@ -72,12 +72,12 @@ {% if params.iconType %} {% from "components/icon/_macro.njk" import onsIcon %} - {{ + {{- onsIcon({ "iconType": params.iconType, "iconSize": params.iconSize }) - }} + -}} {% endif %} diff --git a/src/components/quote/_macro.njk b/src/components/quote/_macro.njk index 30305ec611..b76ea2b2a8 100644 --- a/src/components/quote/_macro.njk +++ b/src/components/quote/_macro.njk @@ -1,11 +1,11 @@ {% macro onsQuote(params) %}
    {% from "components/icon/_macro.njk" import onsIcon %} - {{ + {{- onsIcon({ "iconType": 'quote' }) - }} + -}} {{ caller() if caller else params.text | safe }} {% if params.ref %}— {{ params.ref | safe }}{% endif %}
    diff --git a/src/components/summary/_macro.njk b/src/components/summary/_macro.njk index 6197e60fb7..5f2909d658 100644 --- a/src/components/summary/_macro.njk +++ b/src/components/summary/_macro.njk @@ -44,11 +44,11 @@ {% if rowItem.iconType %} {% from "components/icon/_macro.njk" import onsIcon %} - {{ + {{- onsIcon({ "iconType": rowItem.iconType }) - }} + -}} {% endif %} diff --git a/src/components/table/_macro.njk b/src/components/table/_macro.njk index 8d9eb34654..1a967a94df 100644 --- a/src/components/table/_macro.njk +++ b/src/components/table/_macro.njk @@ -18,13 +18,13 @@ {{- th.value -}} {% if 'sortable' in variants %} - {{ + {{- onsIcon({ "iconType": "sort-sprite", "id": th.value | replace(' ', '-'), "classes": 'ons-u-d-no' }) - }} + -}} {% endif %} {% endfor %} diff --git a/yarn.lock b/yarn.lock index 7cdbf8e4b9..9cc60d7034 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2995,6 +2995,14 @@ callsites@^3.0.0: resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ== +camel-case@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/camel-case/-/camel-case-3.0.0.tgz#ca3c3688a4e9cf3a4cda777dc4dcbc713249cf73" + integrity sha512-+MbKztAYHXPr1jNTSKQF52VpcFjwY5RkR7fxksV8Doo4KAYc5Fl4UJRgthBbTmEx8C54DqahhbLJkDwjI3PI/w== + dependencies: + no-case "^2.2.0" + upper-case "^1.1.1" + camelcase-keys@^7.0.0: version "7.0.2" resolved "https://registry.yarnpkg.com/camelcase-keys/-/camelcase-keys-7.0.2.tgz#d048d8c69448745bb0de6fc4c1c52a30dfbe7252" @@ -3185,6 +3193,13 @@ class-utils@^0.3.5: isobject "^3.0.0" static-extend "^0.1.1" +clean-css@^4.2.1: + version "4.2.4" + resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.2.4.tgz#733bf46eba4e607c6891ea57c24a989356831178" + integrity sha512-EJUDT7nDVFDvaQgAo2G/PJvxmp1o/c6iXLbswsBbUFXi1Nr+AjA2cKmfbKDMjMvzEe75g3P6JkaDDAKk96A85A== + dependencies: + source-map "~0.6.0" + clean-stack@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b" @@ -3364,7 +3379,7 @@ comma-separated-tokens@^2.0.0: resolved "https://registry.yarnpkg.com/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz#4e89c9458acb61bc8fef19f4529973b2392839ee" integrity sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg== -commander@^2.14.1, commander@^2.2.0, commander@^2.20.0, commander@^2.9.0: +commander@^2.14.1, commander@^2.19.0, commander@^2.2.0, commander@^2.20.0, commander@^2.9.0: version "2.20.3" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== @@ -5858,6 +5873,19 @@ html-escaper@^2.0.0: resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.2.tgz#dfd60027da36a36dfcbe236262c00a5822681453" integrity sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg== +html-minifier@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/html-minifier/-/html-minifier-4.0.0.tgz#cca9aad8bce1175e02e17a8c33e46d8988889f56" + integrity sha512-aoGxanpFPLg7MkIl/DDFYtb0iWz7jMFGqFhvEDZga6/4QTjneiD8I/NXL1x5aaoCp7FSIT6h/OhykDdPsbtMig== + dependencies: + camel-case "^3.0.0" + clean-css "^4.2.1" + commander "^2.19.0" + he "^1.2.0" + param-case "^2.1.1" + relateurl "^0.2.7" + uglify-js "^3.5.1" + html-tags@^3.3.1: version "3.3.1" resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.3.1.tgz#a04026a18c882e4bba8a01a3d39cfe465d40b5ce" @@ -7701,6 +7729,11 @@ lookup-closest-locale@6.2.0: resolved "https://registry.yarnpkg.com/lookup-closest-locale/-/lookup-closest-locale-6.2.0.tgz#57f665e604fd26f77142d48152015402b607bcf3" integrity sha512-/c2kL+Vnp1jnV6K6RpDTHK3dgg0Tu2VVp+elEiJpjfS1UyY7AjOYHohRug6wT0OpoX2qFgNORndE9RqesfVxWQ== +lower-case@^1.1.1: + version "1.1.4" + resolved "https://registry.yarnpkg.com/lower-case/-/lower-case-1.1.4.tgz#9a2cabd1b9e8e0ae993a4bf7d5875c39c42e8eac" + integrity sha512-2Fgx1Ycm599x+WGpIYwJOvsjmXFzTSc34IwDWALRA/8AopUKAVPwfJ+h5+f85BCp0PWmmJcWzEpxOpoXycMpdA== + lru-cache@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" @@ -8681,6 +8714,13 @@ nice-try@^1.0.4: resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== +no-case@^2.2.0: + version "2.3.2" + resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.2.tgz#60b813396be39b3f1288a4c1ed5d1e7d28b464ac" + integrity sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ== + dependencies: + lower-case "^1.1.1" + node-environment-flags@^1.0.5: version "1.0.6" resolved "https://registry.yarnpkg.com/node-environment-flags/-/node-environment-flags-1.0.6.tgz#a30ac13621f6f7d674260a54dede048c3982c088" @@ -9143,6 +9183,13 @@ pako@~1.0.5: resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf" integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw== +param-case@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/param-case/-/param-case-2.1.1.tgz#df94fd8cf6531ecf75e6bef9a0858fbc72be2247" + integrity sha512-eQE845L6ot89sk2N8liD8HAuH4ca6Vvr7VWAWwt7+kvvG5aBcPmmphQ68JsEG2qa9n1TykS2DLeMt363AAH8/w== + dependencies: + no-case "^2.2.0" + parent-module@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2" @@ -10050,6 +10097,11 @@ regjsparser@^0.9.1: dependencies: jsesc "~0.5.0" +relateurl@^0.2.7: + version "0.2.7" + resolved "https://registry.yarnpkg.com/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9" + integrity sha512-G08Dxvm4iDN3MLM0EsP62EDV9IuhXPR6blNz6Utcp7zyV3tr4HVNINt6MpaRWbxoOHT3Q7YN2P+jaHX8vUbgog== + remark-cli@^12.0.0: version "12.0.0" resolved "https://registry.yarnpkg.com/remark-cli/-/remark-cli-12.0.0.tgz#13919d1acf18028c3776f01a2e7cc1eb95b8b93a" @@ -10978,7 +11030,7 @@ source-map@^0.5.1, source-map@^0.5.6, source-map@~0.5.3: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" integrity sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ== -source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: +source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, source-map@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== @@ -11955,6 +12007,11 @@ ua-parser-js@^1.0.33: resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.36.tgz#a9ab6b9bd3a8efb90bb0816674b412717b7c428c" integrity sha512-znuyCIXzl8ciS3+y3fHJI/2OhQIXbXw9MWC/o3qwyR+RGppjZHrM27CGFSKCJXi2Kctiz537iOu2KnXs1lMQhw== +uglify-js@^3.5.1: + version "3.17.4" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.17.4.tgz#61678cf5fa3f5b7eb789bb345df29afb8257c22c" + integrity sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g== + umd@^3.0.0: version "3.0.3" resolved "https://registry.yarnpkg.com/umd/-/umd-3.0.3.tgz#aa9fe653c42b9097678489c01000acb69f0b26cf" @@ -12309,6 +12366,11 @@ update-browserslist-db@^1.0.13: escalade "^3.1.1" picocolors "^1.0.0" +upper-case@^1.1.1: + version "1.1.3" + resolved "https://registry.yarnpkg.com/upper-case/-/upper-case-1.1.3.tgz#f6b4501c2ec4cdd26ba78be7222961de77621598" + integrity sha512-WRbjgmYzgXkCV7zNVpy5YgrHgbBv126rMALQQMrmzOVC4GM2waQ9x7xtm8VU+1yF2kWyPzI9zbZ48n4vSxwfSA== + uri-js@^4.2.2: version "4.4.1" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e"