aboutsummaryrefslogtreecommitdiff
path: root/.eleventy.js
blob: c2b2086c82188c7dac397a82a4c4cb22709ff969 (plain)
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
/*jshint esversion: 6 */

const dayjs = require("dayjs");
const faviconPlugin = require("eleventy-favicon");
const eleventyPluginFeathericons = require("eleventy-plugin-feathericons");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const _ = require("lodash");

module.exports = function (config) {
    config.addPassthroughCopy({
        "src/css/styles.css": "./styles.css",
    });
    config.addPassthroughCopy({
        "src/css/fonts": "./fonts",
        "src/files": "./files",
    });
    config.addPassthroughCopy({
        "src/images": "./images",
    });
    config.addPlugin(faviconPlugin, {
        destination: "./public",
    });
    config.addWatchTarget("./src/css");
    config.addPlugin(eleventyPluginFeathericons);
    config.addPlugin(syntaxHighlight);
    config.addPlugin(pluginRss, {
        posthtmlRenderOptions: {
            closingSingleTag: "default",
        },
    });

    config.addFilter("dateFilter", function (date) {
        return dayjs(date).format("DD MMM YYYY");
    });

    function filterTagList(tags) {
        return (tags || []).filter(
            (tag) => ["all", "nav", "post", "posts"].indexOf(tag) === -1
        );
    }

    config.addCollection("postsByYear", (collection) => {
        return _.chain(
            collection.getAllSorted().filter((post) => {
                return post.data.tags?.includes("posts");
            })
        )
            .groupBy((post) => {
                return dayjs(post.date).format("DD MMM YYYY");
            })
            .toPairs()
            .reverse()
            .value();
    });

    config.addFilter("filterTagList", filterTagList);

    return {
        dir: {
            input: "src",
            output: "public",
        },
    };
};