Skip to content

Commit

Permalink
Merge pull request #78 from tatianamac/feature/eslint-ava
Browse files Browse the repository at this point in the history
馃彙 Install ESLint && Ava
  • Loading branch information
tatianamac committed Feb 19, 2020
2 parents b2cba4f + 5955864 commit b78dd4a
Show file tree
Hide file tree
Showing 8 changed files with 2,656 additions and 23 deletions.
11 changes: 5 additions & 6 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
const makeItemLink = (slug) => `#${slug}`;
const findExistingDefinition = (word, collection) =>
collection.find((item) => item.data.title === word);
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>`;
}
Expand All @@ -25,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>`;
}
Expand Down
12 changes: 12 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"ignorePatterns": ["node_modules/"],
"env": {
"browser": true,
"es2020": true,
"node": true
},
"parserOptions": {
"sourceType": "module"
}
}
7 changes: 7 additions & 0 deletions 11ty/filters/_tests/definitionPermalink.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import test from 'ava';

import definitionPermalink from '../definitionPermalink';

test('constructs correct detail link', (t) => {
t.is(definitionPermalink('test-slug'), '/#test-slug');
});
3 changes: 3 additions & 0 deletions 11ty/filters/definitionPermalink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(slug) {
return `/#${slug}`;
};
2 changes: 2 additions & 0 deletions 11ty/filters/helpers/findExistingDefinition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = (word, collection) =>
collection.find((item) => item.data.title === word);
5 changes: 5 additions & 0 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
files: ['./**/*.spec.js'],
require: ['esm'],
verbose: true
};
Loading

0 comments on commit b78dd4a

Please sign in to comment.