-
Notifications
You must be signed in to change notification settings - Fork 513
/
ListGroups.ejs
70 lines (51 loc) · 1.84 KB
/
ListGroups.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
<%
// ListGroups
//
// Generates a list of each group (API) from the GroupData JSON and
// returns it. This can be used to create an index of APIs.
const locale = env.locale;
const APIHref = `/${locale}/docs/Web/API/`;
const defaultAPIHref = "/en-US/docs/Web/API/";
// Conveniences to shorten names of some functions
const htmlEscape = mdn.htmlEscape;
const spacesToUnderscores = web.spacesToUnderscores;
// Get the GroupData database
const groupData = web.getJSONData("GroupData")[0];
const groupNames = Object.keys(groupData);
groupNames.sort();
// Start building the lists for each letter
const outputByLetter = {};
for(const name of groupNames) {
const groupObj = groupData[name];
const firstLetter = name[0];
if (!groupObj.overview) {
continue;
}
const overviewName = groupObj.overview;
const subPath = spacesToUnderscores(htmlEscape(overviewName));
const defaultGroupUrl = defaultAPIHref + subPath;
const groupUrl = APIHref + subPath;
// Get page info from default locale
// as some pages are not localized yet
const aPage = await wiki.getPage(defaultGroupUrl);
let pageBadges = (await page.badges(aPage)).join(" ");
if (pageBadges.length) {
pageBadges = `<span class='indexListBadges'> ${pageBadges}</span>`;
}
// Finish constructing the HTML and then append it to the text for the corresponding
// letter group.
const link = web.smartLink(groupUrl, null, name, null, APIHref, "ListGroups");
const groupOutput = `<li>${link}${pageBadges}</li>`;
if (!outputByLetter[firstLetter]) {
outputByLetter[firstLetter] = groupOutput;
} else {
outputByLetter[firstLetter] += groupOutput;
}
}
// Now output the whole thing
const keys = Object.keys(outputByLetter);
const output = keys.map(letter => `<h3>${letter}</h3>
<ul>${outputByLetter[letter]}</ul>`).join("\n");
%><div class="index">
<%-output%>
</div>