5 const main = document.getElementById('main')
6 const aside = document.getElementById('aside')
7 const progress = document.getElementById('progress')
8 const progressCounter = Progress(sites.map(site => site.wiki))
9 const authors = new Set()
10 const terms = new Set()
12 const storeEntry = (author, url, parent, cat, entry) => {
13 if (!(parent in entries)) {
15 entries[parent][cat] = [{ entry, author, url }]
16 } else if (!(cat in entries[parent])) {
17 entries[parent][cat] = [{ entry, author, url }]
19 entries[parent][cat].push({ entry, author, url })
25 const storeEntries = (author, url, parent, entries) => {
26 Array.isArray(entries)
27 ? storeEntry(author, url, parent, 'list-definitions', entries)
28 : Object.keys(entries).forEach(entry => storeEntry(author, url, parent, entry, entries[entry]))
31 const transform = (author, url, ndtl) => {
32 Object.keys(ndtl).forEach(cat => storeEntries(author, url, cat, ndtl[cat]))
35 const parse = (site, content) => {
36 console.log('Wiki', 'Parsing ' + site.wiki)
37 const ndtl = indental(content)
38 transform(site.author, site.url, ndtl)
41 const selected = (key, category) => key.toLowerCase() === category.toLowerCase()
45 const randomTerm = () => {
46 const keys = Object.keys(entries)
47 return keys[Math.floor(Math.random() * keys.length)]
50 const formatSideBarCat = (key, entries) => (currentHtml, cat) => {
51 const catLength = Object.keys(entries[cat]).length
52 const newHtml = `<li class='${selected(key, cat)}'}'>
53 <a href='#${cat}' data-msgs='${catLength}'>${cat.toLowerCase()}</a>
55 return `${currentHtml}${newHtml}`
58 const formatEntry = (definitions, definition) => {
59 const formatEntryList = entryList => entryList.reduce((items, item) => `${items}<li>${item}</li>`, '')
61 const newHtml = typeof definition.entry === 'string'
62 ? `<li>${definition.entry}
63 - <a class='author' target='_blank' href='${definition.url}'> @${definition.author}</a>
65 : `<li><ul>${formatEntryList(definition.entry)}
66 <a class='author' target='_blank' href='${definition.url}'> — @${definition.author}</a>
69 return `${definitions}${newHtml}`
72 const formatEntries = entries => (currentHtml, category) => {
73 const definitions = entries[category].reduce(formatEntry, '')
74 const title = category === 'list-definitions'
76 : `<li class='name'><strong>${category.toLowerCase()}</strong></li>`
77 return `${currentHtml}<ul class='term'>${title}${definitions}</ul>`
80 const findRelated = key => {
81 const searchOtherCategories = entry => {
82 return Object.keys(entries)
83 .filter(category => Object.keys(entries[category]).some(otherCat => otherCat === entry))
86 const foundMatches = Object.keys(entries[key])
87 .filter(entry => entry !== 'list-definitions')
88 .map(searchOtherCategories)
89 const flattened = [].concat.apply([], foundMatches)
90 return Array.from(new Set(flattened)).filter(related => related !== key)
93 const formatRelated = (allRelated, relatedCategory) => {
94 const newHtml = `<span><a href='#${relatedCategory}'>/${relatedCategory.toLowerCase()}</a> </span>`
95 return `${allRelated}${newHtml}`
98 const refresh = key => {
100 if (entries[key] === undefined) return
101 const items = Object.keys(entries[key]).sort().reduce(formatEntries(entries[key]), '')
102 const relatedCategories = findRelated(key)
103 const relatedHtml = relatedCategories.length > 0
104 ? relatedCategories.reduce(formatRelated, 'Related categories: ')
106 main.innerHTML = `<div class='related'><h1>${key}</h1>${relatedHtml}</div>${items}`
108 const html = `Click a /topic to get started, or try a <a href='#${randomTerm()}'>random page</a>`
109 const stats = `The wiki contains ${terms.size} terms in ${Object.keys(entries).length} categories, from ${authors.size} authors.`
110 main.innerHTML = `<h1>WIKI</h1>${html}<br />${stats}`
113 const homeCat = `<li class='${selected(key, '')}'>
114 <a href='#' data-msgs='${terms.size}'>home</a>
116 const cats = Object.keys(entries).sort().reduce(formatSideBarCat(key, entries), homeCat)
117 aside.innerHTML = `<ul>${cats}</ul>`
120 const refreshProgress = () => {
121 progress.innerHTML = progressCounter.render()
125 initialize: hash => {
126 console.log('Wiki', 'Fetching...')
128 sites.filter(site => site.wiki && site.author).forEach(site => {
129 fetch(site.wiki, { cache: 'no-store' }).then(x => x.text()).then(content => {
131 refresh(stripHash(hash))
132 progressCounter.success(site.wiki).then(refreshProgress)
134 console.warn(`${site.wiki}`, err)
135 progressCounter.failure(site.wiki).then(refreshProgress)
139 refresh: key => { refresh(key) }
143const stripHash = hash => {
144 const decoded = decodeURIComponent(hash)
145 return decoded.charAt(0) === '#' ? decoded.substring(1) : decoded
148window.addEventListener('hashchange', () => {
149 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