mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-01-22 09:20:00 +00:00
feat(dictionary): link to defined alt words
This commit is contained in:
parent
3399abf6da
commit
9dc5a142dc
16
.eleventy.js
16
.eleventy.js
@ -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/'})
|
||||
|
@ -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 %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user