sass-site/eleventy.config.cjs

109 lines
3.0 KiB
JavaScript
Raw Normal View History

2023-01-09 20:10:02 +01:00
'use strict';
2023-01-06 23:37:45 +01:00
2023-02-02 21:52:26 +01:00
const { EleventyRenderPlugin } = require('@11ty/eleventy');
2023-01-31 20:18:33 +01:00
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
2023-03-07 18:15:27 +01:00
const { formatDistanceToNow, format } = require('date-fns');
2023-01-24 23:51:07 +01:00
const yaml = require('js-yaml');
2023-02-24 18:52:18 +01:00
const { LoremIpsum } = require('lorem-ipsum');
2023-01-24 23:51:07 +01:00
const markdown = require('markdown-it');
2023-02-25 19:38:22 +01:00
const markdownItAttrs = require('markdown-it-attrs');
2023-01-29 20:17:04 +01:00
const markdownDefList = require('markdown-it-deflist');
2023-01-24 23:51:07 +01:00
const typogrify = require('typogr');
2023-03-07 18:15:27 +01:00
const truncate = require('truncate-html');
2023-01-24 23:51:07 +01:00
2023-01-06 22:40:29 +01:00
/** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */
2023-01-06 23:37:45 +01:00
module.exports = (eleventyConfig) => {
2023-01-09 20:10:02 +01:00
eleventyConfig.addPassthroughCopy('source/assets/dist');
eleventyConfig.addPassthroughCopy('source/assets/img');
eleventyConfig.addPassthroughCopy('source/favicon.ico');
2023-01-06 22:40:29 +01:00
eleventyConfig.setLiquidOptions({
jsTruthy: true,
});
2023-01-11 18:30:24 +01:00
eleventyConfig.setUseGitIgnore(false);
eleventyConfig.watchIgnores.add('source/_data/versionCache.json');
2023-01-24 23:51:07 +01:00
const mdown = markdown({
html: true,
typographer: true,
2023-02-25 19:38:22 +01:00
})
.use(markdownDefList)
.use(markdownItAttrs);
2023-01-24 23:51:07 +01:00
eleventyConfig.setLibrary('md', mdown);
2023-02-01 23:35:15 +01:00
eleventyConfig.addDataExtension('yml, yaml', (contents) =>
yaml.load(contents),
);
2023-01-24 23:51:07 +01:00
2023-02-24 18:52:18 +01:00
// Shortcodes...
const lorem = new LoremIpsum();
eleventyConfig.addLiquidShortcode('lorem', (type, number = 1) => {
switch (type) {
case 'sentence':
case 'sentences':
return lorem.generateSentences(number);
case 'paragraph':
case 'paragraphs':
return lorem.generateParagraphs(number);
case 'word':
case 'words':
return lorem.generateWords(number);
}
return '';
});
2023-01-27 18:20:05 +01:00
// Paired shortcodes...
2023-01-24 23:51:07 +01:00
eleventyConfig.addPairedLiquidShortcode('markdown', (content) =>
2023-02-01 23:42:31 +01:00
mdown.render(content),
2023-01-24 23:51:07 +01:00
);
eleventyConfig.addPairedLiquidShortcode('markdownInline', (content) =>
2023-02-01 23:42:31 +01:00
mdown.renderInline(content),
2023-01-24 23:51:07 +01:00
);
eleventyConfig.addPairedLiquidShortcode('typogr', (content) =>
typogrify.typogrify(content),
);
// Filters...
2023-03-07 18:15:27 +01:00
eleventyConfig.addLiquidFilter('truncatePost', (post) => {
return truncate(post, 250, { byWords: true });
})
eleventyConfig.addLiquidFilter('formatBlogDate', (date) => {
return format(new Date(date),'d MMMM yyyy');
})
2023-01-27 18:25:28 +01:00
eleventyConfig.addLiquidFilter('formatDistanceToNow', (date) => {
return formatDistanceToNow(new Date(date));
2023-01-26 21:56:20 +01:00
});
2023-01-27 18:20:05 +01:00
eleventyConfig.addLiquidFilter('markdown', (content) =>
2023-02-01 23:42:31 +01:00
mdown.render(content),
2023-01-27 18:20:05 +01:00
);
eleventyConfig.addLiquidFilter('markdownInline', (content) =>
2023-02-01 23:42:31 +01:00
mdown.renderInline(content),
2023-01-27 18:20:05 +01:00
);
2023-01-24 23:51:07 +01:00
eleventyConfig.addLiquidFilter('typogr', (content) =>
typogrify.typogrify(content),
);
eleventyConfig.addLiquidFilter('isTypedoc', (page) =>
page.url.startsWith('/documentation/js-api/'),
);
2023-01-29 21:04:56 +01:00
eleventyConfig.addPlugin(EleventyRenderPlugin);
2023-01-31 20:18:33 +01:00
eleventyConfig.addPlugin(syntaxHighlight);
2023-01-29 21:04:56 +01:00
2023-01-06 23:37:45 +01:00
// settings
return {
dir: {
2023-01-09 20:10:02 +01:00
input: 'source',
includes: '_includes',
layouts: '_layouts',
2023-01-06 23:37:45 +01:00
},
};
};