Initial commit
This commit is contained in:
commit
ce96694f13
|
@ -0,0 +1,2 @@
|
|||
.DS_Store
|
||||
node_modules/
|
|
@ -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).
|
|
@ -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}`);
|
||||
});
|
File diff suppressed because it is too large
Load Diff
|
@ -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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue