wiki-plugin-mech 0.1.25 → 0.1.26
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 +63 -26
- package/package.json +1 -1
package/client/mech.js
CHANGED
|
@@ -274,8 +274,8 @@
|
|
|
274
274
|
function walk_emit ({elem,command,args,state}) {
|
|
275
275
|
if(!('neighborhood' in state)) return trouble(elem,`WALK expects state.neighborhood, like from NEIGHBORS.`)
|
|
276
276
|
inspect(elem,'neighborhood',state)
|
|
277
|
-
const way =
|
|
278
|
-
const steps = walks(way,state.neighborhood)
|
|
277
|
+
const [,count,way] = command.match(/\b(\d+)? *(steps|days|weeks|months|hubs)\b/) || []
|
|
278
|
+
const steps = walks(count,way,state.neighborhood)
|
|
279
279
|
const aspects = steps.filter(({graph})=>graph)
|
|
280
280
|
if(state.debug) console.log({steps})
|
|
281
281
|
elem.innerHTML = command
|
|
@@ -283,10 +283,16 @@
|
|
|
283
283
|
elem.innerHTML += ` ⇒ ${aspects.length} aspects, ${nodes.length} nodes`
|
|
284
284
|
if(steps.find(({graph}) => !graph)) trouble(elem,`WALK skipped sites with no links in sitemaps`)
|
|
285
285
|
const item = elem.closest('.item')
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
286
|
+
if (aspects.length) {
|
|
287
|
+
state.aspect = state.aspect || []
|
|
288
|
+
const obj = state.aspect.find(obj => obj.id == elem.id)
|
|
289
|
+
if(obj) obj.result = aspects
|
|
290
|
+
else state.aspect.push({id:elem.id, result:aspects})
|
|
291
|
+
item.classList.add('aspect-source')
|
|
292
|
+
item.aspectData = () => state.aspect.map(obj => obj.result).flat()
|
|
293
|
+
if(state.debug) console.log({command,state:state.aspect,item:item.aspectData()})
|
|
294
|
+
|
|
295
|
+
}
|
|
290
296
|
}
|
|
291
297
|
|
|
292
298
|
function tick_emit ({elem,command,args,body,state}) {
|
|
@@ -668,6 +674,31 @@
|
|
|
668
674
|
elem.innerHTML = command + ` ⇒ sent`
|
|
669
675
|
}
|
|
670
676
|
|
|
677
|
+
function solo_emit({elem,command,state}) {
|
|
678
|
+
if(!('aspect' in state)) return trouble(elem,`"SOLO" expects "aspect" state, like from "WALK".`)
|
|
679
|
+
inspect(elem,'aspect',state)
|
|
680
|
+
const todo = state.aspect.map(each => ({
|
|
681
|
+
source:each.id,
|
|
682
|
+
aspects:each.result
|
|
683
|
+
}))
|
|
684
|
+
// from Solo plugin, client/solo.js
|
|
685
|
+
const pageKey = elem.closest('.page').dataset.key
|
|
686
|
+
const doing = {type:'batch', sources:todo, pageKey}
|
|
687
|
+
console.log({pageKey,doing})
|
|
688
|
+
const popup = window.open('/plugins/solo/dialog/#','solo','popup,height=720,width=1280')
|
|
689
|
+
if (popup.location.pathname != '/plugins/solo/dialog/'){
|
|
690
|
+
console.log('launching new dialog')
|
|
691
|
+
popup.addEventListener('load', event => {
|
|
692
|
+
console.log('launched and loaded')
|
|
693
|
+
popup.postMessage(doing, window.origin)
|
|
694
|
+
})
|
|
695
|
+
}
|
|
696
|
+
else {
|
|
697
|
+
console.log('reusing existing dialog')
|
|
698
|
+
popup.postMessage(doing, window.origin)
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
671
702
|
|
|
672
703
|
// C A T A L O G
|
|
673
704
|
|
|
@@ -696,7 +727,8 @@
|
|
|
696
727
|
ROSTER: {emit:roster_emit},
|
|
697
728
|
LINEUP: {emit:lineup_emit},
|
|
698
729
|
LISTEN: {emit:listen_emit},
|
|
699
|
-
MESSAGE: {emit:message_emit}
|
|
730
|
+
MESSAGE: {emit:message_emit},
|
|
731
|
+
SOLO: {emit:solo_emit}
|
|
700
732
|
}
|
|
701
733
|
|
|
702
734
|
|
|
@@ -779,21 +811,22 @@
|
|
|
779
811
|
}
|
|
780
812
|
|
|
781
813
|
// inspired by aspects-of-recent-changes/roster-graphs.html
|
|
782
|
-
function walks(way,neighborhood) {
|
|
814
|
+
function walks(count,way='steps',neighborhood) {
|
|
815
|
+
const find = slug => neighborhood.find(info => info.slug == slug)
|
|
783
816
|
const prob = n => Math.floor(n * Math.abs(Math.random()-Math.random()))
|
|
784
817
|
const rand = a => a[prob(a.length)]
|
|
785
818
|
const domains = neighborhood
|
|
786
819
|
.map(info => info.domain)
|
|
787
820
|
.filter(uniq)
|
|
788
821
|
switch(way) {
|
|
789
|
-
case 'steps': return steps()
|
|
790
|
-
case 'days': return periods(1)
|
|
791
|
-
case 'weeks': return periods(7)
|
|
792
|
-
case 'months': return periods(30)
|
|
793
|
-
case 'hubs': return hubs()
|
|
822
|
+
case 'steps': return steps(count)
|
|
823
|
+
case 'days': return periods(way,1,count)
|
|
824
|
+
case 'weeks': return periods(way,7,count)
|
|
825
|
+
case 'months': return periods(way,30,count)
|
|
826
|
+
case 'hubs': return hubs(count)
|
|
794
827
|
}
|
|
795
828
|
|
|
796
|
-
function steps() {
|
|
829
|
+
function steps(count=5) {
|
|
797
830
|
return domains.map(domain => {
|
|
798
831
|
const name = domain.split('.').slice(0,3).join('.')
|
|
799
832
|
const done = new Set()
|
|
@@ -802,7 +835,6 @@
|
|
|
802
835
|
const here = neighborhood
|
|
803
836
|
.filter(info => info.domain==domain && ('links' in info))
|
|
804
837
|
if(!here.length) return {name,graph:null}
|
|
805
|
-
const find = slug => neighborhood.find(info => info.slug == slug)
|
|
806
838
|
const node = info => {
|
|
807
839
|
nid = graph.addNode('',{
|
|
808
840
|
name:info.title.replaceAll(/ /g,"\n"),
|
|
@@ -829,17 +861,15 @@
|
|
|
829
861
|
})
|
|
830
862
|
}
|
|
831
863
|
|
|
832
|
-
function periods(days) {
|
|
864
|
+
function periods(way,days,count=12) {
|
|
833
865
|
const interval = days*24*60*60*1000
|
|
834
|
-
const iota = [
|
|
866
|
+
const iota = [...Array(Number(count)).keys()]
|
|
835
867
|
const dates = iota.map(n => Date.now()-n*interval)
|
|
836
868
|
const aspects = []
|
|
837
869
|
for(const stop of dates) {
|
|
838
870
|
const start = stop-interval
|
|
839
|
-
const name = new Date(
|
|
840
|
-
// const done = new Set()
|
|
871
|
+
const name = `${way.replace(/s$/,'')} ${new Date(start).toLocaleDateString()}`
|
|
841
872
|
const graph = new Graph()
|
|
842
|
-
const find = slug => neighborhood.find(info => info.slug == slug)
|
|
843
873
|
const node = info => {
|
|
844
874
|
return graph.addUniqNode('',{
|
|
845
875
|
name:info.title.replaceAll(/ /g,"\n"),
|
|
@@ -865,22 +895,29 @@
|
|
|
865
895
|
return aspects
|
|
866
896
|
}
|
|
867
897
|
|
|
868
|
-
function hubs() {
|
|
898
|
+
function hubs(count=12) {
|
|
869
899
|
const aspects = []
|
|
900
|
+
const ignored = new Set()
|
|
870
901
|
const hits = {}
|
|
871
902
|
for (const info of neighborhood)
|
|
872
903
|
if(info.links)
|
|
873
|
-
|
|
874
|
-
|
|
904
|
+
if(Object.keys(info.links).length <= 15) {
|
|
905
|
+
for(const link in info.links)
|
|
906
|
+
if(find(link))
|
|
907
|
+
hits[link] = (hits[link]||0) + 1
|
|
908
|
+
} else {
|
|
909
|
+
ignored.add(info.slug)
|
|
910
|
+
}
|
|
911
|
+
if(ignored.size > 0)
|
|
912
|
+
console.log('hub links ignored for large pages:',[...ignored])
|
|
875
913
|
const hubs = Object.entries(hits)
|
|
876
914
|
.sort((a,b) => b[1]-a[1])
|
|
877
|
-
.slice(0,
|
|
915
|
+
.slice(0,count)
|
|
878
916
|
console.log({hits,hubs})
|
|
879
917
|
|
|
880
918
|
for(const hub of hubs) {
|
|
881
|
-
const name =
|
|
919
|
+
const name = `hub ${hub[1]} ${hub[0]}`
|
|
882
920
|
const graph = new Graph()
|
|
883
|
-
const find = slug => neighborhood.find(info => info.slug == slug)
|
|
884
921
|
const node = info => {
|
|
885
922
|
return graph.addUniqNode('',{
|
|
886
923
|
name:info.title.replaceAll(/ /g,"\n"),
|