-
Notifications
You must be signed in to change notification settings - Fork 515
/
Copy pathWebExtAllExamples.ejs
76 lines (61 loc) · 1.99 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
68
69
70
71
72
73
74
75
76
<%
/*
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/main/";
const allExamples = await MDN.fetchWebExtExamples();
const lang = env.locale;
const s_name = mdn.localString({
"de": "Name",
"en-US": "Name",
"zh-CN": "名称",
"zh-TW": "名稱",
});
const s_desc = mdn.localString({
"de": "Beschreibung",
"en-US": "Description",
"zh-CN": "描述",
"zh-TW": "描述",
});
const s_javascript_apis = mdn.localString({
"de": "JavaScript APIs",
"en-US": "JavaScript APIs",
"zh-CN": "JavaScript API",
"zh-TW": "JavaScript API",
});
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 %>