mirror of
https://github.com/nostr-protocol/nips.git
synced 2024-12-13 19:06:24 +00:00
add nip-20: web comments.
This commit is contained in:
parent
140d48e4e9
commit
9f9a864ce1
50
20.md
Normal file
50
20.md
Normal 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.
|
Loading…
Reference in New Issue
Block a user