-
Notifications
You must be signed in to change notification settings - Fork 509
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): create a PWA sidebar #8238
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1701931
Create a PWA sidebar
wbamberg 1d9dd64
Fix case for sidebar URL
wbamberg 301b902
Update kumascript/macros/PWASidebar.ejs
wbamberg 9b044f2
Update kumascript/macros/PWASidebar.ejs
wbamberg fa543f4
Fix suggestion
wbamberg 5ff767a
Merge remote-tracking branch 'upstream/main' into pwa-sidebar
wbamberg 46aba1c
Update for current page set
wbamberg d93a7fe
Use fully qualified slugs
wbamberg 72a49b5
Review comments (refactoring)
wbamberg 8ac094f
Formatting
wbamberg c6e4b77
Remove trailing slash
wbamberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<% | ||
|
||
const sidebar = { | ||
sidebarURL: "/docs/Web/Progressive_web_apps/", | ||
sections: [ | ||
{ | ||
name: "/docs/Web/Progressive_web_apps/Guides", | ||
contents: [ | ||
"/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/Structural_overview", | ||
], | ||
}, | ||
{ | ||
name: "/docs/Web/Progressive_web_apps/Tutorials", | ||
contents: [ | ||
{ | ||
name: "/docs/Web/Progressive_web_apps/Tutorials/js13kGames", | ||
contents: [ | ||
"/docs/Web/Progressive_web_apps/Tutorials/js13kGames/Introduction", | ||
"/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/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", | ||
], | ||
}, | ||
{ | ||
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%> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing slash: