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

Write JS snippet that generates JSON representation of website menu #1179

Closed
eecavanna opened this issue Mar 8, 2024 · 4 comments
Closed
Assignees
Labels
X SMALL Less than 1 day

Comments

@eecavanna
Copy link
Collaborator

eecavanna commented Mar 8, 2024

This is to facilitate future attempts to synchronize the data portal's menu with the website's menu.

This snippet could be copy/pasted into the JavaScript console of a web browser when viewing the website.

Here's an example of an issue where the task was to do that synchronization: #1152

@eecavanna eecavanna added X SMALL Less than 1 day backlog Issues not assigned to a sprint or not finished during a sprint. Needs to be reprioritized. labels Mar 8, 2024
@eecavanna eecavanna self-assigned this Mar 8, 2024
@eecavanna eecavanna changed the title Write a JavaScript snippet that generates JSON representation of website menu Write JS snippet that generates JSON representation of website menu Mar 8, 2024
@eecavanna
Copy link
Collaborator Author

eecavanna commented Mar 9, 2024

Here's a snippet that gets "99% of the way there." All that's missing is:

  • This produces output that uses double quotes instead of single quotes
  • This includes href values even for menu items that link to #
// Usage: Copy/paste into a web browser's JavaScript console and press [ENTER].
(function showMenuAsJSON() {
  const arr = [];

  // For each drop-down menu:
  document.querySelectorAll(".header-nav-item").forEach((col, colIdx) => {
    // Add a top-level element (having no `items` yet) to the result array, for the top-level link.
    const a = col.querySelectorAll("a:first-child")[0];
    arr.push({ label: a.title, href: a.href, items: [] });

    // For each link in this drop-down menu, add an item to this column's `items` array.
    col.querySelectorAll(".header-dropdown > a").forEach((a) => {
      arr[colIdx].items.push({ label: a.title, href: a.href });
    });
  });

  console.log(JSON.stringify(arr, null, 2));
})();

This can already be used for "sanity checks."

@eecavanna
Copy link
Collaborator Author

eecavanna commented Mar 12, 2024

Tasks remaining until done:

  • Update snippet result to use single quotes instead of double quotes (to match web/src/menus.ts)
  • Add this snippet to some document within the repository (e.g. a document about maintaining web/src/menus.ts)

@eecavanna eecavanna moved this from In Review to In Progress in 2024 - Sprint 32 - March 11 - March 22, 2024 Mar 12, 2024
@eecavanna eecavanna removed the backlog Issues not assigned to a sprint or not finished during a sprint. Needs to be reprioritized. label Mar 12, 2024
@eecavanna
Copy link
Collaborator Author

With respect to the second bullet point: I plan to document this snippet in the wiki.

@eecavanna
Copy link
Collaborator Author

The snippet has been documented here: https://github.com/microbiomedata/nmdc-server/wiki/Maintaining-the-navigation-menu

Closing this ticket as done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
X SMALL Less than 1 day
Projects
No open projects
Development

No branches or pull requests

1 participant