wiki-plugin-mech 0.1.28 → 0.1.30

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.
Files changed (2) hide show
  1. package/client/mech.js +31 -5
  2. 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,11 +862,14 @@
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
847
869
  const back = slug => neighborhood.filter(info => good(info) && slug in info.links)
848
- const newr = infos => infos.toSorted((a,b)=>b.date-a.date).slice(0,3)
870
+ // const uniq = (value, index, self) => self.indexOf(value) === index
871
+ const dedup = (value, index, self) => self.findIndex(info => info.slug == value.slug) === index
872
+ const newr = infos => infos.toSorted((a,b)=>b.date-a.date).filter(dedup).slice(0,3)
849
873
  const domains = neighborhood
850
874
  .map(info => info.domain)
851
875
  .filter(uniq)
@@ -866,24 +890,26 @@
866
890
  site:info.domain
867
891
  })
868
892
  }
893
+ const up = info => finds(info?.patterns?.up) ?? newr(back(info.slug))
894
+ const down = info => info?.patterns?.down ?? Object.keys(info.links||{})
869
895
 
870
896
  // hub
871
897
  const nid = node(info)
872
898
 
873
899
  // parents of hub
874
- for(const parent of newr(back(info.slug))) {
900
+ for(const parent of up(info)) {
875
901
  graph.addRel('',node(parent),nid)
876
902
  }
877
903
 
878
904
  // children of hub
879
- for(const link in (info.links||{})) {
905
+ for(const link of down(info)) {
880
906
  const child = find(link)
881
907
  if(child) {
882
908
  const cid = node(child)
883
909
  graph.addRel('',nid,cid)
884
910
 
885
911
  // parents of children of hub
886
- for(const parent of newr(back(child.slug))) {
912
+ for(const parent of up(child)) {
887
913
  graph.addRel('',node(parent),cid)
888
914
  }
889
915
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-mech",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "Federated Wiki - Mechanism Scripting Plugin",
5
5
  "keywords": [
6
6
  "mech",