-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
80 lines (67 loc) · 2.65 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
const { DateTime } = require("luxon");
const fs = require("fs");
const markdownIt = require("markdown-it");
const pageHeading = require("./src/_includes/shortcodes/pageHeading");
const waveDivider = require("./src/_includes/shortcodes/waveDivider.js");
const accordion = require("./src/_includes/shortcodes/accordion.js");
const phoneMockup = require("./src/_includes/shortcodes/phoneMockup.js");
const badge = require("./src/_includes/shortcodes/badge");
const lazyImagesPlugin = require("eleventy-plugin-lazyimages");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const isPostPublished = (post) => !post.data.draft;
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("admin");
eleventyConfig.addPassthroughCopy("src/assets/css/style.css");
eleventyConfig.addPassthroughCopy("src/assets/images");
eleventyConfig.addPassthroughCopy("src/assets/favicon");
eleventyConfig.addPassthroughCopy({ "src/robots.txt": "/robots.txt" });
eleventyConfig.addPlugin(lazyImagesPlugin);
eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.addPassthroughCopy({
"./node_modules/alpinejs/dist/cdn.js": "./js/alpine.js",
});
const md = new markdownIt({
html: true,
breaks: true,
linkify: true,
});
eleventyConfig.addPairedShortcode("markdown", (content) => {
return md.render(content);
});
let getSvgContent = function (file) {
let relativeFilePath = `./src/assets/svg/${file}.svg`;
let data = fs.readFileSync(relativeFilePath, function (err, contents) {
if (err) return err;
return contents;
});
return data.toString("utf8");
};
eleventyConfig.addShortcode("svg", getSvgContent);
eleventyConfig.addShortcode("pageHeading", pageHeading);
eleventyConfig.addShortcode("badge", badge);
eleventyConfig.addShortcode("waveDivider", waveDivider);
eleventyConfig.addShortcode("accordion", accordion);
eleventyConfig.addShortcode("phoneMockup", phoneMockup);
eleventyConfig.addCollection("page", function (collections) {
return collections.getFilteredByTag("page").sort(function (a, b) {
return a.data.order - b.data.order;
});
});
eleventyConfig.addCollection("posts", (collection) => {
return collection.getFilteredByGlob("./src/posts/*.md").filter(isPostPublished);
});
eleventyConfig.addShortcode("currentDate", (date = DateTime.now()) => {
return date;
});
eleventyConfig.addFilter("dateFormating", (dateObj) => {
return DateTime.fromJSDate(dateObj).toLocaleString(DateTime.DATE_MED);
});
return {
dir: {
input: "src",
data: "_data",
includes: "_includes",
layouts: "_layouts",
},
};
};