diff --git a/README b/README
index 8ec148a..92c04ec 100644
--- a/README
+++ b/README
@@ -7,9 +7,8 @@ to be uploaded to a web server, or simply viewed in the browser. Tumblr and
Twitter (through nitter) sources are supported.
| Usage
-Rssssing only works with the Bun[1] runtime
-- Run `bun run setup`, `npm run setup`, etc.
+- Run `yarn run setup`, `npm run setup`, etc.
- Add usernames and such to the "feeds" array in config.js
- `bun .`
- Open `out/index.html` in a browser. Enjoy :)
diff --git a/index.js b/index.js
index c49433d..270a31b 100644
--- a/index.js
+++ b/index.js
@@ -1,12 +1,34 @@
-const fetch = require('node-fetch')
-const config = require('./config.js')
-const Path = require('path')
+// const fetch = require('node-fetch')
+// const config = require('./config.js')
+// const Path = require('path')
+// const { writeFile } = require('fs/promises')
-let cache = require('./cache.json')
-const { JSDOM } = require('jsdom')
+// let cache = require('./cache.json')
+// const { JSDOM } = require('jsdom')
+import fetch from "node-fetch"
+import Path from "path"
+import FS from "fs/promises"
+import { JSDOM } from "jsdom"
+
+import config from "./config.js"
+
+let cache = await FS.readFile('./cache.json', { encoding: 'utf-8' })
+ .then(json => JSON.parse(json) )
let waitingList = new Map()
+const write = async (path, content) => {
+ let dir = Path.dirname(path)
+
+ try {
+ await FS.access(dir)
+ } catch(e) {
+ await FS.mkdir(dir, { recursive: true })
+ }
+
+ return await FS.writeFile(path, content)
+}
+
const handleNitterUser = async user => {
let data
let index = 0
@@ -78,7 +100,7 @@ const fetchRss = async (hostname, path) => {
waitingList.set(hostname, 0)
}
- return await fetch(new URL(path, 'https://' + hostname))
+ return await fetch(new URL(path, 'https://' + hostname) )
.then(response => {
waitingList.set(hostname, config.courtesyWait)
return response.text()
@@ -150,11 +172,9 @@ const printFeed = async (sources, directory, header, viewOptions) => {
let tooLongAgo = viewOptions.tooLongAgo ?
(Date.now() - (Date.now() % oneDay)) - oneDay * viewOptions.tooLongAgo :
0
- let missingSources = 0
for(let source of sources) {
if(source == undefined) {
- missingSources++
continue
}
@@ -166,10 +186,6 @@ const printFeed = async (sources, directory, header, viewOptions) => {
feed = feed.sort((a, b) => a.date < b.date)
- if(missingSources) {
- console.log('Missing ' + missingSources + ' feeds!')
- }
-
// Render
let pages = []
@@ -184,7 +200,7 @@ const printFeed = async (sources, directory, header, viewOptions) => {
const writePage = (index, content) =>
promises.push(
- Bun.write(Path.join(directory, index == 0 ? 'index' : index) + '.html', content)
+ write(Path.join(directory, index == 0 ? 'index' : index.toString() ) + '.html', content)
)
for(let i = 0; i < pages.length; i++) {
@@ -194,7 +210,7 @@ const printFeed = async (sources, directory, header, viewOptions) => {
`end` :
`next`
- writePage(i, renderPage(`Page ${i + 1}`, pages[i], header, link))
+ writePage(i, renderPage(`Page ${i + 1}`, pages[i], header, link) )
}
if(pages.length == 0) {
@@ -213,9 +229,9 @@ const renderPage = (title, posts, header, footer) => {