Repository navigation
Expand file tree
/
Copy path.eleventy.js
More file actions
78 lines (64 loc) · 2.42 KB
/
Copy path.eleventy.js
File metadata and controls
78 lines (64 loc) · 2.42 KB
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
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const pluginRss = require("@11ty/eleventy-plugin-rss");
module.exports = function (eleventyConfig) {
// Plugins
eleventyConfig.addPlugin(syntaxHighlight);
// To enable merging of tags
eleventyConfig.setDataDeepMerge(true);
// Copy these static files to _site folder
eleventyConfig.addPassthroughCopy("src/assets/**/*");
eleventyConfig.addPassthroughCopy("src/manifest.json");
eleventyConfig.addPassthroughCopy("src/resume/assets");
// To create excerpts
eleventyConfig.setFrontMatterParsingOptions({
excerpt: true,
excerpt_alias: "post_excerpt",
excerpt_separator: "<!-- excerpt -->",
});
// To create a filter to determine duration of post
eleventyConfig.addFilter("readTime", (value) => {
const content = value;
const textOnly = content.replace(/(<([^>]+)>)/gi, "");
const readingSpeedPerMin = 450;
return Math.max(1, Math.floor(textOnly.length / readingSpeedPerMin));
});
eleventyConfig.addFilter("formatDate", (value) => {
const date = new Date(value);
return date.toLocaleDateString("en-US", { year: 'numeric', month: 'long', day: 'numeric' })
});
// Enable us to iterate over all the tags, excluding posts and all
eleventyConfig.addCollection("tagList", (collection) => {
const tagsSet = new Set();
collection.getAll().forEach((item) => {
if (!item.data.tags) return;
item.data.tags
.filter((tag) => !["posts", "all"].includes(tag))
.forEach((tag) => tagsSet.add(tag));
});
return Array.from(tagsSet).sort();
});
const md = markdownIt({ linkify: true, html: true });
md.use(markdownItAnchor, {
level: [1, 2, 3],
permalink: true,
permalinkBefore: false,
permalinkSymbol: "#",
});
eleventyConfig.setLibrary("md", md);
// asset_img shortcode
eleventyConfig.addLiquidShortcode("asset_img", (filename, alt) => {
return `<img src="/assets/img/posts/${filename}" alt="${alt}" />`;
});
eleventyConfig.addLiquidShortcode("cover_img", (filename, alt) => {
return `<picture><img class="article__cover" src="/assets/img/posts/${filename}" alt="${alt}" /></picture>`;
});
eleventyConfig.addLiquidFilter("dateToRfc3339", pluginRss.dateRfc3339);
eleventyConfig.addPlugin(pluginRss);
return {
dir: {
input: "src",
},
};
};