initial commit
This commit is contained in:
commit
ed081aca56
4 changed files with 54 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
node_modules
|
||||
bun.lock
|
14
entry/run_hn_stage.js
Normal file
14
entry/run_hn_stage.js
Normal 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
7
package.json
Normal 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
31
roles/hn-fetch-jobs.js
Normal 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
|
||||
}
|
Loading…
Add table
Reference in a new issue