-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eleventy.js
138 lines (124 loc) · 3.91 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
const dotenv = require('dotenv');
const fs = require('fs');
const svgSprite = require('eleventy-plugin-svg-sprite');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const markdownIt = require('markdown-it');
const implicitFigures = require('markdown-it-image-figures');
const localConfigFile = '.env.local';
if (fs.existsSync(localConfigFile)) {
const envConfig = dotenv.parse(fs.readFileSync(localConfigFile));
for (const k in envConfig) {
process.env[k] = envConfig[k];
}
}
/// Data
const alphabet = require('./src/_data/alphabet');
/// Filters
const searchFilter = require('./src/filters/searchFilter');
const { blameAll, getUserData } = require('./src/filters/blame');
// const { blameLast, blameAll } = require("./src/filters/blame");
const {
toFaDigits,
formatTime,
getAutherByEmail,
ifNoValue,
} = require('./src/utils/index');
module.exports = function (eleventyConfig) {
/******* PLUGINS *****/
eleventyConfig.addPlugin(syntaxHighlight, {
init: function ({ Prism }) {},
});
eleventyConfig.addPlugin(svgSprite, {
path: './assets/s',
});
/******* FILTERS *****/
eleventyConfig.addFilter('toFaDigits', toFaDigits);
eleventyConfig.addFilter('formatTime', formatTime);
eleventyConfig.addFilter('ifNoValue', ifNoValue);
eleventyConfig.addFilter('getAutherByEmail', getAutherByEmail);
eleventyConfig.addFilter('search', searchFilter);
if (process.env.NODE_ENV !== 'production') {
eleventyConfig.addFilter('blame', () => [
{
email: 'someone@mail',
time: new Date(),
},
]);
eleventyConfig.addFilter('getUserData', () => ({
user: '',
url: '',
avatar_url: '',
}));
} else {
eleventyConfig.addNunjucksAsyncFilter('blame', (path, callback) =>
blameAll(path).then(callback.bind(null, null))
);
eleventyConfig.addNunjucksAsyncFilter('getUserData', (email, callback) =>
getUserData(email).then(callback.bind(null, null))
);
}
/******* SHORTCODES *****/
// if (process.env.NODE_ENV !== 'production') {
// eleventyConfig.addNunjucksShortcode('getFileContributors', () => '###');
// eleventyConfig.addNunjucksShortcode('getFileContributorsAPI', () => '###');
// } else {
// eleventyConfig.addNunjucksAsyncShortcode(
// 'getFileContributors',
// getFileContributors
// );
// eleventyConfig.addNunjucksAsyncShortcode(
// 'getFileContributorsAPI',
// async (path) => {
// const contribs = await getFileContributorsByAPI(path);
// return `
// <ul id="contributors">
// ${contribs
// .map(
// (i) => `
// <li>
// <a href="${i.url}" target="_blank" rel="noreferrer">
// <img src="${i.avatar_url}" />
// </a>
// </li>
// `
// )
// .join('')}
// </ul>`;
// }
// );
// }
/******* COLLECTIONS *****/
eleventyConfig.addCollection('words', (collection) => {
return [...collection.getFilteredByGlob('./words/**/*.md')];
});
alphabet.forEach((l) =>
eleventyConfig.addCollection(l, (collection) => {
return [...collection.getFilteredByGlob(`./words/${l}/*.md`)];
})
);
/******* DATA *****/
// v+1:
// eleventyConfig.addGlobalData("alphabet", alphabet);
/******* PASSTHROUGH *****/
eleventyConfig.addPassthroughCopy({ assets: 'assets' });
eleventyConfig.addPassthroughCopy({ admin: 'admin' });
/******* Markdown Options *****/
const options = {
html: true,
};
const markdownLib = markdownIt(options).use(implicitFigures, {
figcaption: true,
});
eleventyConfig.setLibrary('md', markdownLib);
return {
passthroughFileCopy: true,
dir: {
input: 'words',
output: 'public',
// ⚠️ These values are both relative to your input directory.
data: '../src/_data',
includes: '../src/_includes',
// layouts: "../src/_layouts"
},
};
};