nips/20.md
2022-07-20 14:26:47 -03:00

1.3 KiB

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:

{
  "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:

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.