5 const main = document.getElementById('main')
6 const aside = document.getElementById('aside')
7 const authors = new Set()
8 const terms = new Set()
10 const storeEntry = (author, url, parent, cat, entry) => {
11 if (!(parent in entries)) {
13 entries[parent][cat] = [{ entry, author, url }]
14 } else if (!(cat in entries[parent])) {
15 entries[parent][cat] = [{ entry, author, url }]
17 entries[parent][cat].push({ entry, author, url })
23 const storeEntries = (author, url, parent, entries) => {
24 Array.isArray(entries)
25 ? storeEntry(author, url, parent, 'list-definitions', entries)
26 : Object.keys(entries).forEach(entry => storeEntry(author, url, parent, entry, entries[entry]))
29 const transform = (author, url, ndtl) => {
30 Object.keys(ndtl).forEach(cat => storeEntries(author, url, cat, ndtl[cat]))
33 const parse = (site, content) => {
34 console.log('Wiki', 'Parsing ' + site.wiki)
35 const ndtl = indental(content)
36 transform(site.author, site.url, ndtl)
39 const selected = (key, category) => key.toLowerCase() === category.toLowerCase()
43 const formatSideBarCat = (key, entries) => (currentHtml, cat) => {
44 const catLength = Object.keys(entries[cat]).length
45 const newHtml = `<li class='${selected(key, cat)}'}'>
46 <a href='#${cat}' data-msgs='${catLength}'>${cat.toLowerCase()}</a>
48 return `${currentHtml}${newHtml}`
51 const formatEntry = (definitions, definition) => {
52 const formatEntryList = entryList => entryList.reduce((items, item) => `${items}<li>${item}</li>`, '')
54 const newHtml = typeof definition.entry === 'string'
55 ? `<li>${definition.entry}
56 <a class='author' target='_blank' href='${definition.url}'> - @${definition.author}</a>
58 : `<li><ul>${formatEntryList(definition.entry)}
59 <a class='author' target='_blank' href='${definition.url}'> — @${definition.author}</a>
62 return `${definitions}${newHtml}`
65 const formatEntries = entries => (currentHtml, category) => {
66 const definitions = entries[category].reduce(formatEntry, '')
67 const title = category === 'list-definitions'
69 : `<li class='name'><strong>${category.toLowerCase()}</strong></li>`
70 return `${currentHtml}<ul class='term'>${title}${definitions}</ul>`
73 const findRelated = key => {
74 const searchOtherCategories = entry => {
75 return Object.keys(entries)
76 .filter(category => Object.keys(entries[category]).some(otherCat => otherCat === entry))
79 const foundMatches = Object.keys(entries[key])
80 .filter(entry => entry !== 'list-definitions')
81 .map(searchOtherCategories)
82 const flattened = [].concat.apply([], foundMatches)
83 return Array.from(new Set(flattened)).filter(related => related !== key)
86 const formatRelated = (allRelated, relatedCategory) => {
87 const newHtml = `<span><a href='#${relatedCategory}'>/${relatedCategory.toLowerCase()}</a> </span>`
88 return `${allRelated}${newHtml}`
91 const refresh = key => {
93 if (entries[key] === undefined) return
94 const items = Object.keys(entries[key]).sort().reduce(formatEntries(entries[key]), '')
95 const relatedCategories = findRelated(key)
96 const relatedHtml = relatedCategories.length > 0
97 ? relatedCategories.reduce(formatRelated, 'Related categories: ')
99 main.innerHTML = `<div class='related'><h1>${key}</h1>${relatedHtml}</div>${items}`
101 const html = `Click a /topic to get started, or try a random page`
102 const stats = `The wiki contains ${terms.size} terms in ${Object.keys(entries).length} categories, from ${authors.size} authors.`
103 main.innerHTML = `${html}<br />${stats}`
106 const homeCat = `<li class='${selected(key, '')}'>
107 <a href='#' data-msgs='${terms.size}'>home</a>
109 const cats = Object.keys(entries).sort().reduce(formatSideBarCat(key, entries), homeCat)
110 aside.innerHTML = `<ul>${cats}</ul>`
114 initialize: hash => {
115 console.log('Wiki', 'Fetching...')
116 sites.filter(site => site.wiki && site.author).forEach(site => {
117 fetch(site.wiki, { cache: 'no-store' }).then(x => x.text()).then(content => {
119 refresh(stripHash(hash))
121 console.warn(`${site.wiki}`, err)
125 refresh: key => { refresh(key) }
129const stripHash = hash => {
130 const decoded = decodeURIComponent(hash)
131 return decoded.charAt(0) === '#' ? decoded.substring(1) : decoded
134window.addEventListener('hashchange', () => {
135 wiki.refresh(stripHash(window.location.hash).toUpperCase())
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list