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-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');
|
|
|
|
const markdown = require('markdown-it');
|
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-02-17 17:10:42 +01:00
|
|
|
const sass = require('sass');
|
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-01-10 23:05:39 +01:00
|
|
|
eleventyConfig.setLiquidOptions({
|
|
|
|
jsTruthy: true,
|
|
|
|
});
|
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-01-29 21:04:56 +01:00
|
|
|
}).use(markdownDefList);
|
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-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
|
|
|
);
|
|
|
|
|
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-17 17:10:42 +01:00
|
|
|
eleventyConfig.addLiquidFilter(
|
|
|
|
'codeExample',
|
2023-02-17 17:48:22 +01:00
|
|
|
(contents, autogenCSS = true, syntax = null) => {
|
2023-02-17 17:10:42 +01:00
|
|
|
//TODO when are values for syntax passed in?
|
2023-02-17 17:48:22 +01:00
|
|
|
//TODO add tests
|
|
|
|
const splitContents = contents.split('===');
|
|
|
|
|
2023-02-17 17:10:42 +01:00
|
|
|
const scssContents = splitContents[0];
|
|
|
|
const sassContents = splitContents[1];
|
|
|
|
const cssContents = splitContents[2];
|
|
|
|
|
2023-02-17 17:48:22 +01:00
|
|
|
const scssExamples = scssContents.split('---');
|
|
|
|
const sassExamples = sassContents.split('---');
|
2023-02-17 17:10:42 +01:00
|
|
|
|
|
|
|
let cssExample;
|
2023-02-17 17:48:22 +01:00
|
|
|
if (cssContents) {
|
|
|
|
cssExample = cssContents;
|
|
|
|
} else if (!cssContents && autogenCSS) {
|
2023-02-17 17:10:42 +01:00
|
|
|
// TODO check first if you even have scss or sass to generate css from
|
|
|
|
// TODO what if no scss but sass?
|
|
|
|
cssExample = '';
|
|
|
|
scssExamples.forEach((scssSnippet) => {
|
|
|
|
const generatedCSS = sass.compileString(scssSnippet);
|
|
|
|
cssExample += generatedCSS.css;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2023-02-17 17:48:22 +01:00
|
|
|
scss: scssExamples,
|
2023-02-17 17:10:42 +01:00
|
|
|
css: cssExample,
|
|
|
|
sass: sassExamples,
|
2023-02-17 17:48:22 +01:00
|
|
|
splitLocation: '50.0%', //TODO dynamically determine
|
2023-02-17 17:10:42 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
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
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|