diff --git a/.eleventy.js b/.eleventy.js index eda765200..09216ae8e 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -2,6 +2,7 @@ const definitionPermalink = require('./11ty/helpers/definitionPermalink'); const renderDefinitionContentNextEntries = require('./11ty/shortcodes/renderDefinitionContentNextEntries'); const findExistingDefinition = require('./11ty/filters/helpers/findExistingDefinition'); const pluginRss = require('@11ty/eleventy-plugin-rss'); +const removeMd = require('remove-markdown'); module.exports = function(config) { // Add a filter using the Config API @@ -187,6 +188,27 @@ module.exports = function(config) { }); }); + config.addCollection('search', (collection) => { + return collection + .getFilteredByGlob('./11ty/definitions/*.md') + .sort((a, b) => { + // `localeCompare()` is super cool: http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare + return a.data.title + .toLowerCase() + .localeCompare(b.data.title.toLowerCase()); + }); + }); + + // add filter to strip Markdown formatting from search text + config.addFilter('removeMarkdownFormatting', (value) => { + return removeMd(value).replace(/[\s\s+,\n]/g, ' '); + }); + + // add filter to extract text from sub_terms in search template + config.addFilter('extractSubTermText', (value) => { + return value ? value.map((subterm) => subterm.text).join(',') : ''; + }); + const mdIt = require('markdown-it')({ html: true }); diff --git a/11ty/_includes/components/search.njk b/11ty/_includes/components/search.njk new file mode 100644 index 000000000..3677e92cd --- /dev/null +++ b/11ty/_includes/components/search.njk @@ -0,0 +1,7 @@ +
+ +
+ + +
+
diff --git a/11ty/_includes/components/table-of-content.njk b/11ty/_includes/components/table-of-content.njk index bb1b265a9..b0b68e2de 100644 --- a/11ty/_includes/components/table-of-content.njk +++ b/11ty/_includes/components/table-of-content.njk @@ -1,5 +1,6 @@

Terms

+ {% include 'components/search.njk' %}