Webmention sender endpoint for Indiekit. Automatically discovers and sends webmentions for published posts.
  • JavaScript 76.2%
  • Nunjucks 23.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ricardo f495792863 fix: report posts dropped before processing, and stop retrying dead ones
A post whose page could not be fetched was skipped with a bare continue,
before it reached allResults. The summary took its post count from the query
and its sent/failed/skipped counts from allResults, so a batch in which every
post was dropped reported:

  Processed 4 posts: 0 sent, 0 failed, 0 skipped

with an empty results array — indistinguishable from having nothing to do.

Unreachable posts were also never abandoned. Since the batch is ordered oldest
first and limited to 10, posts whose pages no longer exist occupied a slot on
every cycle indefinitely, and enough of them would starve newer posts entirely.

Count unreachable posts separately from skipped webmention targets, give up
after MAX_UNREACHABLE_ATTEMPTS cycles, and exclude abandoned posts from the
pending queue and from the pending counts on the dashboard and status API.
2026-08-16 14:54:26 +02:00
lib fix: report posts dropped before processing, and stop retrying dead ones 2026-08-16 14:54:26 +02:00
locales fix: report posts dropped before processing, and stop retrying dead ones 2026-08-16 14:54:26 +02:00
views fix: report posts dropped before processing, and stop retrying dead ones 2026-08-16 14:54:26 +02:00
CLAUDE.md docs: add CLAUDE.md technical reference 2026-02-13 18:23:14 +01:00
index.js fix: add localesDirectory getter for i18n support 2026-02-13 15:30:04 +01:00
package.json fix: report posts dropped before processing, and stop retrying dead ones 2026-08-16 14:54:26 +02:00
README.md Initial commit: Webmention sender endpoint for Indiekit 2026-02-06 11:06:38 +01:00

@rmdes/indiekit-endpoint-webmention-sender

Webmention sender endpoint for Indiekit. Automatically discovers and sends webmentions for published posts.

What it does

When triggered, this plugin:

  1. Finds posts that haven't had webmentions sent yet
  2. Extracts external links from post content
  3. Discovers webmention endpoints on target URLs (via Link header or HTML)
  4. Sends webmentions (or pingbacks as fallback)
  5. Marks posts as processed to avoid duplicate sends

Installation

npm install @rmdes/indiekit-endpoint-webmention-sender

Usage

Add @rmdes/indiekit-endpoint-webmention-sender to your Indiekit config:

export default {
  plugins: [
    "@rmdes/indiekit-endpoint-webmention-sender",
    // ... other plugins
  ],

  "@rmdes/indiekit-endpoint-webmention-sender": {
    mountPath: "/webmention-sender", // Optional, defaults to /webmention-sender
    timeout: 10000, // Optional, endpoint discovery timeout in ms
    userAgent: "My Site Webmention Sender", // Optional
  },
};

API

GET /webmention-sender

Returns status information about pending and sent webmentions.

Response:

{
  "pending": 5,
  "sent": 42
}

POST /webmention-sender

Processes pending posts and sends webmentions. Requires authentication.

Headers:

  • Authorization: Bearer <token> (must have update scope)

Query Parameters:

  • source_url (optional) - Process only a specific post URL

Response:

{
  "success": "OK",
  "success_description": "Processed 2 posts: 5 sent, 1 failed, 3 skipped",
  "results": [
    {
      "url": "https://example.com/posts/hello",
      "sent": [
        { "target": "https://other.site/article", "endpoint": "https://other.site/webmention", "type": "webmention", "status": 202 }
      ],
      "failed": [],
      "skipped": [
        { "target": "https://no-webmention.site/", "reason": "No webmention endpoint found" }
      ]
    }
  ]
}

Automatic Processing

For automatic webmention sending, add a polling loop to your deployment. Example for Cloudron's start.sh:

# Webmention sender - polls every 5 minutes
(
    echo "[webmention] Starting auto-send polling"
    while true; do
        SECRET=$(cat /app/data/config/.secret 2>/dev/null)
        ORIGIN="${CLOUDRON_APP_ORIGIN}"

        if [ -n "$SECRET" ]; then
            TOKEN=$(node -e "
                const jwt = require('jsonwebtoken');
                const token = jwt.sign(
                    { me: '$ORIGIN', scope: 'update' },
                    '$SECRET',
                    { expiresIn: '5m' }
                );
                console.log(token);
            " 2>/dev/null)

            if [ -n "$TOKEN" ]; then
                RESULT=$(curl -s -X POST "http://localhost:8080/webmention-sender?token=${TOKEN}" 2>&1)
                echo "[webmention] $(date '+%Y-%m-%d %H:%M:%S') - $RESULT"
            fi
        fi

        sleep 300  # 5 minutes
    done
) &

How it works

  1. Link Extraction: Uses Cheerio to parse HTML and extract all external links (excluding internal links and share intents)

  2. Endpoint Discovery: For each target URL:

    • Checks Link HTTP header for rel="webmention"
    • Checks X-Pingback header (fallback)
    • Parses HTML for <link rel="webmention"> or <a rel="webmention">
  3. Sending: Sends a POST request with source and target parameters:

    POST /webmention HTTP/1.1
    Content-Type: application/x-www-form-urlencoded
    
    source=https://your.site/post&target=https://their.site/article
    
  4. Tracking: Stores webmention-sent: true on processed posts in MongoDB to prevent duplicate sends

License

MIT