on master help sign in
Aggregator done.
commit580b66aa5d948acefe762a3051eda6e357a014c1 authorDevine Lu Linvega <aliceffekt@gmail.com> dateMon 29 Jul 2019, 08:21 (7 years ago) parent863200d
5 files changed+106−17
scripts/hallway.js+3−6 scripts/indental.js+59 scripts/sites.js+1−1 scripts/wiki.js+42−10 wiki.html+1
scripts/hallway.js+3−6
@@ -187,12 +187,9 @@ function Hallway (sites) {
187187}
188188
189189function toggleVisibility (id) {
190− var e = document.getElementById(id);
191− if(e.style.display == 'block')
192− e.style.display = 'none';
193− else
194− e.style.display = 'block';
195− }
190+ var e = document.getElementById(id)
191+ if (e.style.display == 'block') { e.style.display = 'none' } else { e.style.display = 'block' }
192+}
196193
197194function escapeHtml (unsafe) {
198195 return unsafe.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;')
scripts/indental.jsnew file+59
@@ -0,0 +1,59 @@
1+'use strict'
2+
3+function indental (data, Type) {
4+ function formatLine (line) {
5+ const a = []
6+ const h = {}
7+ for (const id in line.children) {
8+ const child = line.children[id]
9+ if (child.key) {
10+ if (h[child.key]) { console.warn(`Redefined key: ${child.key}.`) }
11+ h[child.key] = child.value
12+ } else if (child.children.length === 0 && child.content) {
13+ a[a.length] = child.content
14+ } else {
15+ h[child.content.toUpperCase()] = formatLine(child)
16+ }
17+ }
18+ return a.length > 0 ? a : h
19+ }
20+
21+ function makeLine (line) {
22+ return line.indexOf(' : ') > -1 ? {
23+ indent: line.search(/\S|$/),
24+ content: line.trim(),
25+ key: line.split(' : ')[0].trim().toUpperCase(),
26+ value: line.split(' : ')[1].trim()
27+ } : {
28+ indent: line.search(/\S|$/),
29+ content: line.trim(),
30+ children: []
31+ }
32+ }
33+
34+ function skipLine (line) {
35+ return line.trim() !== '' && line.substr(0, 1) !== ';'
36+ }
37+
38+ const lines = data.split('\n').filter(skipLine).map(makeLine)
39+
40+ // Assoc
41+ const stack = {}
42+ for (const id in lines) {
43+ const line = lines[id]
44+ const target = stack[line.indent - 2]
45+ if (target) { target.children.push(line) }
46+ stack[line.indent] = line
47+ }
48+
49+ // Format
50+ const h = {}
51+ for (const id in lines) {
52+ const line = lines[id]
53+ if (line.indent > 0) { continue }
54+ const key = line.content.toUpperCase()
55+ if (h[key]) { console.warn(`Redefined key: ${key}, line ${id}.`) }
56+ h[key] = Type ? new Type(key, formatLine(line)) : formatLine(line)
57+ }
58+ return h
59+}
scripts/sites.js+1−1
@@ -81,7 +81,7 @@ const sites = [
8181 { url: 'https://xinniw.github.io' },
8282 { url: 'https://mboxed.github.io/forida' },
8383 { url: 'https://letters.vexingworkshop.com' },
84− { url: 'https://tom.org.nz', title: 'Tom Hackshaw', type: 'Portfolio', author: 'tomupom', contact: 'tom@tomhackshaw.com', feed: 'https://tom.org.nz/scripts/twtxt.txt', wiki: 'https://tom.org.nz/scripts/database/glossary.ndtl' },
84+ { url: 'https://tom.org.nz', title: 'Tom Hackshaw', type: 'Portfolio', author: 'tomupom', contact: 'tom@tomhackshaw.com', feed: 'https://tom.org.nz/scripts/twtxt.txt' },
8585 { url: 'https://teknari.com' },
8686 { url: 'https://colectivo-de-livecoders.gitlab.io', title: 'Colectivo de Livecoders', type: 'blog', author: 'clic', contact: 'https://t.me/clic_laplata' },
8787 { url: 'https://www.madewithtea.com', title: 'madewithtea.com', type: 'blog' },
scripts/wiki.js+42−10
@@ -6,23 +6,55 @@ function Wiki (sites) {
66 this.el = document.createElement('div')
77 this.el.id = 'wiki'
88
9− this.install = function (host) {
10− console.log('Wiki','Installing..')
9+ this.index = {}
10+
11+ this.install = (host) => {
12+ console.log('Wiki', 'Installing..')
1113 this.fetch()
1214 host.appendChild(this.el)
1315 }
1416
15− this.start = function () {
16− console.log('Wiki','Starting..')
17+ this.start = () => {
18+ console.log('Wiki', 'Starting..')
1719 this.el.innerHTML = 'hello.'
1820 }
1921
20− this.fetch = function () {
21− console.log('Wiki','Fetching..')
22+ this.fetch = () => {
23+ console.log('Wiki', 'Fetching..')
2224 for (const site of sites) {
23− if(!site.wiki || !site.author){continue}
24− console.log(site)
25+ if (!site.wiki || !site.author) { continue }
26+ fetch(site.wiki, { cache: 'no-store' }).then(x => x.text()).then((content) => {
27+ this.parse(site, content)
28+ this.refresh(feeds)
29+ }).catch((err) => {
30+ console.warn(`${site.wiki}`, err)
31+ })
32+ }
33+ }
34+
35+ this.refresh = () => {
36+ console.log(Object.keys(this.index).length + ' terms')
37+ }
38+
39+ this.add = (name, value, cat, origin) => {
40+ if (!this.index[name]) {
41+ this.index[name] = []
2542 }
26− console.log(`Found ${Object.keys(feeds).length} feeds.`)
43+ this.index[name].push({ value, cat, origin })
44+ }
45+
46+ this.parse = (site, content) => {
47+ console.log('Wiki', 'Parsing ' + site.wiki)
48+ const cats = indental(this.filter(content))
49+ for (const cat in cats) {
50+ const terms = cats[cat]
51+ for (const name in terms) {
52+ this.add(name, terms[name], cat, site)
53+ }
54+ }
55+ }
56+
57+ this.filter = (lines) => {
58+ return lines.split('\n').filter((line) => { return line.indexOf(' = `') < 0 && line.trim().length > 1 }).join('\n')
2759 }
28−}
60+}
wiki.html+1
@@ -7,6 +7,7 @@
77 <link rel="stylesheet" type="text/css" href="links/main.css"/>
88 <script src="scripts/wiki.js"></script>
99 <script src="scripts/sites.js"></script>
10+ <script src="scripts/indental.js"></script>
1011 <title>Wiki</title>
1112</head>
1213<body>