mirror of https://github.com/lukechilds/nips.git
fiatjaf
2 years ago
1 changed files with 50 additions and 0 deletions
@ -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. |
Loading…
Reference in new issue