wiki-plugin-mech 0.1.27 → 0.1.28
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 +89 -73
- package/package.json +1 -1
package/client/mech.js
CHANGED
|
@@ -275,9 +275,23 @@
|
|
|
275
275
|
function walk_emit ({elem,command,args,state}) {
|
|
276
276
|
if(!('neighborhood' in state)) return trouble(elem,`WALK expects state.neighborhood, like from NEIGHBORS.`)
|
|
277
277
|
inspect(elem,'neighborhood',state)
|
|
278
|
-
const [,count,way] = command.match(/\b(\d+)? *(steps|days|weeks|months|hubs)\b/) || []
|
|
278
|
+
const [,count,way] = command.match(/\b(\d+)? *(steps|days|weeks|months|hubs|lineup|references)\b/) || []
|
|
279
279
|
if(!way && command != 'WALK') return trouble(elem, `WALK can't understand rest of this block.`)
|
|
280
|
-
const
|
|
280
|
+
const scope = {
|
|
281
|
+
lineup(){
|
|
282
|
+
const items = [...document.querySelectorAll('.page')]
|
|
283
|
+
const index = items.indexOf(elem.closest('.page'))
|
|
284
|
+
return items.slice(0,index)
|
|
285
|
+
},
|
|
286
|
+
references(){
|
|
287
|
+
const div = elem.closest('.page')
|
|
288
|
+
const pageObject = wiki.lineup.atKey(div.dataset.key)
|
|
289
|
+
const story = pageObject.getRawPage().story
|
|
290
|
+
console.log({div,pageObject,story})
|
|
291
|
+
return story.filter(item => item.type == 'reference')
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const steps = walks(count,way,state.neighborhood,scope)
|
|
281
295
|
const aspects = steps.filter(({graph})=>graph)
|
|
282
296
|
if(state.debug) console.log({steps})
|
|
283
297
|
elem.innerHTML = command
|
|
@@ -825,8 +839,8 @@
|
|
|
825
839
|
}
|
|
826
840
|
|
|
827
841
|
// 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)
|
|
842
|
+
function walks(count,way='steps',neighborhood,scope={}) {
|
|
843
|
+
const find = (slug,site) => neighborhood.find(info => info.slug == slug && (!site || info.domain == site))
|
|
830
844
|
const prob = n => Math.floor(n * Math.abs(Math.random()-Math.random()))
|
|
831
845
|
const rand = a => a[prob(a.length)]
|
|
832
846
|
const good = info => info.links && Object.keys(info.links).length < 10
|
|
@@ -835,12 +849,56 @@
|
|
|
835
849
|
const domains = neighborhood
|
|
836
850
|
.map(info => info.domain)
|
|
837
851
|
.filter(uniq)
|
|
852
|
+
|
|
853
|
+
function blanket(info) {
|
|
854
|
+
|
|
855
|
+
// hub[0] => slug
|
|
856
|
+
// find(slug) => info
|
|
857
|
+
// node(info) => nid
|
|
858
|
+
// back(slug) => infos
|
|
859
|
+
// newr(infos) => infos
|
|
860
|
+
|
|
861
|
+
const graph = new Graph()
|
|
862
|
+
const node = info => {
|
|
863
|
+
return graph.addUniqNode('',{
|
|
864
|
+
name:info.title.replaceAll(/ /g,"\n"),
|
|
865
|
+
title:info.title,
|
|
866
|
+
site:info.domain
|
|
867
|
+
})
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// hub
|
|
871
|
+
const nid = node(info)
|
|
872
|
+
|
|
873
|
+
// parents of hub
|
|
874
|
+
for(const parent of newr(back(info.slug))) {
|
|
875
|
+
graph.addRel('',node(parent),nid)
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// children of hub
|
|
879
|
+
for(const link in (info.links||{})) {
|
|
880
|
+
const child = find(link)
|
|
881
|
+
if(child) {
|
|
882
|
+
const cid = node(child)
|
|
883
|
+
graph.addRel('',nid,cid)
|
|
884
|
+
|
|
885
|
+
// parents of children of hub
|
|
886
|
+
for(const parent of newr(back(child.slug))) {
|
|
887
|
+
graph.addRel('',node(parent),cid)
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
return graph
|
|
892
|
+
}
|
|
893
|
+
|
|
838
894
|
switch(way) {
|
|
839
895
|
case 'steps': return steps(count)
|
|
840
896
|
case 'days': return periods(way,1,count)
|
|
841
897
|
case 'weeks': return periods(way,7,count)
|
|
842
898
|
case 'months': return periods(way,30,count)
|
|
843
899
|
case 'hubs': return hubs(count)
|
|
900
|
+
case 'references': return references()
|
|
901
|
+
case 'lineup': return lineup()
|
|
844
902
|
}
|
|
845
903
|
|
|
846
904
|
function steps(count=5) {
|
|
@@ -937,84 +995,42 @@
|
|
|
937
995
|
.slice(0,count)
|
|
938
996
|
console.log({hits,hubs})
|
|
939
997
|
|
|
940
|
-
// hub[0] => slug
|
|
941
|
-
// find(slug) => info
|
|
942
|
-
// node(info) => nid
|
|
943
|
-
// back(slug) => infos
|
|
944
|
-
// newr(infos) => infos
|
|
945
|
-
|
|
946
998
|
for(const hub of hubs) {
|
|
947
999
|
const name = `hub ${hub[1]} ${hub[0]}`
|
|
948
|
-
const 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
|
-
|
|
1000
|
+
const graph = blanket(find(hub[0]))
|
|
980
1001
|
aspects.push({name,graph})
|
|
981
1002
|
}
|
|
982
1003
|
return aspects
|
|
983
1004
|
}
|
|
984
1005
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
const
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
1006
|
+
function lineup() {
|
|
1007
|
+
const aspects = []
|
|
1008
|
+
const lineup = scope.lineup()
|
|
1009
|
+
console.log({lineup})
|
|
1010
|
+
for(const div of lineup){
|
|
1011
|
+
const pageObject = wiki.lineup.atKey(div.dataset.key)
|
|
1012
|
+
const slug = pageObject.getSlug()
|
|
1013
|
+
const site = pageObject.getRemoteSite(location.host)
|
|
1014
|
+
const info = find(slug,site)
|
|
1015
|
+
console.log({div,pageObject,site,slug,info})
|
|
1016
|
+
aspects.push({name:pageObject.getTitle(), graph:blanket(info)})
|
|
1017
|
+
}
|
|
1018
|
+
return aspects
|
|
995
1019
|
}
|
|
996
1020
|
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
.
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
.map(pair => pair[0])
|
|
1011
|
-
.slice(0,3)
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
*/
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1021
|
+
function references() {
|
|
1022
|
+
const aspects = []
|
|
1023
|
+
const items = scope.references()
|
|
1024
|
+
console.log({items})
|
|
1025
|
+
for(const item of items){
|
|
1026
|
+
const {title,site,slug} = item
|
|
1027
|
+
const info = find(slug,site)
|
|
1028
|
+
console.log({site,slug,info})
|
|
1029
|
+
aspects.push({name:title, graph:blanket(info)})
|
|
1030
|
+
}
|
|
1031
|
+
console.log({aspects})
|
|
1032
|
+
return aspects
|
|
1033
|
+
}
|
|
1018
1034
|
}
|
|
1019
1035
|
|
|
1020
1036
|
|