feat(11ty): render flags in defintions

This commit is contained in:
Oscar
2019-11-15 23:24:12 +01:00
parent b5e2289702
commit 017aef19fc
5 changed files with 41 additions and 11 deletions

View File

@ -21,6 +21,34 @@ module.exports = function (config) {
config.addPassthroughCopy({'_site/css/': 'assets/css/'})
config.addShortcode("definitionFlag", (flag) => {
const cleanText = new Map([
['avoid', {
class: 'avoid',
text: 'Avoid'
}],
['better-alternative', {
class: 'better',
text: 'Better alternate'
}],
['tool', {
class: 'tool',
text: ''
}]
])
if (flag) {
const info = cleanText.get(flag.level)
const sep = flag.text && info.text ? '—' : ''
const text = flag.text ? [info.text, flag.text].join(sep) : info.text
return `<p class="word__signal word__signal--${info.class}">${text}</p>`
}
return '<p class="word__signal"></p>'
});
// NOTE (ovlb): this will not be remembered as the best code ive written. if anyone seeing this has a better solution then the following to achieve sub groups of the definitions: i am happy to get rid of it
config.addCollection('definitions', collection => {