mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-01-22 09:20:00 +00:00
feat(filters): move permalink function into file, add test
# Conflicts: # .eleventy.js
This commit is contained in:
parent
d2f7547d2d
commit
aaf3ea3b73
@ -1,15 +1,15 @@
|
||||
const makeItemLink = (slug) => `#${slug}`;
|
||||
const findExistingDefinition = require('./11ty/filters/helpers/findExistingDefinition');
|
||||
const definitionPermalink = require('./11ty/filters/definitionPermalink');
|
||||
|
||||
module.exports = function(config) {
|
||||
// Add a filter using the Config API
|
||||
config.addFilter('linkTarget', makeItemLink);
|
||||
config.addFilter('linkTarget', definitionPermalink);
|
||||
|
||||
config.addFilter('linkIfExistsInCollection', (word, collection) => {
|
||||
const existingDefinition = findExistingDefinition(word, collection);
|
||||
|
||||
if (existingDefinition) {
|
||||
return `<a href="${makeItemLink(
|
||||
return `<a href="${definitionPermalink(
|
||||
existingDefinition.data.slug
|
||||
)}">${word}</a>`;
|
||||
}
|
||||
@ -24,7 +24,7 @@ module.exports = function(config) {
|
||||
);
|
||||
|
||||
if (existingDefinition) {
|
||||
return `<a href="${makeItemLink(
|
||||
return `<a href="${definitionPermalink(
|
||||
existingDefinition.data.slug
|
||||
)}" aria-label="${subTermData.full_title}">${subTermData.text}</a>`;
|
||||
}
|
||||
|
7
11ty/filters/_tests/definitionPermalink.spec.js
Normal file
7
11ty/filters/_tests/definitionPermalink.spec.js
Normal file
@ -0,0 +1,7 @@
|
||||
import test from 'ava';
|
||||
|
||||
import definitionPermalink from '../definitionPermalink';
|
||||
|
||||
test('constructs correct detail link', (t) => {
|
||||
t.is(definitionPermalink('test-slug'), '/definitions/test-slug/');
|
||||
});
|
3
11ty/filters/definitionPermalink.js
Normal file
3
11ty/filters/definitionPermalink.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = function(slug) {
|
||||
return `/definitions/${slug}/`;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user