-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathPWASidebar.ejs
122 lines (109 loc) · 4.22 KB
/
PWASidebar.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<%
const sidebar = {
sidebarURL: "/docs/Web/Progressive_web_apps",
sections: [
{
name: "/docs/Web/Progressive_web_apps/Guides",
contents: [
"/docs/Web/Progressive_web_apps/Guides/What_is_a_progressive_web_app",
"/docs/Web/Progressive_web_apps/Guides/Installing",
"/docs/Web/Progressive_web_apps/Guides/Making_PWAs_installable",
"/docs/Web/Progressive_web_apps/Guides/Offline_and_background_operation",
"/docs/Web/Progressive_web_apps/Guides/Caching",
"/docs/Web/Progressive_web_apps/Guides/Best_practices",
],
},
{
name: "/docs/Web/Progressive_web_apps/Tutorials",
contents: [
{
name: "/docs/Web/Progressive_web_apps/Tutorials/CycleTracker",
contents: [
"/docs/Web/Progressive_web_apps/Tutorials/CycleTracker",
"/docs/Web/Progressive_web_apps/Tutorials/CycleTracker/HTML_and_CSS",
"/docs/Web/Progressive_web_apps/Tutorials/CycleTracker/Secure_connection",
"/docs/Web/Progressive_web_apps/Tutorials/CycleTracker/JavaScript_functionality",
"/docs/Web/Progressive_web_apps/Tutorials/CycleTracker/Manifest_file",
"/docs/Web/Progressive_web_apps/Tutorials/CycleTracker/Service_workers",
],
},
{
name: "/docs/Web/Progressive_web_apps/Tutorials/js13kGames",
contents: [
"/docs/Web/Progressive_web_apps/Tutorials/js13kGames",
"/docs/Web/Progressive_web_apps/Tutorials/js13kGames/App_structure",
"/docs/Web/Progressive_web_apps/Tutorials/js13kGames/Offline_Service_workers",
"/docs/Web/Progressive_web_apps/Tutorials/js13kGames/Installable_PWAs",
"/docs/Web/Progressive_web_apps/Tutorials/js13kGames/Re-engageable_Notifications_Push",
"/docs/Web/Progressive_web_apps/Tutorials/js13kGames/Loading",
],
},
],
},
{
name: "/docs/Web/Progressive_web_apps/How_to",
contents: [
"/docs/Web/Progressive_web_apps/How_to/Trigger_install_prompt",
"/docs/Web/Progressive_web_apps/How_to/Define_app_icons",
"/docs/Web/Progressive_web_apps/How_to/Create_a_standalone_app",
"/docs/Web/Progressive_web_apps/How_to/Customize_your_app_colors",
"/docs/Web/Progressive_web_apps/How_to/Display_badge_on_app_icon",
"/docs/Web/Progressive_web_apps/How_to/Expose_common_actions_as_shortcuts",
"/docs/Web/Progressive_web_apps/How_to/Share_data_between_apps",
"/docs/Web/Progressive_web_apps/How_to/Associate_files_with_your_PWA",
],
},
{
name: "/docs/Web/Progressive_web_apps/Reference",
contents: [],
},
]
};
function getLink(pageSlug) {
return `/${env.locale}${pageSlug}`;
}
async function getTitle(pageSlug) {
let page = await wiki.getPage(getLink(pageSlug));
if (!page.title) {
page = await wiki.getPage(`/en-US${pageSlug}`);
}
const title = page.short_title || page.title;
return mdn.htmlEscape(title);
}
async function renderRootItem(item) {
return `<li><a href="${getLink(item)}"><strong>${await getTitle(item)}</strong></a></li>`
}
async function renderItem(item) {
let output = "";
if (typeof item === "string") {
output += `<li><a href="${getLink(item)}">${await getTitle(
item
)}</a></li>`;
} else {
output += `<li><ol>${await renderSubsection(item)}</ol></li>`;
}
return output;
}
async function renderSubsection(subsection) {
let output = `<li><details><summary>${await getTitle(
subsection.name
)}</summary><ol>`;
output += (await Promise.all(subsection.contents.map(item => renderItem(item)))).join('');
output += "</ol></details></li>";
return output;
}
async function renderSection(section) {
let output = await renderRootItem(section.name);
output += (await Promise.all(section.contents.map(item => renderItem(item)))).join('');
return output;
}
async function renderSidebar() {
let output = '<section id="Quick_links" data-macro="PWASidebar"><ol>';
output += await renderRootItem(sidebar.sidebarURL);
output += (await Promise.all(sidebar.sections.map(section => renderSection(section)))).join('');
output += "</ol></section>";
return output;
}
const output = await renderSidebar();
%>
<%-output%>