generated from distantcam/windty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
83 lines (73 loc) · 2.35 KB
/
.eleventy.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const fs = require("fs");
const htmlmin = require("html-minifier-terser");
const tailwind = require('tailwindcss');
const postCss = require('postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const mdit = require('markdown-it')
const mditAttrs = require('markdown-it-attrs');
const mditHighlight = require('markdown-it-highlightjs');
module.exports = async function(eleventyConfig) {
const { EleventyHtmlBasePlugin } = await import("@11ty/eleventy");
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
if (process.env.ELEVENTY_PRODUCTION) {
eleventyConfig.addTransform("htmlmin", htmlminTransform);
}
// markdown
const mditOptions = {
html: true,
breaks: true,
linkify: true,
typographer: true,
}
const mdLib = mdit(mditOptions).use(mditAttrs).use(mditHighlight, { inline: true }).disable('code')
eleventyConfig.setLibrary('md', mdLib)
// Passthrough
eleventyConfig.addPassthroughCopy({ "src/assets": "." });
eleventyConfig.addPassthroughCopy({ 'src/_assets/public': '/' });
eleventyConfig.addPassthroughCopy({ 'src/_assets/img': '/img' });
eleventyConfig.addPassthroughCopy({ 'src/_assets/fonts': '/fonts' });
// Watch targets
eleventyConfig.addWatchTarget("./src/_assets/css/");
// process css
eleventyConfig.addNunjucksAsyncFilter('postcss', postcssFilter);
return {
dir: {
input: "src/pages",
layouts: '../_layouts',
includes: '../_layouts/includes',
data: '../_data',
output: '_site',
},
templateFormats: ['md', 'njk', 'jpg', 'gif', 'png', 'html'],
pathPrefix: process.env.BASE_HREF ? `/${process.env.BASE_HREF}/` : "/" // used with github pages
}
};
function htmlminTransform(content, outputPath) {
if( outputPath.endsWith(".html") ) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
}
const postcssFilter = (cssCode, done) => {
postCss([
require('postcss-import'),
tailwind(require('./tailwind.config')),
autoprefixer(),
// TODO use purgecss for each layout
// cssnano({ preset: 'default' })
])
.process(cssCode, {
// path to our CSS file
from: './src/_assets/css/styles.css'
})
.then(
(r) => done(null, r.css),
(e) => done(e, null)
);
}