Initial commit

This commit is contained in:
Shadowfacts 2021-11-06 10:05:58 -04:00
commit ce96694f13
5 changed files with 2119 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.DS_Store
node_modules/

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# frenzy-readability
A microservice for using Mozilla's [readability](https://github.com/mozilla/readability) library as an extractor for [Frenzy](https://git.shadowfacts.net/shadowfacts/frenzy).

33
index.js Normal file
View File

@ -0,0 +1,33 @@
import { Readability } from "@mozilla/readability";
import { JSDOM } from "jsdom";
import express from "express";
import morgan from "morgan";
import bodyParser from "body-parser";
import createDOMPurify from "dompurify";
const app = express();
app.use(morgan('combined'));
app.use(bodyParser.text({
type: "text/html",
}));
app.get('/status', (req, res) => {
res.type('text/plain').send('OK');
});
app.post('/readability', (req, res) => {
const doc = new JSDOM(req.body, {
url: req.params.url,
});
const reader = new Readability(doc.window.document);
const article = reader.parse();
const purifier = createDOMPurify(doc.window);
const cleaned = purifier.sanitize(article.content);
res.send(cleaned);
});
const port = process.env.PORT || 4001;
// only accept local requests
app.listen(port, "localhost", () => {
console.log(`listening on port ${port}`);
});

2057
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

25
package.json Normal file
View File

@ -0,0 +1,25 @@
{
"name": "frenzy-readability",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "https://git.shadowfacts.net/shadowfacts/frenzy-readability"
},
"author": "",
"license": "MIT",
"dependencies": {
"@mozilla/readability": "^0.4.1",
"body-parser": "^1.19.0",
"dompurify": "^2.3.3",
"express": "^4.17.1",
"jsdom": "^18.0.0",
"morgan": "^1.10.0"
}
}