Adding mentions script and initial config

This commit is contained in:
Dan 2026-01-12 08:43:25 +00:00
parent aa6b1ee3c1
commit a9c9ca866c
5 changed files with 145 additions and 3 deletions

0
.webmentions-sent Normal file
View file

View file

@ -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

View file

@ -10,7 +10,7 @@ order: 4
- **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:**

View file

@ -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 -}}
]

97
send-webmentions.sh Executable file
View file

@ -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"