diff --git a/automations/webmentions.ts b/automations/webmentions.ts index eddbcea8..167c362f 100644 --- a/automations/webmentions.ts +++ b/automations/webmentions.ts @@ -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); @@ -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, ""); diff --git a/package-lock.json b/package-lock.json index 5d644571..eaf0cc68 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,6 +37,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", @@ -70,6 +71,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" } @@ -3331,10 +3333,13 @@ "dev": true }, "node_modules/@types/node": { - "version": "17.0.20", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.20.tgz", - "integrity": "sha512-Q15Clj3lZSLnhVA6yKw1G7SQz46DeL9gO1TEgfK1OQGvMdQ6TUWmCeWf1QBUNkw2BDfV52i2YuYd9OF3ZwGhjw==", - "dev": true + "version": "20.11.16", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.16.tgz", + "integrity": "sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } }, "node_modules/@types/resolve": { "version": "1.17.1", @@ -10680,6 +10685,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/uc.micro": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", @@ -10719,6 +10737,12 @@ "integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A==", "dev": true }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", @@ -13875,10 +13899,13 @@ "dev": true }, "@types/node": { - "version": "17.0.20", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.20.tgz", - "integrity": "sha512-Q15Clj3lZSLnhVA6yKw1G7SQz46DeL9gO1TEgfK1OQGvMdQ6TUWmCeWf1QBUNkw2BDfV52i2YuYd9OF3ZwGhjw==", - "dev": true + "version": "20.11.16", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.16.tgz", + "integrity": "sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ==", + "dev": true, + "requires": { + "undici-types": "~5.26.4" + } }, "@types/resolve": { "version": "1.17.1", @@ -19386,6 +19413,12 @@ "integrity": "sha512-eaBzG6MxNzEn9kiwvtre90cXaNLkmadMWa1zQMs3XORCXNbsH/OewwbxC5ia9dCxIxnTAsSxXJaa/p5y8DlvJg==", "dev": true }, + "typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true + }, "uc.micro": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", @@ -19416,6 +19449,12 @@ "integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A==", "dev": true }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", diff --git a/package.json b/package.json index 1ab9fbe3..d7f840a1 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", @@ -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" }, diff --git a/tsconfig.json b/tsconfig.json index 116ce256..f668f6f7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,8 @@ "module": "esnext", "target": "esnext", "moduleResolution": "node", - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "lib": ["esnext", "dom"], }, "include": [ "automations/**/*.ts"