-
Notifications
You must be signed in to change notification settings - Fork 6
/
.eleventy.js
183 lines (144 loc) · 7.55 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// @param {import("@11ty/eleventy/src/UserConfig")} eleventyConfig
// Imports --------------------------------------------
import { EleventyI18nPlugin, EleventyHtmlBasePlugin, EleventyRenderPlugin, IdAttributePlugin } from '@11ty/eleventy';
import fs from 'fs';
import markdownIt from 'markdown-it';
import markdownItIns from 'markdown-it-ins';
import markdownItMark from 'markdown-it-mark';
import markdownItSub from 'markdown-it-sub';
import markdownItSup from 'markdown-it-sup';
import markdownItToc from 'markdown-it-table-of-contents';
import path from 'path';
import pluginRSS from '@11ty/eleventy-plugin-rss';
import pluginSyntaxHighlight from '@11ty/eleventy-plugin-syntaxhighlight';
import pluginEmbedEverything from 'eleventy-plugin-embed-everything';
import slugify from '@sindresorhus/slugify';
// Local ---------------------------------------------
// Plugins
import pluginDrafts from './elva/plugins/drafts.js';
import pluginDescriptions from './elva/plugins/seodescriptions.js';
// Plugin Configs
import pluginEmbedEverythingConfig from './elva/config/embeds.js';
// Transforms
import transformCSS from './elva/transforms/css.js';
import transformHTML from './elva/transforms/html.js';
import transformJS from './elva/transforms/js.js';
// Shortcodes
import image from './elva/shortcodes/image.js';
// Filters
import base64 from './elva/filters/base64.js';
import cdnify from './elva/filters/cdnify.js';
import { formatDate } from './elva/filters/dates.js';
import languageFilter from './elva/filters/language.js';
import mimetype from './elva/filters/mimetype.js';
import random from './elva/filters/random.js';
import readingTime from './elva/filters/readingtime.js';
import sort from './elva/filters/sort.js';
import translate from './elva/filters/translate.js';
import where from './elva/filters/where.js';
// Languages
// to-do: This is a temp fix based on this bug: https://github.com/11ty/eleventy-dependency-tree-esm/issues/2
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const locales = require('./content/_data/locales.json');
// 11ty -----------------------------------------------
export default async function(eleventyConfig) {
// Global Settings --------------------------------
eleventyConfig.addGlobalData('settings', {
// these get merged with content/_data/settings.js
url: process.env.URL || process.env.CF_PAGES_URL || 'http://localhost:8080',
isProduction: process.env.NODE_ENV === 'production',
isStaging: (process.env.URL && process.env.URL.includes('github.io')) || (process.env.CF_PAGES_URL && process.env.CF_PAGES_URL.includes('pages.dev')) || false
});
// Watch Targets ----------------------------------
eleventyConfig.addWatchTarget('./content/assets');
eleventyConfig.addWatchTarget('./theme/**/*.{css,js}');
eleventyConfig.addWatchTarget('./elva/templates/*', { resetConfig: true });
// Layouts ----------------------------------------
eleventyConfig.addLayoutAlias('base', 'base.njk');
eleventyConfig.addLayoutAlias('home', 'home.njk');
eleventyConfig.addLayoutAlias('page', 'page.njk');
eleventyConfig.addLayoutAlias('post', 'post.njk');
eleventyConfig.addLayoutAlias('posts', 'posts.njk');
// Virtual Templates ------------------------------
const cssTemplate = fs.readFileSync(path.resolve('theme/css/', 'bundle.njk'), 'utf-8');
const jsTemplate = fs.readFileSync(path.resolve('theme/js/', 'bundle.njk'), 'utf-8');
const robotsTemplate = fs.readFileSync(path.resolve('elva/templates/', 'robots.njk'), 'utf-8');
const sitemapTemplate = fs.readFileSync(path.resolve('elva/templates/', 'sitemap.njk'), 'utf-8');
eleventyConfig.addTemplate('css-bundle.njk', cssTemplate);
eleventyConfig.addTemplate('js-bundle.njk', jsTemplate);
eleventyConfig.addTemplate('robots.njk', robotsTemplate);
eleventyConfig.addTemplate('sitemap.njk', sitemapTemplate);
const feedTemplate = fs.readFileSync(path.resolve('elva/templates/', 'feed.njk'), 'utf-8');
const feedXSLTemplate = fs.readFileSync(path.resolve('elva/templates/', 'feed.xsl.njk'), 'utf-8');
const feedJSONTemplate = fs.readFileSync(path.resolve('elva/templates/', 'feed.json.njk'), 'utf-8');
const manifestTemplate = fs.readFileSync(path.resolve('elva/templates/', 'manifest.njk'), 'utf-8');
for (let [key, locale] of Object.entries(locales)) {
eleventyConfig.addTemplate(key + '-feed.njk', feedTemplate, { lang: key });
eleventyConfig.addTemplate(key + '-feed.xsl.njk', feedXSLTemplate, { lang: key });
eleventyConfig.addTemplate(key + '-feed.json.njk', feedJSONTemplate, { lang: key });
eleventyConfig.addTemplate(key + '-manifest.njk', manifestTemplate, { lang: key });
}
// Plugins ----------------------------------------
await eleventyConfig.addPlugin(pluginRSS);
eleventyConfig.addPlugin(pluginDrafts);
eleventyConfig.addPlugin(pluginDescriptions);
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(EleventyI18nPlugin, { defaultLanguage: 'en' });
eleventyConfig.addPlugin(IdAttributePlugin);
eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.addPlugin(pluginEmbedEverything, pluginEmbedEverythingConfig);
// Transforms -------------------------------------
eleventyConfig.addPlugin(transformCSS);
eleventyConfig.addPlugin(transformHTML);
eleventyConfig.addPlugin(transformJS);
// Shortcodes -------------------------------------
eleventyConfig.addShortcode('version', () => `${+ new Date()}`);
eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`);
eleventyConfig.addShortcode('build', () => `${new Date().toISOString().split('T')[0]}`);
eleventyConfig.addShortcode('image', image);
// Filters ----------------------------------------
eleventyConfig.addFilter('base64', base64);
eleventyConfig.addFilter('cdnify', cdnify);
eleventyConfig.addFilter('formatDate', formatDate);
eleventyConfig.addFilter('languageFilter', languageFilter);
eleventyConfig.addFilter('mimetype', mimetype);
eleventyConfig.addFilter('random', random);
eleventyConfig.addFilter('readingTime', readingTime);
eleventyConfig.addFilter('translate', translate);
eleventyConfig.addFilter('sort', sort);
eleventyConfig.addFilter('where', where);
// Passthrough -------------------------------------
eleventyConfig.addPassthroughCopy({'./content/assets/files': './assets/files'});
eleventyConfig.addPassthroughCopy({'./content/assets/img': './assets/img'});
eleventyConfig.addPassthroughCopy({'./theme/fonts': './assets/fonts'});
// Markdown ----------------------------------------
eleventyConfig.setLibrary('md', markdownIt({
html: true,
linkify: true,
typographer: true
}));
eleventyConfig.amendLibrary('md', (mdLib) => {
mdLib.use(markdownItIns);
mdLib.use(markdownItMark);
mdLib.use(markdownItSub);
mdLib.use(markdownItSup);
mdLib.use(markdownItToc, { slugify, includeLevel: [2,3]});
});
// 11ty Settings -----------------------------------
return {
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
dataTemplateEngine: 'njk',
// If your site deploys to a subdirectory, change `pathPrefix`
pathPrefix: '/',
dir: {
input: 'content',
output: 'dist',
data: '_data',
includes: '../theme/_includes',
layouts: '../theme/_layouts'
}
}
}