Skip to content

threenine/nuxstr-comments

Repository files navigation

Nuxstr Comments

npm version npm downloads License Nuxt

Enable nostr protocol based comment system on your Nuxt 4 based applications.

Features

  • Nostr-powered comments for Nuxt Content blog posts
  • NIP-07 Browser Extension login prompt if user is not authenticated
  • NIP-22 Plain Text Content - (no HTML, Markdown, or other formatting)
  • Configurable relay list and tagging strategy
  • Comments are published as kind:1111 as Website Url
{
  "kind": 1111,
  "content": "Nice article!",
  "tags": [
    // referencing the root url
    ["I", "https://abc.com/articles/1"],
    // the root "kind": for an url
    ["K", "web"],

    // the parent reference (same as root for top-level comments)
    ["i", "https://abc.com/articles/1"],
    // the parent "kind": for an url
    ["k", "web"]
  ]
  // other fields
}

Warning

NuxstrComments [NIP-22] MUST NOT be used to reply to kind 1 notes.
NIP-10 should instead be followed.

Quick Setup

Install the module to your Nuxt application with one command:

npx nuxi module add @threenine/nuxstr-comments

That's it! You can now use Nuxstr Comments in your Nuxt app ✨

Usage

By default, the component tags comments by the current route path (e.g., content:/blog/my-post) and fetches them from configured relays.

  1. Configuration (nuxt.config.ts):
export default defineNuxtConfig({
  modules: [
    '@threenine/nuxstr-comments',
  ],
  nuxstrComments: {
    relays: ['wss://relay.damus.io', 'wss://relay.nostr.band'],
    tagStrategy: 'path',
    tagPrefix: 'comment:',
  },
})
  1. Add the comments component where you want comments to appear (usually below a ContentDoc):
<template>
  <div>
      <NuxstrComments />
  </div>
</template>

Select your preferred relays from the list of relays and configure the tag strategy and tag prefix.

When a user attempts to post, they will be prompted to log in with their Nostr browser extension NIP-07.

Comments are published as kind: 1111 as defined in NIP-22 notes tagged with a t tag containing the content tag (e.g., comment:/blog/my-post).

Replys to comments are enabled, and are also published as kind: 1111, as defined in NIP-22

Contribution

Local development
# Install dependencies
pnpm install

# Generate type stubs
pnpm run dev:prepare

# Develop with the playground
pnpm run dev

# Build the playground
pnpm run dev:build

# Run ESLint
pnpm run lint

# Run Vitest
pnpm run test
pnpm run test:watch

# Release new version
pnpm run release

Support

⚡️ lightning address:

threenine@getalby.com

Buy Me A Coffee