add nip-20: web comments.

This commit is contained in:
fiatjaf 2022-07-20 14:26:47 -03:00
parent 140d48e4e9
commit 9f9a864ce1

50
20.md Normal file
View File

@ -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.