-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.js
111 lines (95 loc) · 3.54 KB
/
eleventy.config.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
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
require('dotenv').config();
const fs = require('fs');
const pluginRss = require("@11ty/eleventy-plugin-rss");
const fg = require('fast-glob').sync;
const MarkdownIt = require("markdown-it");
const EleventyPluginOgImage = require('eleventy-plugin-og-image');
const {decode} = require('html-entities');
const yaml = require("js-yaml");
module.exports = (eleventyConfig) => {
// COLLECTIONS
// =====================================================================
// Create Posts Collection
// ---------------------------------------------------------------
eleventyConfig.addCollection('posts', (api) => {
const files = fg(["src/content/posts/**/*.md"], {
ignore: ["src/content/posts/index.md"]
});
return api.getFilteredByGlob(files).sort((a,b) => b.date - a.date);
});
// Create Projects Collection
// ---------------------------------------------------------------
eleventyConfig.addCollection('projects', (api) => {
const files = fg(["src/content/projects/**/*.md"], {
ignore: ["src/content/projects/index.md"]
});
return api.getFilteredByGlob(files);
});
// =====================================================================
eleventyConfig.addFilter('fromJson', JSON.parse);
eleventyConfig.addFilter('toJson', JSON.stringify);
eleventyConfig.addFilter('decode', function(content) {
return decode(content, {level: 'html5'});
});
eleventyConfig.addGlobalData("eleventyComputed.permalink", function() {
return (data) => {
// Always skip during non-watch/serve builds
if(data.draft) {
return false;
}
return data.permalink;
}
});
eleventyConfig.addDataExtension("yaml", contents => yaml.load(contents));
eleventyConfig.addPairedShortcode('markdown', async (content) => {
const md = MarkdownIt();
return md.render(content.toString());
})
eleventyConfig.addShortcode('bookshop_link', async (isbn, slug, title) => {
// Ideally we want to send readers directly to the page, however
// the ISBN from ItalicType isn’t always book available on Bookshop.
// There may be an API to search for a book and get an active ISBN.
// Affiliate link structure:
// const url = `https://bookshop.org/a/84246/${ isbn }`;
const searchURL = `https://bookshop.org/search?keywords=${slug}`;
return `<a class="cmp-button" href="${searchURL}" rel="external" aria-label="Search for ${title} on Bookshop.org">Search for this book on Bookshop.org</a>`;
});
// OG IMAGE PLUGIN
eleventyConfig.addPlugin(EleventyPluginOgImage, {
satoriOptions: {
fonts: [
{
name: 'Mona Sans',
data: fs.readFileSync('./Mona-Sans-SemiBoldWide.woff'),
weight: 500,
style: 'normal'
}
]
}
});
eleventyConfig.addGlobalData('environment', process.env.NODE_ENV);
eleventyConfig.addGlobalData('site_url', process.env.SITE_URL);
eleventyConfig.addGlobalData('time_zone', "America/New_York");
eleventyConfig.addGlobalData('old_post_date', () => {
const year = new Date().getFullYear();
return year - 6;
});
eleventyConfig.addGlobalData('meta_description', 'Philip Zastrow. Designer, Engineer, and Web Accessibility Specialist. Website, Blog, and Dreams.');
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPassthroughCopy({"./src/public/" : "/"});
eleventyConfig.addWatchTarget("./src/public/");
// Return your Object options:
return {
dir: {
input: 'src/content',
output: 'dist',
includes: '../includes',
layouts: '../layouts',
data: '../data'
},
templateFormats: [ "md", "liquid", "html", "njk" ],
markdownTemplateEngine: "liquid",
htmlTemplateEngine: "liquid",
dataTemplateEngine: "njk",
}
};