This repository was archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathWebExtAllExamples.ejs
67 lines (52 loc) · 1.85 KB
/
WebExtAllExamples.ejs
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
<%
/*
The "examples.json" file from the https://github.com/mdn/webextensions-examples
repository contains information about the examples living in that repository.
This macro loads the "examples.json" file and uses it to build a table
presenting that information.
For example, the page at https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Examples
is generated using this macro.
*/
const examplesBaseUrl = "https://github.com/mdn/webextensions-examples/tree/master/";
const allExamples = await MDN.fetchJSONResource("https://raw.githubusercontent.com/mdn/webextensions-examples/master/examples.json");
const lang = env.locale;
const s_name = mdn.localString({
"en-US": "Name"
});
const s_desc = mdn.localString({
"en-US": "Description"
});
const s_javascript_apis = mdn.localString({
"en-US": "JavaScript APIs"
});
const s_webextension_api_path = mdn.localString({
"en-US": "Add-ons/WebExtensions/API"
});
function writeJavaScriptAPIs(apisJSON) {
let output = "";
for (let jsAPI of apisJSON) {
var link = `/${lang}/${s_webextension_api_path}/${jsAPI.replace(".", "/")}`;
output += `<a href="${link}"><code>${jsAPI}</code></a><br/>`;
}
return output;
}
function writeAllExamples(examples) {
let output = "<table class=\"standard-table fullwidth-table\">";
output += `<tr>
<th>${s_name}</th>
<th>${s_desc}</th>
<th style=\"width: 40%\">${s_javascript_apis}</th>
</tr>`;
for (let example of examples) {
output += `<tr>`;
output += ` <td><a href="${examplesBaseUrl + example.name}">${example.name}</a></td>`;
output += ` <td>${example.description}</td>`;
output += ` <td>${writeJavaScriptAPIs(example.javascript_apis)}</td>`;
output += `</tr>`;
}
output += "</table>";
return output;
}
var output = writeAllExamples(allExamples);
%>
<%- output %>