Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(macros/DefaultAPISidebar): add Tutorial section #7646

Merged
merged 5 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions kumascript/macros/DefaultAPISidebar.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var text = {
'Events': mdn.getLocalString(commonl10n, 'Events'),
'Interfaces': mdn.getLocalString(commonl10n, 'Interfaces'),
'Guides': mdn.getLocalString(commonl10n, 'Guides'),
'Tutorial': mdn.getLocalString(commonl10n, 'Tutorial'),
'translate': mdn.getLocalString(commonl10n, '[Translate]'),
'title': mdn.getLocalString(commonl10n, 'TranslationCTA'),
};
Expand All @@ -35,14 +36,10 @@ var methods = webAPIGroups[0][group].methods || [];
var properties = webAPIGroups[0][group].properties || [];
var events = webAPIGroups[0][group].events || [];
var groupGuides = webAPIGroups[0][group].guides || [];
var guides = [];
var groupTutorial = webAPIGroups[0][group].tutorial || [];

for (let guideUrl of groupGuides) {
const page = await wiki.getPage(guideUrl);
if (page && page.url) {
guides.push(page);
}
}
var guides = await wiki.getPages(...groupGuides);
var tutorial = await wiki.getPages(...groupTutorial);

function buildSublist(pages, title) {
var result = '<li class="toggle"><details open><summary>' + title + '</summary><ol>';
Expand Down Expand Up @@ -112,6 +109,10 @@ if (guides.length > 0) {
output += buildSublist(guides, text['Guides']);
}

if (tutorial.length > 0) {
output += buildSublist(tutorial, text['Tutorial']);
}

interfaces = interfaces.map(convert);
if (interfaces.length > 0) {
output += buildIFList(interfaces, text['Interfaces']);
Expand Down
11 changes: 10 additions & 1 deletion kumascript/src/api/wiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,16 @@ const wiki = {
return adjustHeadings(result, section, show || 0, heading);
},

// Returns the page object for the specified page.
// Returns all page objects for the specified page paths.
async getPages(this: KumaThis, ...paths: string[]) {
const pages = await Promise.all(
paths.map((path) => (this.wiki as any).getPage(path))
);

return pages.filter((page) => page && page.url);
},

// Returns the page object for the specified page path.
getPage(this: KumaThis, path) {
return this.info.getPageByURL(path || this.env.url);
},
Expand Down