-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
223 lines (197 loc) · 7.57 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// import eleventyPurgeCss from 'eleventy-plugin-purgecss';
import eleventyAutoCacheBuster from 'eleventy-auto-cache-buster';
import eleventyPluginTOC from 'notacouch-eleventy-plugin-toc-ally';
// import eleventyPluginTOCDigitalMan from '@thedigitalman/eleventy-plugin-toc-a11y';
import eleventyTimeToRead from 'eleventy-plugin-time-to-read';
import markdownIt from 'markdown-it';
import markdownItNamedHeadings from 'markdown-it-named-headings';
import markdownItAttrs from 'markdown-it-attrs';
// Components
// import HeaderNav from './_src/components/global/HeaderNav.js';
import HomeHero from './_src/components/slices/HomeHero.js';
import PostPreview from './_src/components/slices/PostPreview.js';
import PostMeta from './_src/components/slices/PostMeta.js';
import Figure from './_src/components/slices/Figure.js';
import FloatWrapper from './_src/components/slices/FloatWrapper.js';
import TangentCeiling from './_src/components/toppings/TangentCeiling.js';
import Footer from './_src/components/global/Footer.js';
// TODO: shift to Prettier ESLint at some point
// TODO: inclusive language linter https://github.com/11ty/eleventy-plugin-inclusive-language
// TODO: jsdoc comments for components are not working out, try jsdoc -> json -> transform to argTypes
// try jsdoc -> json schema but it's extremely verbose. jsdoc ignores anything starting with _ so _src/* doesn't work even from command line
// npx jsdoc -X testjsdoc.js > testJsonDoc.json
// start here for above: https://stackoverflow.com/a/24421552/781824
// const componentShortcodeMap = new Map();
// componentShortcodeMap.set('HeaderNav', { args: ["currentPageUrl"] });
// componentShortcodeMap.set('Footer', {});
export default function (eleventyConfig) {
const simpleShortcodeFn = function generateShortcodeFn(component) {
return function () {
return new component().render();
};
};
const simpleComponents = new Map();
function componentRender(component, args) {
return new component().render(...args);
}
simpleComponents.set('Footer', { component: Footer });
// TODO: discuss this with 11ty in discord/github
// Watch components (doesn't seem to work)
eleventyConfig.addWatchTarget('./_src/**/*.js');
// Really can't get ignores to stop ignoring
// eleventyConfig.ignores.delete('styles/');
// eleventyConfig.watchIgnores.delete('styles/');
// eleventyConfig.ignores.delete('styles/base.min.css');
// eleventyConfig.ignores.delete('styles/styles.min.css');
eleventyConfig.addWatchTarget('styles/base.min.css');
eleventyConfig.addWatchTarget('styles/styles.min.css');
// Manage JS expectations in Liquid
// @url https://www.11ty.dev/docs/languages/liquid/#javascript-truthiness-in-liquid
eleventyConfig.setLiquidOptions({
jsTruthy: true,
});
// Default layout
eleventyConfig.addGlobalData('layout', '_index.liquid');
// Pass through assets
const assets = [
'notacouch-icon.png',
'notacouch-icon-256.png',
'blog-images',
'tangibles',
'storybook',
'styles',
];
assets.forEach(function passAsset(asset) {
eleventyConfig.addPassthroughCopy(asset);
});
// eleventyConfig.addPassthroughCopy("styles.css");
// Components changes are not reflected on refresh. Below made no difference.
// eleventyConfig.setServerOptions({
// watch: ['_src/components/**/*.js'],
// });
// @url https://www.11ty.dev/docs/collections/#advanced-custom-filtering-and-sorting
// @url https://github.com/11ty/eleventy/issues/927#issuecomment-627703544
eleventyConfig.addCollection('tagList', function (collectionApi) {
let tags = [];
let tagSet = new Set();
collectionApi.getAll().forEach(function processPostTags(post) {
if (!post.data.tags) {
return;
}
post.data.tags.forEach(function populateTagSet(tag) {
if (tag !== 'all') {
tagSet.add(tag);
}
});
});
tags = Array.from(tagSet).sort();
return tags;
});
// markdown-it-anchor did not work well for me
// @url https://www.npmjs.com/package/@thedigitalman/eleventy-plugin-toc-a11y#step-2-configuration
// tried this instead:
// @url https://github.com/11ty/eleventy/issues/812#issuecomment-1278714780
// Markdown settings, apply `id`s to headers
eleventyConfig.setLibrary(
'md',
markdownIt({
html: true,
breaks: true,
// linkify: true,
typographer: true,
})
.use(markdownItNamedHeadings)
.use(markdownItAttrs),
);
// if (process.env.NODE_ENV === "production") {
// eleventyConfig.addPlugin(purgeCssPlugin);
// }
// not working out of box with 11ty 3.x
// eleventyConfig.addPlugin(eleventyPurgeCss);
eleventyConfig.addPlugin(eleventyAutoCacheBuster);
eleventyConfig.addPlugin(eleventyPluginTOC, {
wrapperClass: 'toc',
headingClass: 'toc__header',
headingText: 'Table of Contents',
listClass: 'toc__ol',
skipLink: true,
skipLinkClass: 'skip-to-link',
skipLinkTargetId: 'post-toc-content',
});
eleventyConfig.addPlugin(eleventyTimeToRead, {
// Unexpected: makes read time shorter than the default 1,000 characters...
// speed: "200 words per minute"
});
eleventyConfig.addShortcode('HeaderNav', async function HeaderNavShortcode(currentPageUrl) {
const { default: HeaderNav } = await import('./_src/components/global/HeaderNav.js');
return componentRender(HeaderNav, arguments);
});
eleventyConfig.addShortcode('HomeHero', function HomeHeroShortcode(title, subtitle = '') {
return componentRender(HomeHero, arguments);
});
eleventyConfig.addShortcode(
'PostPreview',
function PostPreviewShortcode(
titleLink,
titleText,
subtitle = '',
publishedDatetime,
publishedDate,
topicContent,
) {
return componentRender(PostPreview, arguments);
},
);
eleventyConfig.addShortcode(
'PostMeta',
function PostMetaShortcode(
metaPrefix,
publishedDatetime,
publishedDate,
topicContent,
readTime = '',
modifiedDatetime = '',
modifiedDate = '',
) {
return componentRender(PostMeta, arguments);
},
);
eleventyConfig.addShortcode('TangentCeiling', function TangentCeilingShortcode(variant = '') {
return componentRender(TangentCeiling, arguments);
});
eleventyConfig.addPairedShortcode(
'Figure',
function figurePairedShortcode(content = '', type, imageSrc = '', imageAlt = '', caption = '') {
return componentRender(Figure, arguments);
},
);
eleventyConfig.addPairedShortcode(
'FloatWrapper',
function floatWrapperPairedShortcode(content = '') {
return componentRender(FloatWrapper, arguments);
},
);
simpleComponents.forEach(function simpleComponentShortcodify(componentConfig, componentName) {
if (!componentConfig.pair) {
// console.log('cname? ', componentName, simpleShortcodeFn(componentConfig.component).toString())
eleventyConfig.addShortcode(componentName, simpleShortcodeFn(componentConfig.component));
} else {
// @TODO: pair shortcode
// eleventyConfig.addShortcode(componentName, simpleShortcodeFn(componentConfig.component));
}
});
// componentShortcodeMap.keys().forEach(function shortCodify(componentName) {
// const componentFnConfig = componentShortcodeMap.get(componentName);
// const shortCodeFn = function() {
// if (componentFnConfig.args) {
// return function (...componentFnConfig.args) {
// }
// }
// }
// if (!componentFnConfig.shortCodePair) {
// eleventyConfig.addShortcode(componentName, function(currentPageUrl) {
// return (new HeaderNav()).render(currentPageUrl);
// });
// }
// })
}