wiki-plugin-mech 0.1.27 → 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.
Files changed (2) hide show
  1. package/client/mech.js +114 -74
  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`
@@ -275,9 +296,23 @@
275
296
  function walk_emit ({elem,command,args,state}) {
276
297
  if(!('neighborhood' in state)) return trouble(elem,`WALK expects state.neighborhood, like from NEIGHBORS.`)
277
298
  inspect(elem,'neighborhood',state)
278
- const [,count,way] = command.match(/\b(\d+)? *(steps|days|weeks|months|hubs)\b/) || []
299
+ const [,count,way] = command.match(/\b(\d+)? *(steps|days|weeks|months|hubs|lineup|references)\b/) || []
279
300
  if(!way && command != 'WALK') return trouble(elem, `WALK can't understand rest of this block.`)
280
- const steps = walks(count,way,state.neighborhood)
301
+ const scope = {
302
+ lineup(){
303
+ const items = [...document.querySelectorAll('.page')]
304
+ const index = items.indexOf(elem.closest('.page'))
305
+ return items.slice(0,index)
306
+ },
307
+ references(){
308
+ const div = elem.closest('.page')
309
+ const pageObject = wiki.lineup.atKey(div.dataset.key)
310
+ const story = pageObject.getRawPage().story
311
+ console.log({div,pageObject,story})
312
+ return story.filter(item => item.type == 'reference')
313
+ }
314
+ }
315
+ const steps = walks(count,way,state.neighborhood,scope)
281
316
  const aspects = steps.filter(({graph})=>graph)
282
317
  if(state.debug) console.log({steps})
283
318
  elem.innerHTML = command
@@ -825,8 +860,9 @@
825
860
  }
826
861
 
827
862
  // inspired by aspects-of-recent-changes/roster-graphs.html
