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'
15 this._footer = document.createElement('p')
16 this._footer.id = 'footer'
17 this._footer.innerHTML = `The <strong>Wiki</strong> is a decentralized encyclopedia, to join the conversation, add a <a href="https://github.com/XXIIVV/webring#joining-the-wiki">wiki:</a> field to your entry in the <a href="https://github.com/XXIIVV/Webring/">webring</a>.`
24 this.install = (host) => {
25 this._el.appendChild(this._entry)
26 this._sidebar.appendChild(this._categories)
27 this._el.appendChild(this._sidebar)
28 this._el.appendChild(this._footer)
29 host.appendChild(this._el)
34 this._entry.innerHTML = 'Loading..'
37 this.refresh = () => {
40 if (this.byCat[this.loc]) {
41 const formatHtml = (entries, entry) => `${entries} ${this.templateTerm(entry.name, this.byName[entry.name])}<br />`
42 const html = this.byCat[this.loc].reduce(formatHtml, '')
43 this._entry.innerHTML = html
44 } else if (this.byName[this.loc]) {
45 const html = `${this.templateTerm(this.loc, this.byName[this.loc])}<br />${this.templateRelated(this.loc)}`
46 this._entry.innerHTML = html
48 const html = `Unknown: ${this.loc}. Retun <a onclick='wiki.go("")'>home</a>, or try a <a onclick='wiki.go("${this.random()}")'>random page</a>.`
49 this._entry.innerHTML = html
52 const random = this.random()
53 this._entry.innerHTML = `Click a /topic to get started, or try a <a href='#${random.toUrl()}' onclick='wiki.go("${random}")'>random page</a>.<br />The wiki contains ${Object.keys(this.byName).length} terms, in ${Object.keys(this.byCat).length} categories, by ${Object.keys(this.byAuthor).length} authors.`
56 this._categories.innerHTML = Object.keys(this.byCat).reduce((acc, id) => { return this.byCat[id].length > 5 ? `${acc}<li onclick='wiki.go("${id}")' class='${wiki.at(id) ? 'selected' : ''}'>${id.substr(0, 20)} <span class='right'>${this.byCat[id].length}</span></li>` : acc }, `<li onclick='wiki.go("")' class='${wiki.at() ? 'selected' : ''}'>home <span class='right'>${Object.keys(this.byName).length}</span></li>`)
59 this.go = (q = window.location.hash.substr(1).replace(/\+/g, ' ').toUpperCase()) => {
61 window.location.hash = q.toUrl()
65 this.at = (q = '') => {
66 return this.loc.toUpperCase() === q.toUpperCase() || (this.cat(this.loc).toUpperCase() === q.toUpperCase() && q !== '')
70 const keys = Object.keys(this.byCat)
71 return keys[Math.floor(Math.random() * keys.length)]
74 this.related = (name) => {
75 return this.byCat[this.cat(name)]
78 this.cat = (name) => {
79 return this.byName[name] ? this.byName[name][0].cat : ''
82 this.templateRelated = (name) => {
83 const relatedWords = this.related(name)
84 const html = `<ul class='col3'>${relatedWords.reduce((acc, item, id) => { return `${acc}<li onclick='wiki.go("${item.name}")' class='${wiki.at(item.name) ? 'selected' : ''}'>${item.name.toLowerCase()}</li>` }, '')}</ul>`
88 this.templateTerm = (name, entries) => {
89 const formatEntry = (acc, entry) => {
90 if (typeof entry.value === 'string') {
91 return `${acc}<li>${entry.value}<a class='author' target='_blank' href='${entry.origin.url}'> — @${entry.origin.author}</a></li>`
93 const listItems = entry.value.reduce((items, item) => `${items}<li>${item}</li>`)
94 return `${acc}<li><ul>${listItems}<a class='author' target='_blank' href='${entry.origin.url}'> — @${entry.origin.author}</a></ul></li>`
98 const htmlEntries = entries.reduce(formatEntry, '')
99 return `<ul class="term"><li class="name"><strong>${name.toLowerCase()}</strong></li>${htmlEntries}</ul>`
103 console.log('Wiki', 'Fetching..')
104 for (const site of sites) {
105 if (!site.wiki || !site.author) { continue }
106 fetch(site.wiki, { cache: 'no-store' }).then(x => x.text()).then((content) => {
107 this.parse(site, content)
110 console.warn(`${site.wiki}`, err)
115 this.add = (name, value, cat, origin) => {
116 this.byName[name] = this.byName[name] || []
117 this.byName[name].push({ name, value, cat, origin })
119 this.byCat[cat] = this.byCat[cat] || []
120 this.byCat[cat].push({ name, value, cat, origin })
122 this.byAuthor[origin.author] = this.byAuthor[origin.author] || []
123 this.byAuthor[origin.author].push({ name, value, cat, origin })
126 this.parse = (site, content) => {
127 console.log('Wiki', 'Parsing ' + site.wiki)
128 const cats = indental(content)
129 for (const cat in cats) {
130 const terms = cats[cat]
131 for (const name in terms) {
132 this.add(name, terms[name], cat, site)
137 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