diff options
| -rw-r--r-- | 20.md | 50 |
1 files changed, 50 insertions, 0 deletions
| @@ -0,0 +1,50 @@ | |||
| 1 | NIP-20 | ||
| 2 | ====== | ||
| 3 | |||
| 4 | Web Comments | ||
| 5 | ------------ | ||
| 6 | |||
| 7 | `draft` `optional` `author:fiatjaf` | ||
| 8 | |||
| 9 | A special event with kind `34` is defined, meaning "web comment". | ||
| 10 | |||
| 11 | 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. | ||
| 12 | |||
| 13 | The content should be the plaintext of the comment. | ||
| 14 | |||
| 15 | For 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 | |||
| 27 | URL Normalization | ||
| 28 | ----------------- | ||
| 29 | |||
| 30 | Early prototypes have been using the following naïve URL normalization algorithm: | ||
| 31 | |||
| 32 | ```js | ||
| 33 | export 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 | |||
| 50 | This is open for improvement, of course. | ||