6 this._el = document.createElement('div')
8 this._sidebar = document.createElement('div')
9 this._sidebar.id = 'sidebar'
10 this._categories = document.createElement('ul')
11 this._categories.id = 'categories'
12 this._entry = document.createElement('div')
13 this._entry.id = 'entry'
19 this.install = (host) => {
20 console.log('Wiki', 'Installing..')
22 this._el.appendChild(this._entry)
23 this._sidebar.appendChild(this._categories)
24 this._el.appendChild(this._sidebar)
25 host.appendChild(this._el)
29 console.log('Wiki', 'Starting..')
30 this.loc = window.location.hash.substr(1).replace(/\+/g, ' ').toUpperCase()
31 // this.el.innerHTML = 'hello.'
34 this.refresh = () => {
35 console.log(Object.keys(this.index).length + ' terms')
38 if (this.categories[this.index]) {
39 let html = `term: ${this.loc}`
40 this._entry.innerHTML = html
41 } else if (this.categories[this.loc]) {
43 for (const id in this.categories[this.loc]) {
44 const name = this.categories[this.loc][id].name
45 html += `${this.templateTerm(name, this.index[name])}<br />`
47 this._entry.innerHTML = html
49 let html = `Unknown: ${this.loc}`
50 this._entry.innerHTML = html
53 this._entry.innerHTML = 'Click a /topic to get started.'
56 this._categories.innerHTML = Object.keys(this.categories).reduce((acc, id) => { return `${acc}<li onclick='wiki.go("${id}")' class='${wiki.at(id) ? 'selected' : ''}'>${id.substr(0, 20)} <span class='right'>${this.categories[id].length}</span></li>` }, '')
61 window.location.hash = q.toUrl()
65 this.at = (q = '') => {
66 return this.loc.toUpperCase() === q.toUpperCase()
69 this.templateTerm = (name, entry) => {
70 return '<ul class="term"><li class="name"><b>' + name.toLowerCase() + '</b></li>' + entry.reduce((acc, item) => { return `${acc}<li>${item.value} <a class='author' href='${item.origin.url}'> — @${item.origin.author}</a></li>` }, '') + '</ul>'
74 console.log('Wiki', 'Fetching..')
75 for (const site of sites) {
76 if (!site.wiki || !site.author) { continue }
77 fetch(site.wiki, { cache: 'no-store' }).then(x => x.text()).then((content) => {
78 this.parse(site, content)
81 console.warn(`${site.wiki}`, err)
86 this.add = (name, value, cat, origin) => {
87 if (!this.index[name]) {
90 this.index[name].push({ name, value, cat, origin })
91 if (!this.categories[cat]) {
92 this.categories[cat] = []
94 this.categories[cat].push({ name, value, cat, origin })
97 this.parse = (site, content) => {
98 console.log('Wiki', 'Parsing ' + site.wiki)
99 const cats = indental(this.filter(content))
100 for (const cat in cats) {
101 const terms = cats[cat]
102 for (const name in terms) {
103 this.add(name, terms[name], cat, site)
108 this.filter = (lines) => {
109 return lines.split('\n').filter((line) => { return line.indexOf(' = `') < 0 && line.trim().length > 1 }).join('\n')
111 String.prototype.toUrl = function () { return this.toLowerCase().replace(/ /g, '+').replace(/[^0-9a-z\+\:\-\.\/\~]/gi, '').trim() }
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