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'); fetch("./forest.json") .then((res) => res.json()) .then((data) => { 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 = (addr) => { const item = data[addr] return item.tags ? item.tags.includes('top') : false } const addItemToSection = (addr, section, icon) => { const item = data[addr] const title = item.taxon ? (item.title ? `${item.taxon}. ${item.title}` : item.taxon) : (item.title ? item.title : "Untitled") const fullTitle = `${title} [${addr}]` items.push({ id: addr, title: fullTitle, section: section, icon: icon, handler: () => { window.location.href = item.route } }) } const [top, rest] = partition(Object.keys(data), isTopTree) top.forEach((addr) => addItemToSection(addr, "Top Trees", bookmarkIcon)) rest.forEach((addr) => addItemToSection(addr, "All Trees", null)) ninja.data = items });