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): create a PWA sidebar #8238

Merged
merged 11 commits into from
Apr 5, 2023
Merged

feat(macros): create a PWA sidebar #8238

merged 11 commits into from
Apr 5, 2023

Conversation

wbamberg
Copy link
Collaborator

@wbamberg wbamberg commented Feb 17, 2023

Summary

Adds a new sidebar for the PWA docs: https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps

Note: this PR needs to be merged alongside mdn/content#25888.

Problem

PWA docs don't have a usable sidebar.

Solution

This PR adds a new KS macro, PWASidebar, which implements a sidebar for the PWA docs, to support the PWA docs refresh project: mdn/mdn#280.

The sidebar implements the information architecture discussed in the PWA planning doc: https://docs.google.com/document/d/1-skaKXoJ0rKhgBHchTWSTAW5dxrlmVYkPeKUWpet9nE/edit?usp=sharing.

The sidebar is implemented as a model of how we could have JSON-driven sidebars, with a JSON structure defining the sidebar in mdn/content and a little code in Yari that builds a sidebar from that JSON. This would allow us to retire most of the KS sidebar macros (a few complex sidebars like DefaultAPISidebar would need to stay in KS for the time being).

Screenshots

Before

Screen Shot 2023-04-04 at 2 29 33 PM

After

Screen Shot 2023-04-04 at 2 30 17 PM


How did you test this change?

@github-actions github-actions bot added the macros tracking issues related to kumascript macros label Feb 17, 2023
@captainbrosset
Copy link
Contributor

Thanks a lot @wbamberg. Sadly I have no had the time to go through this.
By any chance, could you attach a screenshot of the sidebar here? I know that would help me a lot!

@wbamberg
Copy link
Collaborator Author

Sorry Patrick, I forget some people don't live inside this world :).

Not expanded:

Screen Shot 2023-02-20 at 11 21 12 AM

Expanded:

Screen Shot 2023-02-20 at 11 21 37 AM

The names for tutorials and tutorial steps are placeholders.

One thing worth mentioning is that when an item in the sidebar has a disclosure arrow, like "Your first PWA", (meaning it contains a group of connected subpages, like steps in a tutorial) it can't also be a link to a page (because clicking the label opens the subpages), so if we want an overview page for this we usually end up having that be the first child, like:

* Your first PWA
    * Your first PWA
    * Step 1
    * Step 2
    ...

...this is ugly and I wish we had a better answer here, but it's what we do everywhere.

@captainbrosset
Copy link
Contributor

This looks great.

A couple of thoughts:

  • Do we need to be concerned about the length of the sidebar? The How-to section is likely to contain 15 to 20 topics which, for now, would just be presented in one flat list.

  • What do you think should go under Reference? We discussed about creating a global PWA reference page which would contain links to all manifest, https, service worker, etc. things. Do you think we should also add a link to manifest, and service worker reference docs in the sidebar directly?

  • I'm not too worried about the fact that TOC nodes can't also be links. We have the same issue on learn.microsoft.com and I don't find this to be a big issue myself. At least, as a user, I'm not confused about whether I should read some intro content on the TOC node first, or expand it to find the first page inside of it. I see what you mean about having to repeat the title. But I'm sure we can find creative ways to avoid this:

    • Tutorials
      • Build a simple PWA
        • Get started
        • Add a manifest
        • Install the PWA
      • Build a more complex PWA

    The 2 tutorial names would have to be better than this, but the idea is to find a title for them.

@estelle
Copy link
Member

estelle commented Feb 21, 2023

this LGTM. I like the idea of nesting subcontent.

I assume, like on https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps/Getting_started, the current section would be open and hilited, and everything else will be closed, which I think will make this nav great UX as long as we don't have every other subject listed in the nav, like the learn section does :|

@wbamberg
Copy link
Collaborator Author

I assume, like on https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps/Getting_started, the current section would be open and hilited, and everything else will be closed, which I think will make this nav great UX as long as we don't have every other subject listed in the nav, like the learn section does :|

Yes - and if you try this sidebar out your should see that behavior.

@wbamberg
Copy link
Collaborator Author

wbamberg commented Feb 21, 2023

This looks great.

A couple of thoughts:

  • Do we need to be concerned about the length of the sidebar? The How-to section is likely to contain 15 to 20 topics which, for now, would just be presented in one flat list.

I think 15-20 is fine in a flat list, but if it looks too big we could create additional categories.

  • What do you think should go under Reference? We discussed about creating a global PWA reference page which would contain links to all manifest, https, service worker, etc. things. Do you think we should also add a link to manifest, and service worker reference docs in the sidebar directly?

I'd envisaged this is just one page with nothing under it, linking to the reference docs that live elsewhere. We could have links to say https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API direct from the sidebar, and maybe that would be good. We get a bit into sidebar philosophy though :) of whether sidebars should contain links to pages that themselves have a different sidebar. We do this sometimes on MDN, and it works fine now but rules out certain possible futures for sidebars (see https://github.com/orgs/mdn/discussions/124#discussioncomment-4578532 for example: it makes it much harder to use lists of links in sidebars as reusable bits of IA). But like I say, we do this already sometimes, so it is certainly possible.

