2023-01-09 20:10:02 +01:00
|
|
|
'use strict';
|
2023-01-06 23:37:45 +01:00
|
|
|
|
2023-03-06 12:59:38 +01:00
|
|
|
const path = require('path');
|
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-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-06 12:59:38 +01:00
|
|
|
const { Liquid } = require('liquidjs');
|
2023-03-06 13:02:03 +01:00
|
|
|
const {
|
|
|
|
getImplStatus,
|
|
|
|
canSplit,
|
|
|
|
generateCodeExample,
|
|
|
|
} = 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,
|
2023-01-10 23:05:39 +01:00
|
|
|
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);
|
2023-02-02 22:14:26 +01:00
|
|
|
eleventyConfig.watchIgnores.add('source/_data/versionCache.json');
|
2023-01-10 23:05:39 +01:00
|
|
|
|
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...
|
|
|
|
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);
|
|
|
|
return await liquidEngine.renderFile('code_example', {
|
|
|
|
code,
|
|
|
|
exampleName,
|
2023-03-06 13:02:03 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2023-03-06 12:59:38 +01:00
|
|
|
|
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
|
|
|
);
|
|
|
|
|
2023-01-31 23:05:27 +01:00
|
|
|
eleventyConfig.addPairedLiquidShortcode('typogr', (content) =>
|
|
|
|
typogrify.typogrify(content),
|
|
|
|
);
|
|
|
|
|
2023-01-27 18:26:46 +01:00
|
|
|
// 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/'),
|
|
|
|
);
|
|
|
|
|
2023-02-25 13:44:14 +01:00
|
|
|
eleventyConfig.addLiquidFilter(
|
|
|
|
'implStatus',
|
|
|
|
(
|
|
|
|
dart = null,
|
|
|
|
libsass = null,
|
|
|
|
ruby = null,
|
|
|
|
node = null,
|
|
|
|
feature = null,
|
|
|
|
markdown = null,
|
|
|
|
) => {
|
|
|
|
const data = {
|
|
|
|
dart: getImplStatus(dart),
|
|
|
|
libsass: getImplStatus(libsass),
|
|
|
|
ruby: getImplStatus(ruby),
|
|
|
|
node: getImplStatus(node),
|
|
|
|
feature: feature,
|
|
|
|
markdown: markdown,
|
|
|
|
};
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
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
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|