-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
128 lines (112 loc) · 3.71 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
const isProduction = process.env.NODE_ENV === `production`;
var md = require('markdown-it')('commonmark');
var markdownItAttrs = require('markdown-it-imsize');
var markdownItImgSize = require('markdown-it-imsize');
const AdmZip = require('adm-zip');
const glob = require('glob-promise');
const svgSprite = require("eleventy-plugin-svg-sprite");
const fs = require('fs');
const path = require('path');
module.exports = function(eleventyConfig) {
const outputDir = isProduction ? "public" : ".tmp"
eleventyConfig.addPlugin(svgSprite, {
path: "./components/Assets/svg",
outputFilepath: "sprites/icons.svg"
});
eleventyConfig.on('eleventy.after', async ({ dir, results, runMode, outputMode }) => {
await fs.promises.mkdir(`${outputDir}/media/downloads/zips`, { recursive: true });
const directories = await glob('./components/Assets/zips/*',{ stat: true, withFileTypes: true });
const timeSortedFiles = await directories.map(path => { return glob(`${path}/*.*`)})
for await (const file of timeSortedFiles) {
let zip = new AdmZip();
for await (const f of file) {
zip.addLocalFile(f);
}
console.log("Creating zip file for", file[0].split('/')[4])
zip.writeZip(`${outputDir}/media/downloads/zips/${file[0].split('/')[4]}.zip`);
}
});
eleventyConfig.addCollection("support", function(collectionApi) {
return collectionApi.getFilteredByGlob("site/support/**/index.md")
.map( (post) =>
{
post.data.tags = post.data.tags ?? []
const tag = post.inputPath.split('/')[3]
post.data.tags.push(tag)
if (tag) {
post.data.children = collectionApi.getFilteredByGlob(`site/support/${tag}/*.md`)
.filter(
x => x.fileSlug !== tag
)
.sort( (lhs, rhs) => {
return (lhs.data.order ?? 0) - (rhs.data.order ?? 0)
}
)
}
return post
}
)
.sort( (lhs, rhs) => {
return (lhs.data.order ?? 0) - (rhs.data.order ?? 0)
}
)
});
eleventyConfig.addFilter( 'unique', (obj, propertyName, expect) => {
const tagMap = obj.reduce( (values, current) => {
const tags = current.data.tags.filter((tag) => tag !== expect)
tags.forEach(tag => {
values[tag] = {}
});
return values
}, {});
return Object.keys(tagMap)
});
eleventyConfig.addFilter( 'index', (collections, tag, expect) => {
collections[tag].filter( (post) =>
post.data.tags.indexOf(expect) < 0
).shift()
});
eleventyConfig.setLibrary(
'md',
md
.use(markdownItImgSize)
.use(markdownItAttrs)
);
eleventyConfig.addFilter("hex", function(value) {
return parseInt(value, 10).toString(16).padStart(8,'0')
});
eleventyConfig.addShortcode("youtube", function(id) {
return `<iframe class="youtube" src="https://www.youtube.com/embed/${id}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`
});
eleventyConfig.addShortcode("yta", function(id, alt) {
return `<a class="yta" href="https://www.youtube.com/watch?v=${id}" title="${alt}" target="_blank" rel="noopener noreferrer">
<svg>
<use xlink:href="#svg-youtube"></use>
</svg>
</a>
`
});
eleventyConfig.addShortcode("picture", function(src, alt) {
return ` <picture class="sm:flex w-auto">
<source
type="image/webp"
srcset="${src}.webp"
/>
<source
type="image/png"
srcset="${src}.png"
/>
<img
class="w-full"
src="${src}.png"
alt="${alt}"
/>
</picture>`
});
return {
dir : {
input: "site",
output: outputDir,
}
}
};