forked from GuerillaStudio/vanillalist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
executable file
·69 lines (57 loc) · 2.26 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
const glob = require("glob-promise")
const fs = require("fs/promises")
const { URL } = require("url")
const sharpPlugin = require("eleventy-plugin-sharp")
const pluginRss = require("@11ty/eleventy-plugin-rss");
module.exports = function (eleventyConfig) {
eleventyConfig.addGlobalData('generated', () => {
let now = new Date();
return new Intl.DateTimeFormat(
'en-US', { dateStyle: 'full', timeStyle: 'long' }
).format(now);
});
eleventyConfig.setBrowserSyncConfig({ port: 1312 })
eleventyConfig.addPlugin(sharpPlugin(
{
urlPath: '/uploads',
outputDir: 'public/uploads'
}
))
eleventyConfig.addCollection('plugins', async () => {
const files = (await glob('plugins/*.json')).map(filename => {
return fs.readFile(filename, { encoding: 'utf-8' })
})
const plugins = await Promise.all(files)
return plugins.map(JSON.parse).sort((a, b) => b.id - a.id)
});
eleventyConfig.addFilter('JSONstringify', (value) => {
return JSON.stringify(value)
})
eleventyConfig.addFilter("absoluteUrl", (url, base) => {
try { return new URL(url, base).toString() } catch (e) {
console.error(`Trying to convert ${url} to be an absolute url with base ${base} and failed, returning: ${url} (invalid url)`);
return url;
}
});
eleventyConfig.addFilter("base64", async (url) => {
return fs.readFile(url, 'base64')
});
eleventyConfig.addShortcode("titleGenerator", (title, site, pageUrl, pagination) => {
let endTitle = `${site.name} • ${site.description}`
let paginationSuffix = (pagination && pagination.pageNumber) ? ` (page ${pagination.pageNumber + 1})` : ''
if (title) { endTitle = `${title} • ${site.name}` }
if (pageUrl === '/') { endTitle = `${site.name} • ${site.description}` }
return endTitle + paginationSuffix
});
eleventyConfig.addPassthroughCopy({ "./src/static/": "/"})
eleventyConfig.addWatchTarget("./src/sass/")
eleventyConfig.addWatchTarget("./src/static/")
// RSS
eleventyConfig.addPlugin(pluginRss);
return {
dir: {
input: "src",
output: "public",
},
};
};