This repository has been 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 pathListGroups.ejs
103 lines (78 loc) · 2.52 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<%
// 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.
var locale = env.locale;
var APIHref = '/' + locale + '/docs/Web/API';
var output = '';
// Conveniences to shorten names of some functions
var htmlEscape = kuma.htmlEscape;
var spacesToUnderscores = web.spacesToUnderscores;
// Get the GroupData database
var groupData = string.deserialize(template('GroupData'))[0];
var groupNames = Object.keys(groupData);
groupNames.sort();
function containsTag(tagList, tag) {
var ret = false;
if (!tagList || tagList == undefined) {
return 0;
}
tag = tag.toLowerCase();
tagList.forEach(function(t) {
if (t.toLowerCase() === tag) {
ret = true;
}
});
return ret;
}
// Start building the lists for each letter
var outputByLetter = [];
groupNames.forEach(function(name, idx, arr) {
var groupObj = groupData[name];
var firstLetter = name[0];
var groupOutput = '';
var overviewName = name;
var badge = "";
if (groupObj.hasOwnProperty("overview")) {
overviewName = groupObj.overview;
}
var groupUrl = APIHref + "/" + spacesToUnderscores(htmlEscape(overviewName));
var page = wiki.getPage(groupUrl);
// Go through the tags and build badges if there are any to add
if (page && page != undefined) {
var tags = page.tags;
if (tags) {
if (containsTag(tags, "Non-standard") || containsTag(tags, "Non standard")) {
badge = " " + template("NonStandardBadge", ["1"]);
}
if (containsTag(tags, "Obsolete")) {
badge += " " + template("ObsoleteBadge", [1]);
} else if (containsTag(tags, "Deprecated")) {
badge += " " + template("DeprecatedBadge", [1]);
}
if (containsTag(tags, "Experimental")) {
badge += " " + template("ExperimentalBadge", [1]);
}
if (badge.length) {
badge = "<span class='indexListBadges'>" + badge + "</span>";
}
}
}
// Finish constructing the HTML and then append it to the text for the corresponding
// letter group.
var groupOutput = "<li><a href='" + groupUrl + "'>" + name + "</a>" + badge + "</li>";
if (!outputByLetter[firstLetter]) {
outputByLetter[firstLetter] = groupOutput;
} else {
outputByLetter[firstLetter] += groupOutput;
}
});
// Now output the whole thing
var keys = Object.keys(outputByLetter);
keys.forEach(function(letter, idx, arr) {
output += "<span>" + letter + "</span><ul>" + outputByLetter[letter] + "</ul>";
});
%><div class="index">
<%-output%>
</div>