-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy path.eleventy.js
94 lines (90 loc) · 3.39 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
// development host for playground proxy
const PLAYGROUND_PROXY_HOST = 'http://localhost:8788';
const drafts = [
'CG-FINAL',
'CR',
'ED',
'FCGS',
'PR',
'REC',
'WD',
'latest'
];
export default async function(eleventyConfig) {
eleventyConfig.addPassthroughCopy('404.html');
eleventyConfig.addPassthroughCopy('.htaccess');
eleventyConfig.addPassthroughCopy('LICENSE.md');
eleventyConfig.addPassthroughCopy('_headers');
eleventyConfig.addPassthroughCopy('_redirects');
eleventyConfig.addPassthroughCopy('benchmarks/**/*.{jsonld,nq,md}');
eleventyConfig.addPassthroughCopy('contexts/**/*.{htaccess,html,jsonld}');
eleventyConfig.addPassthroughCopy('contexts/{event,person,place,recipe,remote-context}');
eleventyConfig.addPassthroughCopy('examples/**/*.{html,ttl,txt,json}');
eleventyConfig.addPassthroughCopy('favicon.ico');
eleventyConfig.addPassthroughCopy('fonts');
eleventyConfig.addPassthroughCopy('functions/**/*.js');
eleventyConfig.addPassthroughCopy('images/**/*.{htaccess,png,svg,xcf}');
eleventyConfig.addPassthroughCopy('ns/**/*.{html,jsonld}');
eleventyConfig.addPassthroughCopy('playground/**/*.{css,php,js}');
eleventyConfig.addPassthroughCopy('presentations');
eleventyConfig.addPassthroughCopy('schemas/**/*.json');
eleventyConfig.addPassthroughCopy('site.css');
eleventyConfig.addPassthroughCopy('spec/LICENSE.md');
for(const draft of drafts) {
eleventyConfig.addPassthroughCopy(`spec/${draft}`);
}
eleventyConfig.addPassthroughCopy('static');
eleventyConfig.addPassthroughCopy('test-suite');
eleventyConfig.ignores.add('CONTRIBUTING.md');
eleventyConfig.ignores.add('LICENSE.md');
eleventyConfig.ignores.add('README.md');
eleventyConfig.ignores.add('benchmarks/README.md');
eleventyConfig.ignores.add('contexts/person.html');
eleventyConfig.ignores.add('examples');
eleventyConfig.ignores.add('images/Makefile');
eleventyConfig.ignores.add('images/README.md');
eleventyConfig.ignores.add('minutes/**/*');
eleventyConfig.ignores.add('ns/json-ld.html');
eleventyConfig.ignores.add('playground/dev/README.md');
eleventyConfig.ignores.add('presentations');
eleventyConfig.ignores.add('scripts');
eleventyConfig.ignores.add('spec/tools');
eleventyConfig.ignores.add('spec/LICENSE.md');
for(const draft of drafts) {
eleventyConfig.ignores.add(`spec/${draft}`);
}
eleventyConfig.ignores.add('test-suite');
// setup development proxy to cloudflare pages function server
if(process.env.ELEVENTY_RUN_MODE === 'serve') {
eleventyConfig.setServerOptions({
onRequest: {
'/playground/proxy': playgroundProxy
}
});
}
};
// proxy to worker proxy
async function playgroundProxy({url}) {
const targetUrl = url.searchParams.get('url');
// eleventy only provides the URL
// approximate what the live playground does
const search = new URLSearchParams();
search.set('url', targetUrl);
const proxyUrl =
new URL(`${PLAYGROUND_PROXY_HOST}/playground/proxy?${search}`);
const res = await fetch(proxyUrl, {
headers: {
'Accept': 'application/ld+json, application/json'
}
});
// create headers object and filter properties
// suffient for the site development purposes
const headers = Object.fromEntries(
Array.from(res.headers.entries()).filter(
v => !['content-length', 'content-encoding'].includes(v[0])));
return {
status: res.status,
headers,
body: await res.text()
}
}