sass-site/eleventy.config.js

166 lines
4.6 KiB
JavaScript
Raw Normal View History

2023-01-09 20:10:02 +01:00
'use strict';
2023-01-06 23:37:45 +01:00
const path = require('path');
2023-03-07 21:45:47 +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-01-26 21:56:20 +01:00
const formatDistanceToNow = require('date-fns/formatDistanceToNow');
2023-01-24 23:51:07 +01:00
const yaml = require('js-yaml');
2023-03-07 21:45:47 +01:00
const { Liquid } = require('liquidjs');
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-03-07 21:45:47 +01:00
const Prism = require('prismjs');
const PrismLoader = require('prismjs/components/index.js');
2023-01-24 23:51:07 +01:00
const typogrify = require('typogr');
2023-03-07 21:45:47 +01:00
2023-03-06 13:02:03 +01:00
const {
generateCodeExample,
getImplStatus,
2023-03-06 13:02:03 +01:00
} = require('./source/helpers/sass_helpers.ts');
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
2023-03-06 18:32:51 +01:00
const liquidEngine = new Liquid({
root: [
path.resolve(__dirname, 'source/_includes/'),
path.resolve(__dirname, 'source/'),
],
extname: '.liquid',
strictFilters: true,
jsTruthy: true,
});
2023-03-06 18:32:51 +01:00
eleventyConfig.setLibrary('liquid', liquidEngine);
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-03-06 18:32:51 +01:00
// Paired shortcodes...
// Ideally this could be used with named args, but that's not supported yet in
// 11ty's implementation of LiquidJS:
// https://github.com/11ty/eleventy/issues/2679
// In the meantime, the args are: `dart`, `libsass`, `ruby`, `feature`
eleventyConfig.addPairedLiquidShortcode(
'compatibility',
async (details, dart = null, libsass = null, ruby = null, feature = null) =>
liquidEngine.renderFile('compatibility', {
details,
dart,
libsass,
ruby,
feature,
}),
);
2023-03-06 18:32:51 +01:00
eleventyConfig.addPairedLiquidShortcode(
2023-03-06 13:02:03 +01:00
'codeExample',
2023-03-06 18:32:51 +01:00
async (contents, exampleName, autogenCSS = true, syntax = null) => {
const code = generateCodeExample(contents, autogenCSS, syntax);
return liquidEngine.renderFile('code_examples/code_example', {
2023-03-06 18:32:51 +01:00
code,
exampleName,
2023-03-06 13:02:03 +01:00
});
},
);
eleventyConfig.addPairedLiquidShortcode('funFact', async (contents) =>
liquidEngine.renderFile('fun_fact', {
contents,
}),
);
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),
);
2023-03-07 21:45:47 +01:00
eleventyConfig.addPairedLiquidShortcode('code', (content, language) => {
if (!Prism.languages[language]) {
PrismLoader(language);
}
const html = Prism.highlight(content, Prism.languages[language], language);
const attr = `language-${language}`;
return `<pre class="${attr}"><code class="${attr}">${html}</code></pre>`;
});
// Filters...
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/'),
);
eleventyConfig.addLiquidFilter('implStatus', (status) =>
getImplStatus(status),
2023-02-25 13:44:14 +01:00
);
// plugins
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
},
};
};