wiki-plugin-mech 0.1.28 → 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/mech.js +28 -4
- package/package.json +1 -1
package/client/mech.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"use strict"
|
|
4
4
|
const uniq = (value, index, self) => self.indexOf(value) === index
|
|
5
5
|
const delay = time => new Promise(res => setTimeout(res,time))
|
|
6
|
+
const asSlug = (title) => title.replace(/\s/g, '-').replace(/[^A-Za-z0-9-]/g, '').toLowerCase()
|
|
6
7
|
|
|
7
8
|
function expand(text) {
|
|
8
9
|
return text
|
|
@@ -260,13 +261,33 @@
|
|
|
260
261
|
wiki.showResult(wiki.newPage(page), options)
|
|
261
262
|
}
|
|
262
263
|
|
|
263
|
-
function neighbors_emit ({elem,command,args,state}) {
|
|
264
|
+
async function neighbors_emit ({elem,command,args,body,state}) {
|
|
265
|
+
const belem = probe => document.getElementById(probe.key)
|
|
264
266
|
const want = args[0]
|
|
265
267
|
if(state.debug) console.log({neighborhoodObject:wiki.neighborhoodObject})
|
|
266
268
|
const have = Object.entries(wiki.neighborhoodObject.sites)
|
|
267
269
|
.filter(([domain,site]) => !site.sitemapRequestInflight && (!want || domain.includes(want)))
|
|
268
270
|
.map(([domain,site]) => (site.sitemap||[])
|
|
269
271
|
.map(info => Object.assign({domain},info)))
|
|
272
|
+
for (const probe of (body||[])) {
|
|
273
|
+
if(!probe.command.endsWith(' Survey')) {
|
|
274
|
+
trouble(belem(probe),`NEIGHBORS expects a Site Survey title, like Pattern Link Survey`)
|
|
275
|
+
continue
|
|
276
|
+
}
|
|
277
|
+
const todos = have.filter(sitemap =>
|
|
278
|
+
sitemap.find(info => info.title == probe.command))
|
|
279
|
+
belem(probe).innerHTML = `${probe.command} ⇒ ${todos.length} sites`
|
|
280
|
+
for (const todo of todos) {
|
|
281
|
+
const url = `//${todo[0].domain}/${asSlug(probe.command)}.json`
|
|
282
|
+
const page = await fetch(url).then(res => res.json())
|
|
283
|
+
const survey = page.story.find(item => item.type == 'frame')?.survey
|
|
284
|
+
for (const info of todo) {
|
|
285
|
+
const extra = Object.assign({},survey.find(inf => inf.slug == info.slug),info)
|
|
286
|
+
Object.assign(info,extra)
|
|
287
|
+
}
|
|
288
|
+
console.log({url,page,survey,todo})
|
|
289
|
+
}
|
|
290
|
+
}
|
|
270
291
|
state.neighborhood = have.flat()
|
|
271
292
|
.sort((a,b) => b.date - a.date)
|
|
272
293
|
elem.innerHTML = command + ` ⇒ ${state.neighborhood.length} pages, ${have.length} sites`
|
|
@@ -841,6 +862,7 @@
|
|
|
841
862
|
// inspired by aspects-of-recent-changes/roster-graphs.html
|
|
842
863
|
function walks(count,way='steps',neighborhood,scope={}) {
|
|
843
864
|
const find = (slug,site) => neighborhood.find(info => info.slug == slug && (!site || info.domain == site))
|
|
865
|
+
const finds = (slugs) => slugs ? slugs.map(slug => find(slug)) : null
|
|
844
866
|
const prob = n => Math.floor(n * Math.abs(Math.random()-Math.random()))
|
|
845
867
|
const rand = a => a[prob(a.length)]
|
|
846
868
|
const good = info => info.links && Object.keys(info.links).length < 10
|
|
@@ -866,24 +888,26 @@
|
|
|
866
888
|
site:info.domain
|
|
867
889
|
})
|
|
868
890
|
}
|
|
891
|
+
const up = info => finds(info?.patterns?.up) ?? newr(back(info.slug))
|
|
892
|
+
const down = info => info?.patterns?.down ?? Object.keys(info.links||{})
|
|
869
893
|
|
|
870
894
|
// hub
|
|
871
895
|
const nid = node(info)
|
|
872
896
|
|
|
873
897
|
// parents of hub
|
|
874
|
-
for(const parent of
|
|
898
|
+
for(const parent of up(info)) {
|
|
875
899
|
graph.addRel('',node(parent),nid)
|
|
876
900
|
}
|
|
877
901
|
|
|
878
902
|
// children of hub
|
|
879
|
-
for(const link
|
|
903
|
+
for(const link of down(info)) {
|
|
880
904
|
const child = find(link)
|
|
881
905
|
if(child) {
|
|
882
906
|
const cid = node(child)
|
|
883
907
|
graph.addRel('',nid,cid)
|
|
884
908
|
|
|
885
909
|
// parents of children of hub
|
|
886
|
-
for(const parent of
|
|
910
|
+
for(const parent of up(child)) {
|
|
887
911
|
graph.addRel('',node(parent),cid)
|
|
888
912
|
}
|
|
889
913
|
}
|