commit ed081aca56107ee6110e104d44f084790766d098 Author: dab Date: Wed Aug 20 16:48:49 2025 +0000 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d286b7c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +bun.lock diff --git a/entry/run_hn_stage.js b/entry/run_hn_stage.js new file mode 100644 index 0000000..7209130 --- /dev/null +++ b/entry/run_hn_stage.js @@ -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) diff --git a/package.json b/package.json new file mode 100644 index 0000000..1395d94 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/roles/hn-fetch-jobs.js b/roles/hn-fetch-jobs.js new file mode 100644 index 0000000..325b636 --- /dev/null +++ b/roles/hn-fetch-jobs.js @@ -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 +}