-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
76 lines (66 loc) · 2.16 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
const caniuse = require('caniuse-api')
const browserslist = require('browserslist')
const {features, feature} = require('caniuse-lite')
module.exports = (config) => {
config.addPairedShortcode("codeSample", function(content) {
const htmlEntities = (str) => String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
return `<div class="c-page__preview">${content}</div><pre class="c-page__code"><code class="language-html">${htmlEntities(content)}</code></pre>`;
});
config.addShortcode("caniuse", function(fs) {
const featuresList = Object.keys(features)
const contains = (str, substr) => !!~str.indexOf(substr)
const find = (query) => {
if (typeof query !== "string") {
throw new TypeError("The `query` parameter should be a string.")
}
if (~featuresList.indexOf(query)) { // exact match
return query
}
return featuresList.filter((file) => contains(file, query))
}
const isSupported = (f, browser) => {
let data
try {
data = feature(features[f])
} catch(e) {
let res = find(f)
if (res.length === 1) {
data = features[res[0]]
} else {
throw new ReferenceError(`Please provide a proper feature name. Cannot find ${f}`)
}
}
const b = browser.split(' ')
return data.stats[b[0]][b[1]]
}
const browsers = browserslist('defaults')
const results = browsers.map((browser) => ({
name: browser,
support: fs.reduce((support, f) => support && !!(isSupported(f, browser).split(' ')[0].match(/[axy]/gi)), true),
})).map((result) => `
<li class="u-text-sm">
<div class="u-fw-bold u-o50">
${result.name}
</div>
<div>
${result.support ? '✅' : '❌'}
</div>
</li>
`)
return `
<ul class="o-auto-grid" style="--o-auto-grid--min-width: 10rem">
${results.join('')}
</ul>
`
})
config.addPassthroughCopy('docs/assets/vendor')
return {
dir: {
input: 'docs',
data: 'data',
includes: 'includes',
layouts: 'layouts',
output: 'dist',
},
}
}