import 'ninja-keys'; import 'katex'; import autoRenderMath from 'katex/contrib/auto-render'; function partition(array, isValid) { return array.reduce(([pass, fail], elem) => { return isValid(elem) ? [[...pass, elem], fail] : [pass, [...fail, elem]]; }, [[], []]); } window.addEventListener("load", (event) => { autoRenderMath(document.body) const openAllDetailsAbove = elt => { while (elt != null) { if (elt.nodeName == 'DETAILS') { elt.open = true } elt = elt.parentNode; } } const jumpToSubtree = evt => { if (evt.target.tagName === "A") { return; } const link = evt.target.closest('span[data-target]') const selector = link.getAttribute('data-target') const tree = document.querySelector(selector) openAllDetailsAbove(tree) window.location = selector } [...document.querySelectorAll("[data-target^='#']")].forEach( el => el.addEventListener("click", jumpToSubtree) ); const ninja = document.querySelector('ninja-keys'); const baseUrl = document.querySelector('html').getAttribute('data-base-url') const jsonUrl = `${baseUrl}forest.json` fetch(jsonUrl) .then((res) => res.json()) .then((trees) => { const items = [] const editIcon = '' const bookmarkIcon = '' if (window.sourcePath) { items.push({ id: 'edit', title: 'Edit current tree in Visual Studio Code', section: 'Commands', hotkey: 'cmd+e', icon: editIcon, handler: () => { window.location.href = `vscode://file/${window.sourcePath}` } }) } const isTopTree = (item) => { return item.tags ? item.tags.includes('top') : false } const addItemToSection = (item, section, icon) => { const title = item.taxon ? (item.title ? `${item.taxon}. ${item.title}` : item.taxon) : (item.title ? item.title : "Untitled") const fullTitle = `${title} [${item.uri}]` items.push({ id: item.uri, title: fullTitle, section: section, icon: icon, handler: () => { window.location.href = item.route } }) } const [top, rest] = partition(trees, isTopTree) top.forEach((item) => addItemToSection(item, "Top Trees", bookmarkIcon)) rest.forEach((item) => addItemToSection(item, "All Trees", null)) ninja.data = items }); });