'use strict'
function Portal (sites) {
this.el = document.createElement('div')
this.el.id = 'portal'
this.sites = sites
// Templates
const _readme = '
This webring is an attempt to inspire artists & developers to build their own website and share traffic among each other. The ring welcomes personalized websites such as diaries, wikis & portfolios .
To add yourself to the ring, submit a Pull Request . If you found a broken link, please report it .
'
const _buttons = 'Random | Information | The Hallway | The Wiki | OPML
'
function _directory (sites) {
const siteTypesArray = [...new Set(sites.map(site => site.type).filter(Boolean))]
const siteLangsArray = [...new Set(sites
.reduce((flattened, site) => flattened.concat(site.langs), [])
.sort())]
const siteTypes = siteTypesArray.reduce((output, siteType) =>
`${output}<${siteType}> `,
'<all> ')
const siteLangs = siteLangsArray.reduce((output, siteLang) =>
`${output}<${siteLang}> `,
'<all> ')
const listItems = sites.reduce((acc, site, id) =>
`${acc}${_name(site)} `, '')
return `${siteTypes} ${siteLangs} `
}
function _name (site) {
return site.title || `${site.url.split('//')[1].replace(/\/+$/, '')}`
}
function _type (site) {
return site.type ? `data-type="${site.type} "` : ''
}
function _lang (site) {
return `data-lang="${site.langs.join(' ').trim()}"`
}
function _redirectView (site) {
return `Redirecting to ${site.url}