upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiatjaf <fiatjaf@gmail.com>2022-07-20 14:26:47 -0300
committerfiatjaf <fiatjaf@gmail.com>2022-07-20 14:26:47 -0300
commit9f9a864ce1e1ebfdcfdd4835cd60807440f038e8 (patch)
tree5dd618cd51b68a629b0be8fd0e9f24cc669a109c
parent140d48e4e95535ca9e3b99e2de93165096f3bc10 (diff)
add nip-20: web comments.nip20-web-comments
-rw-r--r--20.md50
1 files changed, 50 insertions, 0 deletions
diff --git a/20.md b/20.md
new file mode 100644
index 0000000..5852999
--- /dev/null
+++ b/20.md
@@ -0,0 +1,50 @@
1NIP-20
2======
3
4Web Comments
5------------
6
7`draft` `optional` `author:fiatjaf`
8
9A special event with kind `34` is defined, meaning "web comment".
10
11Events 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.
12
13The content should be the plaintext of the comment.
14
15For example:
16
17```json
18{
19 "kind": 34,
20 "tags": [
21 ["r", "https://random.blog/article"]
22 ],
23 "content": "I didn't like this article.",
24 ...other fields
25```
26
27URL Normalization
28-----------------
29
30Early prototypes have been using the following naïve URL normalization algorithm:
31
32```js
33export function normalizeURL(raw) {
34 let url = new URL(raw)
35 return (
36 url.origin
37 .replace('://m.', '://') // remove known 'mobile' subdomains
38 .replace('://mobile.', '://')
39 .replace('http://', 'https://') // default everything to https (maybe a terrible idea)
40 .replace( /:\d+/, port => (port === ':443' || port === ':80' ? '' : port)) + // remove 443 and 80 ports
41 url.pathname
42 .replace(/\/+/g, '/') // remove duplicated slashes in the middle of the path
43 .replace(/\/*$/, '') // remove slashes from the end of path
44
45 // notice that only origin ("https://random.blog") and pathname ("/article") are used, all the rest is thrown away
46 )
47}
48```
49
50This is open for improvement, of course.