kumascript/macros/PWASidebar.ejs Outdated Show resolved Hide resolved
kumascript/macros/PWASidebar.ejs Outdated Show resolved Hide resolved
Comment on lines 77 to 79
output += `<li><a href="${baseURL}${item}">${await getTitle(
item
)}</a></li>`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably makes sense to extract renderLink(), which determines both the href and the text.

If the page does not exist in the current locale, I think we'll want to add (en-US) behind, like web.smartlink() already does (I don't mind not using web.smartlink() for now, but we should extract all these helper methods somewhere before replicating them to another sidebar anyways).

kumascript/macros/PWASidebar.ejs Outdated Show resolved Hide resolved
@caugner caugner added the sidebar/toc Sidebar and table of contents label Mar 2, 2023
@caugner caugner changed the title Create a PWA sidebar feat(macros): create a PWA sidebar Mar 2, 2023
wbamberg and others added 5 commits April 3, 2023 11:48
Co-authored-by: Claas Augner <495429+caugner@users.noreply.github.com>
Co-authored-by: Claas Augner <495429+caugner@users.noreply.github.com>
* upstream/main: (251 commits)
  chore(deps-dev): bump typescript from 4.9.5 to 5.0.3 in /client/pwa (mdn#8547)
  chore(deps-dev): bump typescript from 4.9.5 to 5.0.3 (mdn#8543)
  chore(deps-dev): bump postcss-preset-env from 8.2.0 to 8.3.0 (mdn#8561)
  chore(deps-dev): bump @types/react from 18.0.31 to 18.0.32 (mdn#8560)
  chore(advertising): update copies (mdn#8562)
  fix(client): place hash before headings (mdn#8532)
  chore(deps-dev): bump ts-jest from 29.0.5 to 29.1.0 (mdn#8559)
  chore(deps-dev): bump black from 23.1.0 to 23.3.0 in /deployer (mdn#8555)
  chore(deps-dev): bump webpack-dev-server from 4.13.1 to 4.13.2 (mdn#8558)
  chore(deps-dev): bump swr from 2.1.1 to 2.1.2 (mdn#8556)
  chore(deps): bump boto3 from 1.26.99 to 1.26.104 in /deployer (mdn#8557)
  chore(deps-dev): bump black in /testing/integration (mdn#8554)
  ci(stage-build): rsync with -j html,json,txt (mdn#8549)
  ci(stage-build): rsync with -c (mdn#8548)
  chore(deps-dev): bump react-router and react-router-dom from 6.9.0 to 6.10.0 (mdn#8534)
  chore(deps-dev): bump @babel/preset-env from 7.20.2 to 7.21.4 (mdn#8544)
  chore(deps-dev): bump tailwindcss from 3.3.0 to 3.3.1 (mdn#8546)
  chore(deps): bump @mdn/browser-compat-data from 5.2.46 to 5.2.47 (mdn#8545)
  chore(deps-dev): bump @babel/core from 7.21.3 to 7.21.4 (mdn#8542)
  fix(docs): make icons in good/bad examples float (mdn#8531)
  ...
@wbamberg wbamberg marked this pull request as ready for review April 4, 2023 04:08
@wbamberg wbamberg requested a review from caugner April 4, 2023 04:08
@wbamberg
Copy link
Collaborator Author

wbamberg commented Apr 4, 2023

I've updated this sidebar with the new pages we've written, and to include the existing pages until we are ready to replace them all. I've also addressed review comments.

Overall structure here is pretty much the same as what we had before.

Details of the content changes are in mdn/content#25888. This PR needs to land with that one.

Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just two refactoring opportunities (+ one older comment regarding the (en-US) postfix).

Comment on lines 92 to 94
output += `<li><a href="${baseURL}"><strong>${await getTitle(
""
)}</strong></a></li>`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract this as renderRootItem() to describe what this does?

Comment on lines 96 to 98
for (const section of sections) {
output += await renderSection(section);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do the same as in line 59:

Suggested change
for (const section of sections) {
output += await renderSection(section);
}
output += (await Promise.all(sections.map(section => renderSection(section)))).join('');

@wbamberg wbamberg requested a review from caugner April 4, 2023 16:57
@wbamberg
Copy link
Collaborator Author

wbamberg commented Apr 4, 2023

LGTM, just two refactoring opportunities (+ one older comment regarding the (en-US) postfix).

Sorry, I forgot about the paths thing (I remembered much too late to add to this PR!). Much better this way.

Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one trailing slash that can probably be removed.

<%

const sidebar = {
sidebarURL: "/docs/Web/Progressive_web_apps/",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing slash:

Suggested change
sidebarURL: "/docs/Web/Progressive_web_apps/",
sidebarURL: "/docs/Web/Progressive_web_apps",

@caugner
Copy link
Contributor

caugner commented Apr 4, 2023

@wbamberg Now that this PR is no longer a draft, would you mind updating the PR description to follow our template? 🙌

@wbamberg wbamberg merged commit 26e1e35 into mdn:main Apr 5, 2023
10 checks passed
@caugner
Copy link
Contributor

caugner commented Apr 5, 2023

Awesome work, @captainbrosset and @wbamberg! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macros tracking issues related to kumascript macros sidebar/toc Sidebar and table of contents
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants