aboutsummaryrefslogtreecommitdiffstats
path: root/.eleventy.js
blob: 96fd134b9c8a96ac303327c0161887e1f5370384 (plain) (blame)
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
84
const eleventysyntaxhighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
const eleventyrss = require('@11ty/eleventy-plugin-rss')
const markdown = require('markdown-it')
const markdownattrs = require('markdown-it-attrs')
const { DateTime } = require('luxon')
const postcss = require('postcss')
const postcssenv = require('postcss-preset-env')
const babel = require("@babel/core");
const env = require('./src/data/env')

module.exports = eleventyConfig => {
    eleventyConfig.addPlugin(eleventysyntaxhighlight)
    eleventyConfig.addPlugin(eleventyrss)

    eleventyConfig.setLibrary('md', markdown({
        html: true,
        linkify: true,
        typographer: true
    }).use(markdownattrs))

    eleventyConfig.addFilter('datefmt', date => DateTime.fromJSDate(date, { zone: 'utc' }).toFormat("dd LLL yyyy"))

    eleventyConfig.addExtension("css", {
        outputFileExtension: "css",
        compile: async(content, filename) =>
            async data => {
                const css = await postcss()
                    .use(postcssenv)
                    .process(content, {
                        from: filename,
                        map: data.env.isdevel
                    })

                return css.css
            }
    })

    eleventyConfig.addExtension("mjs", {
        outputFileExtension: "js",
        compile: (content, filename) =>
            async data => {
                const js = await babel.transformAsync(content, {
                    presets: [
                        ["@babel/preset-env", {
                            "targets": {
                                "esmodules": true,
                            },
                            bugfixes: true
                        }]
                    ],
                    sourceMaps: data.env.isdevel ? "inline" : false,
                    sourceFileName: filename
                })
                return js.code
            }
    })


    eleventyConfig.addPassthroughCopy('static/')
    eleventyConfig.addPassthroughCopy('favicon.svg')
    eleventyConfig.addPassthroughCopy('favicon.ico')

    return {
        dir: {
            input: 'src',
            output: 'dist',
            includes: 'includes',
            data: 'data',
            layouts: 'layouts'
        },

        dataTemplateEngine: 'njk',
        markdownTemplateEngine: 'njk',
        htmlTemplateEngine: 'njk',
        templateFormats: [
            'html',
            'md',
            'njk',
            '11ty.js',
            'css',
            'mjs'
        ]
    }
}