From a9c9ca866c95f5511411621d5debc563930b8732 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 12 Jan 2026 08:43:25 +0000 Subject: [PATCH] Adding mentions script and initial config --- .webmentions-sent | 0 config.yml | 9 +++ content/now/software.md | 6 +- layouts/_default/list.webmentions.json | 36 ++++++++++ send-webmentions.sh | 97 ++++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 .webmentions-sent create mode 100644 layouts/_default/list.webmentions.json create mode 100755 send-webmentions.sh diff --git a/.webmentions-sent b/.webmentions-sent new file mode 100644 index 0000000..e69de29 diff --git a/config.yml b/config.yml index 73ee525..6b6a541 100644 --- a/config.yml +++ b/config.yml @@ -6,6 +6,15 @@ buildFuture: false buildExpired: false enableEmoji: true +outputs: + home: ["HTML", "RSS", "webmentions"] + +outputFormats: + webmentions: + mediaType: "application/json" + baseName: "webmentions" + isPlainText: true + pagination: pagerSize: 5 diff --git a/content/now/software.md b/content/now/software.md index de9a2d0..52456ed 100644 --- a/content/now/software.md +++ b/content/now/software.md @@ -7,13 +7,13 @@ order: 4 **Software:** -- **Browser** - [Zen](https://zen-browser.app/) +- **Browser** - [Zen](https://zen-browser.app/) - **Code Editor** - VS Code - **Audio** - High Tide & Turntable -- **Password Manager** - 1password +- **Password Manager** - [Proton Pass](https://pr.tn/ref/MNB13JYX) **Hardware:** - **Keyboard** - Ducky One 3 Classic 65% w/ Cherry Red switches - **Mouse** - Razer Naga X -- **Microphone** - Marantz MPM-1000 \ No newline at end of file +- **Microphone** - Marantz MPM-1000 diff --git a/layouts/_default/list.webmentions.json b/layouts/_default/list.webmentions.json new file mode 100644 index 0000000..2a04202 --- /dev/null +++ b/layouts/_default/list.webmentions.json @@ -0,0 +1,36 @@ +{{- $links := slice -}} +{{- $excludeDomains := slice "ritual.sh" "last.fm" "www.last.fm" "amazon.co.uk" "www.amazon.co.uk" "amazon.com" "www.amazon.com" -}} + +{{- range .Site.RegularPages -}} + {{- $postUrl := .Permalink -}} + {{- $content := .Content -}} + + {{- /* Extract all hrefs from content */ -}} + {{- $hrefs := findRE `href="([^"]+)"` $content -}} + + {{- range $hrefs -}} + {{- $href := . | replaceRE `href="([^"]+)"` "$1" -}} + + {{- /* Only external links */ -}} + {{- if hasPrefix $href "http" -}} + {{- $shouldExclude := false -}} + + {{- /* Check if href contains any excluded domain */ -}} + {{- range $excludeDomains -}} + {{- if in $href . -}} + {{- $shouldExclude = true -}} + {{- end -}} + {{- end -}} + + {{- if not $shouldExclude -}} + {{- $links = $links | append (dict "source" $postUrl "target" $href) -}} + {{- end -}} + {{- end -}} + {{- end -}} +{{- end -}} +[ +{{ range $i, $link := $links -}} +{{ if $i }}, +{{ end }} {"source":"{{ $link.source }}","target":"{{ $link.target }}"} +{{ end -}} +] \ No newline at end of file diff --git a/send-webmentions.sh b/send-webmentions.sh new file mode 100755 index 0000000..7a34f34 --- /dev/null +++ b/send-webmentions.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +# Load environment variables from .env file +if [ -f .env ]; then + export $(cat .env | grep -v '^#' | xargs) +else + echo "⚠️ Warning: .env file not found, using defaults" +fi + +# Use environment variables with fallback defaults +WEBMENTIONS_FILE="${WEBMENTIONS_FILE:-public/webmentions.json}" +SENT_CACHE="${SENT_CACHE:-.webmentions-sent}" +API_ENDPOINT="${API_ENDPOINT:-https://api.ritual.sh/webmention/send}" +API_KEY="${API_KEY:-your-secret-key}" + +# Check for dry-run flag +DRY_RUN=false +if [ "$1" = "--dry-run" ] || [ "$1" = "-n" ]; then + DRY_RUN=true + echo "🔍 DRY RUN MODE - No webmentions will be sent" + echo "================================================" +fi + +# Create cache file if it doesn't exist +touch "$SENT_CACHE" + +# Read the webmentions JSON +if [ ! -f "$WEBMENTIONS_FILE" ]; then + echo "No webmentions.json found" + exit 0 +fi + +# Count totals +TOTAL=0 +ALREADY_SENT=0 +TO_SEND=0 + +# Process each link +jq -c '.[]' "$WEBMENTIONS_FILE" | while read -r mention; do + source=$(echo "$mention" | jq -r '.source') + target=$(echo "$mention" | jq -r '.target') + + TOTAL=$((TOTAL + 1)) + + # Create unique key for this source->target pair + key="${source}|${target}" + + # Check if already sent + if grep -Fxq "$key" "$SENT_CACHE"; then + if [ "$DRY_RUN" = true ]; then + echo "⏭️ Already sent: $source -> $target" + else + echo "Already sent: $source -> $target" + fi + ALREADY_SENT=$((ALREADY_SENT + 1)) + continue + fi + + TO_SEND=$((TO_SEND + 1)) + + if [ "$DRY_RUN" = true ]; then + echo "📤 Would send: $source -> $target" + else + echo "Sending webmention: $source -> $target" + + # Send to your API + response=$(curl -s -w "\n%{http_code}" -X POST "$API_ENDPOINT" \ + -H "Authorization: Bearer $API_KEY" \ + -H "Content-Type: application/json" \ + -d "$mention") + + http_code=$(echo "$response" | tail -n1) + + # If successful, add to cache + if [ "$http_code" = "200" ] || [ "$http_code" = "202" ]; then + echo "$key" >> "$SENT_CACHE" + echo "✓ Sent successfully" + else + echo "✗ Failed with status $http_code" + fi + + # Be nice to endpoints - don't spam + sleep 1 + fi +done + +# Summary +echo "" +echo "================================================" +if [ "$DRY_RUN" = true ]; then + echo "🔍 DRY RUN SUMMARY" +else + echo "✅ Webmentions processing complete" +fi +echo "Total links found: $TOTAL" +echo "Already sent: $ALREADY_SENT" +echo "To send: $TO_SEND" \ No newline at end of file