From 9dc5a142dc1ca65bf3bb9652f0be157d480527bc Mon Sep 17 00:00:00 2001 From: Oscar Date: Thu, 14 Nov 2019 09:32:09 +0100 Subject: [PATCH] feat(dictionary): link to defined alt words --- .eleventy.js | 16 ++++++++++++++-- 11ty/_includes/components/definition.njk | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index 91f37979..3bb4af2c 100644 --- a/.eleventy.js +++ b/.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 `${word}` + } + + 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/'}) diff --git a/11ty/_includes/components/definition.njk b/11ty/_includes/components/definition.njk index b02c14e7..a2ce3639 100644 --- a/11ty/_includes/components/definition.njk +++ b/11ty/_includes/components/definition.njk @@ -10,7 +10,7 @@

Alt words

{% endif %}