diff --git a/.gitignore b/.gitignore index 5e438ee..1e97e9c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ node_modules/ # Artifacts /out/* /cache.json -/config.js \ No newline at end of file +/config.js + +# Testing +*.ignore \ No newline at end of file diff --git a/README b/README index 1ad47ff..8ec148a 100644 --- a/README +++ b/README @@ -2,11 +2,13 @@ ┏┓┏┏┏┏┓┏┓┏┓ ┛ ┛┛┛┛┗┛┗┗┫ ┛ -RSS-based art collator +Rsssing is an RSS-based feed for art blogs. It generates a series of web pages +to be uploaded to a web server, or simply viewed in the browser. Tumblr and +Twitter (through nitter) sources are supported. -Do not expect quality code. Only works with the Bun[1] runtime +| Usage +Rssssing only works with the Bun[1] runtime -Usage - Run `bun run setup`, `npm run setup`, etc. - Add usernames and such to the "feeds" array in config.js - `bun .` diff --git a/index.js b/index.js index 5a36c6f..bc7441c 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ const fetch = require('node-fetch') -const config = require('./config.js') +const config = require('./config.js.ignore') const Path = require('path') let cache = require('./cache.json') @@ -144,52 +144,60 @@ const processTumblr = (rss, user) => { const oneDay = 1000 * 60 * 60 * 24 -const print = async feeds => { +const printFeed = async (sources, directory, header) => { // Coalate - let masterFeed = [] + let feed = [] let tooLongAgo = (Date.now() - (Date.now() % oneDay)) - oneDay * config.tooLongAgo - let missingFeeds = 0 + let missingSources = 0 - for(let feed of feeds) { - if(feed == undefined) { - missingFeeds++ + for(let source of sources) { + if(source == undefined) { + missingSources++ continue } - for(let post of feed) { + for(let post of source) { if(tooLongAgo && post.date > tooLongAgo) - masterFeed.push(post) + feed.push(post) } } - masterFeed = masterFeed.sort((a, b) => a.date < b.date) + feed = feed.sort((a, b) => a.date < b.date) - if(missingFeeds) { - console.log('Missing ' + missingFeeds + ' feeds!') + if(missingSources) { + console.log('Missing ' + missingSources + ' feeds!') } // Render let pages = [] - for(let i = 0; i < Math.ceil(masterFeed.length / config.pageSize); i++) { - pages.push(masterFeed.slice(i * config.pageSize, (i + 1) * config.pageSize) ) + for(let i = 0; i < Math.ceil(feed.length / config.pageSize); i++) { + pages.push(feed.slice(i * config.pageSize, (i + 1) * config.pageSize) ) } // Write - console.log('Writing...') for(let i = 0; i < pages.length; i++) { - Bun.write('out/' + (i == 0 ? 'index' : i) + '.html', renderPage(pages[i], i, pages.length) ) + let nextPage = i + 1 + + let link = nextPage === pages.length ? + `end` : + `next` + + Bun.write( + Path.join(directory, (i == 0 ? 'index' : i) + '.html'), + renderPage(`Page ${i + 1}`, pages[i], header, link) + ) } } -const renderPage = (posts, index, pageCount) => { +const renderPage = (title, posts, header, footer) => { let html = `\
-${post.user} ${date.getMonth()}/${date.getDate()}/${date.getFullYear()} open
${post.user} ${date.getMonth()}/${date.getDate()}/${date.getFullYear()} open