.eleventy.js (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
const markdownIt = require('markdown-it');
const markdownItToc = require('markdown-it-table-of-contents');
const markdownItAnchor = require('markdown-it-anchor');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy('src/assets');
eleventyConfig.addPassthroughCopy('CNAME');
const md = markdownIt({
html: true,
linkify: true,
typographer: true,
breaks: false,
})
.use(require('markdown-it-block-embed'))
.use(markdownItToc, { includeLevel: [1, 2, 3] })
.use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.headerLink(),
slugify: function (s) {
return String(s)
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
.trim()
.replace(/[^\w\s-]/g, '')
.replace(/\s+/g, '-');
},
});
eleventyConfig.setLibrary('md', md);
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPairedShortcode('aside', (content, label) => {
return `<aside class="aside"><p class="aside-label">${label}</p>${md.render(content)}</aside>`;
});
eleventyConfig.addShortcode('current', (slug, currentSlug) => {
return slug === currentSlug ? 'aria-current="page"' : '';
});
// if NO_RELOAD node environment variable is found, disable live reloading
if (process.env.NO_RELOAD) {
eleventyConfig.setServerOptions({
liveReload: false,
});
}
// sort chapter collection by fileSlug
eleventyConfig.addCollection('sortedChapter', function (collection) {
return collection
.getFilteredByTag('chapter')
.sort(
(a, b) =>
parseInt(a.fileSlug.substr(0, 2)) - parseInt(b.fileSlug.substr(0, 2)),
);
});
return {
dir: {
input: 'src',
},
};
};
|