Skip to content

Commit 455fa58

Browse files
Render Nunjucks icon macro into SVGs files
1 parent 6eb248f commit 455fa58

4 files changed

Lines changed: 48 additions & 2 deletions

File tree

packages/nhsuk-frontend/gulpfile.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import types from './tsconfig.json' with { type: 'json' }
1717
/**
1818
* Utility tasks
1919
*/
20-
gulp.task('assets', assets.copy)
20+
gulp.task('assets', gulp.series(assets.copy, assets.render))
2121
gulp.task('fixtures', fixtures.compile)
2222
gulp.task('scripts', gulp.series(scripts.compile, scripts.version))
2323
gulp.task('styles', gulp.series(styles.compile, styles.version))
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
import { join } from 'node:path'
22

33
import * as config from '@nhsuk/frontend-config'
4+
import { files, icons } from '@nhsuk/frontend-lib'
45
import { assets, task } from '@nhsuk/frontend-tasks'
56

7+
import { nunjucks } from '#lib'
8+
69
/**
7-
* Copy NHS.UK frontend images, icons and other assets
10+
* Copy NHS.UK frontend images and other assets
811
*/
912
export const copy = task.name('assets:copy', () =>
1013
assets.copy('nhsuk/assets/**', {
1114
srcPath: join(config.paths.pkg, 'src'),
1215
destPath: join(config.paths.pkg, 'dist/nhsuk/assets')
1316
})
1417
)
18+
19+
/**
20+
* Render NHS.UK frontend icons
21+
*/
22+
export const render = task.name('assets:render', async () => {
23+
for (const icon of icons.getNames()) {
24+
const svg = nunjucks.renderMacro('nhsukIcon', 'nhsuk/macros/icon.njk', {
25+
context: icon
26+
})
27+
28+
// Write icon SVG to destination
29+
await files.write(`nhsuk-icon-${icon}.svg`, {
30+
destPath: join(config.paths.pkg, 'dist/nhsuk/assets/images'),
31+
output: { contents: svg }
32+
})
33+
}
34+
})

shared/lib/icons.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Get icon names
3+
*/
4+
export function getNames() {
5+
return [
6+
'arrow-down-circle',
7+
'arrow-down',
8+
'arrow-left-circle',
9+
'arrow-left',
10+
'arrow-right-circle',
11+
'arrow-right',
12+
'arrow-up-circle',
13+
'arrow-up',
14+
'chevron-down-circle',
15+
'chevron-left-circle',
16+
'chevron-right-circle',
17+
'chevron-up-circle',
18+
'cross',
19+
'minus',
20+
'plus',
21+
'search',
22+
'tick',
23+
'user'
24+
]
25+
}

shared/lib/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
*/
44
export * as components from './components.mjs'
55
export * as files from './files.mjs'
6+
export * as icons from './icons.mjs'
67
export * as screenshots from './screenshots.mjs'

0 commit comments

Comments
 (0)