Skip to content

Commit

Permalink
fix: filter out deleted webmentions
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoehnelt committed Feb 5, 2024
1 parent 44f1652 commit a7f6a4a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 10 deletions.
16 changes: 15 additions & 1 deletion automations/webmentions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ import dotenv from "dotenv";
import { JSDOM } from "jsdom";
import DOMPurify from "dompurify";

interface WebMention {
"wm-id": string;
"wm-source": string;
"wm-target": string;
"wm-property": string;
"wm-received": string;
content?: {
text: string;
html: string;
};
url: string;
}

const window = new JSDOM("").window;
const purify = DOMPurify(window);

Expand Down Expand Up @@ -40,12 +53,13 @@ const main = async () => {
.then(get("children"))
.then(writeMentionsToFile);

function writeMentionsToFile(mentions) {
function writeMentionsToFile(mentions: WebMention[]) {
const all = {};
mentions
.filter((mention) =>
BLOCKLIST.every((url) => !mention["wm-source"].includes(url))
)
.filter((mention) => mention.content?.text !== "[deleted]")
.forEach((mention) => {
let target = mention["wm-target"].replace(domain, "");

Expand Down
55 changes: 47 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"prepare:mastodon": "esbuild automations/mastodon.ts --outfile=dist/mastodon.mjs --bundle --platform=node --format=esm --external:./node_modules/*",
"prepare:npm": "esbuild automations/npm.ts --outfile=dist/npm.mjs --bundle --platform=node --format=esm --external:./node_modules/*",
"prepare:webmentions": "esbuild automations/webmentions.ts --outfile=dist/webmentions.mjs --bundle --platform=node --format=esm --external:./node_modules/*",
"test": "tsc --noEmit",
"webmentions": "node dist/webmentions.mjs"
},
"devDependencies": {
Expand All @@ -35,6 +36,7 @@
"@types/linkify-it": "^3.0.2",
"@types/markdown-it": "^12.2.3",
"@types/mdurl": "^1.0.2",
"@types/node": "^20.11.16",
"@types/universal-analytics": "^0.4.5",
"autoprefixer": "^10.4.14",
"axios": "^1.6.0",
Expand Down Expand Up @@ -68,6 +70,7 @@
"rimraf": "^5.0.1",
"slugify": "^1.6.6",
"tailwindcss": "^3.3.3",
"typescript": "^5.3.3",
"url": "^0.11.1",
"workbox-build": "^7.0.0"
},
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"lib": ["esnext", "dom"],
},
"include": [
"automations/**/*.ts"
Expand Down

0 comments on commit a7f6a4a

Please sign in to comment.