Skip to content

Commit 00ece05

Browse files
jq query now in js
1 parent accd68b commit 00ece05

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<div id=result>working</div>
2+
<script type=module>
3+
// import * as frame from 'http://code.fed.wiki/assets/v1/frame.js'
4+
// const context = await frame.context()
5+
const sitemap = await fetch('/system/sitemap.json').then(res => res.json())
6+
window.result.innerHTML = `
7+
<pre></pre>
8+
<button>start</button>
9+
`
10+
let start = 0
11+
const button = window.result.querySelector('button')
12+
const result = window.result.querySelector('pre')
13+
button.addEventListener('click',e => more())
14+
15+
async function more() {
16+
button.disabled = true
17+
const todo = sitemap.slice(start,start+=50)
18+
await scan(todo)
19+
button.innerText = `more of ${sitemap.length-start}`
20+
button.disabled = false
21+
}
22+
23+
async function scan(todo) {
24+
return Promise.all(
25+
todo.map(async info => {
26+
await fetch(`/${info.slug}.json`)
27+
.then(res => res.json())
28+
.then(page => check(info,page))
29+
})
30+
)
31+
}
32+
33+
// jq '.journal|group_by(.id)|.[]|select(any(.type=="remove") and any(.item.type=="assets"))
34+
35+
function check(infox,page) {
36+
const groups = Object.groupBy(page.journal, info => info.id)
37+
const want = Object.entries(groups).filter(([id,actions]) =>
38+
actions.some(action => action.type == "remove") &&
39+
actions.some(action => action.item?.type == "assets"))
40+
if(want.length>0) {
41+
result.innerHTML += `${infox.title} has\n`
42+
for (const wanted of want) {
43+
console.log(infox.title, wanted[0], wanted[1])
44+
result.innerHTML += ` ${wanted[0]} ${wanted[1].map(action => action.type).join(" ")}\n`
45+
}
46+
}
47+
}
48+
49+
</script>

0 commit comments

Comments
 (0)