feat(dictionary): link to defined alt words

This commit is contained in:
Oscar 2019-11-14 09:32:09 +01:00
parent 3399abf6da
commit 9dc5a142dc
2 changed files with 15 additions and 3 deletions

View File

@ -1,10 +1,22 @@
const makeItemLink = (slug) => `#${slug}`
module.exports = function (config) {
// Add a filter using the Config API
config.addFilter('linkTarget', (slug) => `#${slug}`);
config.addFilter('linkTarget', makeItemLink);
config.addFilter('linkIfExistsInCollection', (word, collection) => {
const existingDefintion = collection.find(item => item.data.title === word)
if (existingDefintion) {
return `<a href=${makeItemLink(existingDefintion.data.slug)}>${word}</a>`
}
return word
})
// just a debug filter to lazily inspect the content of anything in a template
config.addFilter('postInspect', function (post) {
console.log(post);
})
config.addPassthroughCopy({'_site/css/': 'assets/css/'})

View File

@ -10,7 +10,7 @@
<h4>Alt words</h4>
<ul class="list-semicolon">
{% for word in definition.data.alt_words %}
<li>{{ word }}</li>
<li>{{ word | linkIfExistsInCollection(collections.definedWords) | safe }}</li>
{% endfor %}
</ul>
{% endif %}