initial commit

This commit is contained in:
dab 2025-08-20 16:48:49 +00:00
commit ed081aca56
4 changed files with 54 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
node_modules
bun.lock

14
entry/run_hn_stage.js Normal file
View file

@ -0,0 +1,14 @@
import { async_stage } from 'stage_d'
import oncue_hnfetchjobs from '../roles/hn-fetch-jobs'
const roles = {
'hn-fetch-jobs': oncue_hnfetchjobs,
}
const framerock_config = {
hostname: '0.0.0.0',
port: 8800,
page_title: 'stage_d demo',
}
async_stage(roles, { framerock_config }).then(()=>{}).catch(console.error)

7
package.json Normal file
View file

@ -0,0 +1,7 @@
{
"name": "stage_d_examples",
"version": "0.1.0",
"dependencies": {
"stage_d": "git+https://git.daemons.my/dab/stage_d.git#6a4a0a2c28f476790415488905e32225797f9525"
}
}

31
roles/hn-fetch-jobs.js Normal file
View file

@ -0,0 +1,31 @@
export default async function () {
let action = ['INDICATE_FAILURE', 'unexpected']
const response = await fetch('https://news.ycombinator.com/jobs')
if (response.status === 200) {
const lst_combined = []
const rewriter = new HTMLRewriter()
rewriter.on('.athing.submission .titleline > a', {
element (elem) {
lst_combined.push(['url', elem.getAttribute('href')])
return
},
text (text) {
if (text.text !== '') {
lst_combined.push(['title', text.text])
}
return
}
})
rewriter.transform(response)
const lst_postings = []
lst_combined.forEach(([ key, value ], idx) => {
if (idx % 2 === 0) {
lst_postings.push({})
}
lst_postings[lst_postings.length-1][key] = value
return
})
action = ['INDICATE_SUCCESS', lst_postings]
}
return action
}