828
- function walks(count,way='steps',neighborhood) {
829
- const find = slug => neighborhood.find(info => info.slug == slug)
863
+ function walks(count,way='steps',neighborhood,scope={}) {
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
830
866
  const prob = n => Math.floor(n * Math.abs(Math.random()-Math.random()))
831
867
  const rand = a => a[prob(a.length)]
832
868
  const good = info => info.links && Object.keys(info.links).length < 10
@@ -835,12 +871,58 @@
835
871
  const domains = neighborhood
836
872
  .map(info => info.domain)
837
873
  .filter(uniq)
874
+
875
+ function blanket(info) {
876
+
877
+ // hub[0] => slug
878
+ // find(slug) => info
879
+ // node(info) => nid
880
+ // back(slug) => infos
881
+ // newr(infos) => infos
882
+
883
+ const graph = new Graph()
884
+ const node = info => {
885
+ return graph.addUniqNode('',{
886
+ name:info.title.replaceAll(/ /g,"\n"),
887
+ title:info.title,
888
+ site:info.domain
889
+ })
890
+ }
891
+ const up = info => finds(info?.patterns?.up) ?? newr(back(info.slug))
892
+ const down = info => info?.patterns?.down ?? Object.keys(info.links||{})
893
+
894
+ // hub
895
+ const nid = node(info)
896
+
897
+ // parents of hub
898
+ for(const parent of up(info)) {
899
+ graph.addRel('',node(parent),nid)
900
+ }
901
+
902
+ // children of hub
903
+ for(const link of down(info)) {
904
+ const child = find(link)
905
+ if(child) {
906
+ const cid = node(child)
907
+ graph.addRel('',nid,cid)
908
+
909
+ // parents of children of hub
910
+ for(const parent of up(child)) {
911
+ graph.addRel('',node(parent),cid)
912
+ }
913
+ }
914
+ }
915
+ return graph
916
+ }
917
+
838
918
  switch(way) {
839
919
  case 'steps': return steps(count)
840
920
  case 'days': return periods(way,1,count)
841
921
  case 'weeks': return periods(way,7,count)
842
922
  case 'months': return periods(way,30,count)
843
923
  case 'hubs': return hubs(count)
924
+ case 'references': return references()
925
+ case 'lineup': return lineup()
844
926
  }
845
927
 
846
928
  function steps(count=5) {
@@ -937,84 +1019,42 @@
937
1019
  .slice(0,count)
938
1020
  console.log({hits,hubs})
939
1021
 
940
- // hub[0] => slug
941
- // find(slug) => info
942
- // node(info) => nid
943
- // back(slug) => infos
944
- // newr(infos) => infos
945
-
946
1022
  for(const hub of hubs) {
947
1023
  const name = `hub ${hub[1]} ${hub[0]}`
948
- const graph = new Graph()
949
- const node = info => {
950
- return graph.addUniqNode('',{
951
- name:info.title.replaceAll(/ /g,"\n"),
952
- title:info.title,
953
- site:info.domain
954
- })
955
- }
956
- // hub
957
- const info = find(hub[0])
958
- const nid = node(info)
959
-
960
- // parents of hub
961
- for(const parent of newr(back(info.slug))) {
962
- graph.addRel('',node(parent),nid)
963
- }
964
-
965
- // hub children
966
- for(const link in (info.links||{})) {
967
- const child = find(link)
968
- if(child) {
969
- const cid = node(child)
970
- graph.addRel('',nid,cid)
971
-
972
- // parents of children
973
- for(const parent of newr(back(child.slug))) {
974
- graph.addRel('',node(parent),cid)
975
- }
976
- }
977
- }
978
-
979
-
1024
+ const graph = blanket(find(hub[0]))
980
1025
  aspects.push({name,graph})
981
1026
  }
982
1027
  return aspects
983
1028
  }
984
1029
 
985
-
986
- /*
987
-
988
- for (const name of newest(Object.keys(info.links||{}))){
989
- const kid = node(name)
990
- graph.addRel('',nid,kid)
991
-
992
- const parents = neighborhood.find(info => info.slug==name)?.cites || []
993
- for (const parent of newest(parents))
994
- graph.addRel('',node(parent),kid)
1030
+ function lineup() {
1031
+ const aspects = []
1032
+ const lineup = scope.lineup()
1033
+ console.log({lineup})
1034
+ for(const div of lineup){
1035
+ const pageObject = wiki.lineup.atKey(div.dataset.key)
1036
+ const slug = pageObject.getSlug()
1037
+ const site = pageObject.getRemoteSite(location.host)
1038
+ const info = find(slug,site)
1039
+ console.log({div,pageObject,site,slug,info})
1040
+ aspects.push({name:pageObject.getTitle(), graph:blanket(info)})
1041
+ }
1042
+ return aspects
995
1043
  }
996
1044
 
997
- for (const name of newest(info.cites))
998
- graph.addRel('',node(name),nid)
999
- return graph
1000
- }
1001
-
1002
- function newest(slugs) {
1003
- const recent = slug => neighborhood
1004
- .filter(info => info.slug == slug)
1005
- return slugs
1006
- .map(slug => [slug,recent(slug)])
1007
- .filter(pair => pair[1].length)
1008
- .map(pair => [pair[0],pair[1].sort((a,b) => b.date - a.date)[0]])
1009
- .sort((a,b) => b[1].date - a[1].date)
1010
- .map(pair => pair[0])
1011
- .slice(0,3)
1012
- }
1013
-
1014
- */
1015
-
1016
-
1017
-
1045
+ function references() {
1046
+ const aspects = []
1047
+ const items = scope.references()
1048
+ console.log({items})
1049
+ for(const item of items){
1050
+ const {title,site,slug} = item
1051
+ const info = find(slug,site)
1052
+ console.log({site,slug,info})
1053
+ aspects.push({name:title, graph:blanket(info)})
1054
+ }
1055
+ console.log({aspects})
1056
+ return aspects
1057
+ }
1018
1058
  }
1019
1059
 
1020
1060
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-mech",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "Federated Wiki - Mechanism Scripting Plugin",
5
5
  "keywords": [
6
6
  "mech",