Created
          January 26, 2021 01:40 
        
      - 
      
- 
        Save ishiduca/b82bc19b501c8cacf15df575f11b22c3 to your computer and use it in GitHub Desktop. 
Revisions
- 
        ishiduca created this gist Jan 26, 2021 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ #!/usr/bin/env node var find = require('./find-rss') process.stdin(pipe(find(JSON.stringify)).pipe(process.stdout) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ var trumpet = require('trumpet') var { through, duplex, concat, pipe } = require('mississippi') var mimeTypes = { 'application/atom': 'atom', 'application/atom+xml': 'atom', 'text/atom': 'atom', 'text/atom+xml': 'atom', 'application/rss': 'rss', 'application/rss+xml': 'rss', 'text/rss': 'rss', 'text/rss+xml': 'rss', 'application/rdf': 'rdf', 'application/rdf+xml': 'rdf', 'text/rdf': 'rdf', 'text/rdf+xml': 'rdf', 'application/feed+json': 'json-feed', 'application/json': 'json-feed' } module.exports = function find (f) { var tr = trumpet() var snk = through.obj((data, _, done) => { try { done(null, f(data)) } catch (error) { done(error) } }) var i = 0 var mid = through.obj() mid.setMaxListeners(0) mid.on('pipe', () => (i += 1)) mid.on('unpipe', () => { if ((i -= 1) === 0 && tr._readableState.ended) mid.end() }) tr.once('end', () => { if (i === 0 && !mid._readableState.ended) mid.end() }) pipe( mid, through.obj((data, _, done) => { if (mimeTypes[data.type] == null) return done() done(null, data) }), concat(list => snk.end(list)), error => (error != null) && snk.emit('error', error) ) tr.selectAll('link', link => { var data = {} var src = through.obj() link.getAttribute('href', href => (data.href = href)) link.getAttribute('rel', rel => (data.rel = rel)) link.getAttribute('type', type => (data.type = type)) link.getAttribute('title', title => (data.title = title)) pipe( link.createReadStream(), concat(() => src.end(data)), error => { if (error != null) mid.emit('error', error) // else src.end(data) } ) src.pipe(mid, { end: false }) }) return duplex.obj(tr, snk) } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ curl -- https://jsonfeed.org/version/1.1 | bin.js | JSONStream