'use strict'
function Wiki (sites) {
const feeds = {}
this.sites = sites
this._el = document.createElement('div')
this._el.id = 'wiki'
this._sidebar = document.createElement('div')
this._sidebar.id = 'sidebar'
this._categories = document.createElement('ul')
this._categories.id = 'categories'
this._entry = document.createElement('div')
this._entry.id = 'entry'
this._footer = document.createElement('p')
this._footer.id = 'footer'
this._footer.innerHTML = `The Wiki is a decentralized encyclopedia, to join the conversation, add a wiki: field to your entry in the webring.`
this.loc = ''
this.byName = {}
this.byCat = {}
this.byAuthor = {}
this.install = (host) => {
this._el.appendChild(this._entry)
this._sidebar.appendChild(this._categories)
this._el.appendChild(this._sidebar)
this._el.appendChild(this._footer)
host.appendChild(this._el)
this.fetch()
}
this.start = () => {
this._entry.innerHTML = 'Loading..'
}
this.refresh = () => {
// Main
if (this.loc) {
if (this.byCat[this.loc]) {
let html = ''
for (const id in this.byCat[this.loc]) {
const name = this.byCat[this.loc][id].name
html += `${this.templateTerm(name, this.byName[name])}
`
}
this._entry.innerHTML = html
} else if (this.byName[this.loc]) {
let html = `${this.templateTerm(this.loc, this.byName[this.loc])}
${this.templateRelated(this.loc, this.byName[this.loc])}`
this._entry.innerHTML = html
} else {
let html = `Unknown: ${this.loc}. Retun home, or try a random page.`
this._entry.innerHTML = html
}
} else {
const random = this.random()
this._entry.innerHTML = `Click a /topic to get started, or try a random page.
The wiki contains ${Object.keys(this.byName).length} terms, in ${Object.keys(this.byCat).length} categories, by ${Object.keys(this.byAuthor).length} authors.`
}
// Sidebar
this._categories.innerHTML = Object.keys(this.byCat).reduce((acc, id) => { return this.byCat[id].length > 5 ? `${acc}