Initial commit

main
Shadowfacts 1 year ago
commit ce96694f13
  1. 2
      .gitignore
  2. 2
      README.md
  3. 33
      index.js
  4. 2057
      package-lock.json
  5. 25
      package.json

2
.gitignore vendored

@ -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}`);
});

2057
package-lock.json generated

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…
Cancel
Save