From 9f9a864ce1e1ebfdcfdd4835cd60807440f038e8 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 20 Jul 2022 14:26:47 -0300 Subject: [PATCH] add nip-20: web comments. --- 20.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 20.md diff --git a/20.md b/20.md new file mode 100644 index 00000000..58529990 --- /dev/null +++ b/20.md @@ -0,0 +1,50 @@ +NIP-20 +====== + +Web Comments +------------ + +`draft` `optional` `author:fiatjaf` + +A special event with kind `34` is defined, meaning "web comment". + +Events of this kind should have at least one `r` tag with the value set to the normalized URL of the webpage they're commenting in. + +The content should be the plaintext of the comment. + +For example: + +```json +{ + "kind": 34, + "tags": [ + ["r", "https://random.blog/article"] + ], + "content": "I didn't like this article.", + ...other fields +``` + +URL Normalization +----------------- + +Early prototypes have been using the following naïve URL normalization algorithm: + +```js +export function normalizeURL(raw) { + let url = new URL(raw) + return ( + url.origin + .replace('://m.', '://') // remove known 'mobile' subdomains + .replace('://mobile.', '://') + .replace('http://', 'https://') // default everything to https (maybe a terrible idea) + .replace( /:\d+/, port => (port === ':443' || port === ':80' ? '' : port)) + // remove 443 and 80 ports + url.pathname + .replace(/\/+/g, '/') // remove duplicated slashes in the middle of the path + .replace(/\/*$/, '') // remove slashes from the end of path + + // notice that only origin ("https://random.blog") and pathname ("/article") are used, all the rest is thrown away + ) +} +``` + +This is open for improvement, of course.