summaryrefslogtreecommitdiff
path: root/eleventy.config.mjs
blob: 0ed461a3674413fcccc31dd2fede3e0736d4459c (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { parseISO , format} from "date-fns";
import { config as siteConfig } from "./siteconfig.mjs";
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import markdownIt from "markdown-it";
import EleventyPluginOgImage from 'eleventy-plugin-og-image';
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import fs from "fs"
import { OgImage } from 'eleventy-plugin-og-image/og-image';
import path from "path";
import sitemap from "@quasibit/eleventy-plugin-sitemap";
import { DateTime } from "luxon";

export class CustomOgImage extends OgImage {
  async shortcodeOutput() {
    return this.outputUrl();
  }
}

export default function(eleventyConfig) {
	// Order matters, put this at the top of your configuration file.
  eleventyConfig.addFilter("embedSVG", function(filePath) {
    const fullPath = path.join("./", filePath);
    return fs.readFileSync(fullPath, "utf-8");
  });
	eleventyConfig.addNunjucksFilter("date", (dateObj, formatString) => {
		return DateTime.fromJSDate(dateObj).toFormat(
			formatString || "cccc, LLLL dd yyyy"
		);
	});

  eleventyConfig.addCollection("navItems", function (collectionsApi) {
		return collectionsApi.getAll().filter(i =>  {
      if (i.data.nav) {
        return i.data.nav > 0
      }
    }).sort(function (a, b) {
			return (a.data.nav ?? -1000) - (b.data.nav ?? -1000);
		});
	});

  eleventyConfig.addPlugin(syntaxHighlight);
  eleventyConfig.addPlugin(EleventyPluginOgImage, {
    satoriOptions: {
      fonts: [
        {
          name: 'JetBrains Mono',
          data: fs.readFileSync('./assets/fonts/JetBrains/OG-Regular.ttf'),
          weight: 400,
          style: 'normal',
        },
        {
          name: 'JetBrains Mono',
          data: fs.readFileSync('./assets/fonts/JetBrains/OG-Bold.ttf'),
          weight: 800,
          style: 'normal',
        },
        {
          name: 'Kode Mono',
          data: fs.readFileSync('./assets/fonts/KodeMono/Regular.ttf'),
          weight: 400,
          style: 'normal',
        },
        {
          name: 'Kode Mono',
          data: fs.readFileSync('./assets/fonts/KodeMono/Bold.ttf'),
          weight: 800,
          style: 'normal',
        },
      ],
    },
    OgImage: CustomOgImage,
  });

	eleventyConfig.addPlugin(sitemap, {
		sitemap: {
			hostname: "https://spelis.li",
		},
	});

	eleventyConfig.addGlobalData("age", () => {
    const birthday = new Date("2010-05-11");

    const today = new Date();

    let age = today.getFullYear() - birthday.getFullYear();

    if (
        today.getMonth() < birthday.getMonth() ||
        (today.getMonth() === birthday.getMonth() &&
         today.getDate() < birthday.getDate())
    ) {
        age--;
    }

    return age;
	});

  // eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
  //   widths: [200, "auto"],
  //   htmlOptions: {
  // 	imgAttributes: {
  // 		loading: "lazy",
  // 		decoding: "async",
  // 	},
  // 	pictureAttributes: {}
  // },
  // });

  eleventyConfig.addBundle("css", {
    toFileDirectory: "assets/css/bundles/",

		// (Optional) File extension used for bundle file output, defaults to bundle name
		outputFileExtension: "css",
  });

  eleventyConfig.addBundle("js", {
    toFileDirectory: "assets/js/bundles/",

		// (Optional) File extension used for bundle file output, defaults to bundle name
		outputFileExtension: "js",
  });

  eleventyConfig.addGlobalData("layout","page");
  eleventyConfig.addGlobalData("site", {
    title: siteConfig.siteTitle ?? "Site",
    headerLinks: siteConfig.headerLinks ?? [],
    footerLinks: siteConfig.footerLinks ?? []
  })

  let options = {
		html: true,
		breaks: true,
		linkify: true,
    langPrefix: 'codeblock language-',
	};

	eleventyConfig.setLibrary("md", markdownIt(options));
  
  eleventyConfig
		.addPassthroughCopy({"./public/": "/"})
		.addPassthroughCopy({"./assets/": "/assets"})
		.addPassthroughCopy({"./assets/images/favicon.ico": "/favicon.ico"})

};
export const config = {
  dir: {
    input: "content",
    output: "_dist",
    includes: "../_includes",
    layouts: "../_layouts",
  },
  templateFormats: ["md", "njk"],
  htmlTemplateEngine: "njk",
  markdownTemplateEngine: "njk"
};