diff options
| -rw-r--r-- | .forgejo/workflows/fetch-webmentions.yml | 75 |
1 files changed, 50 insertions, 25 deletions
diff --git a/.forgejo/workflows/fetch-webmentions.yml b/.forgejo/workflows/fetch-webmentions.yml index 3128f0e1..e29debcc 100644 --- a/.forgejo/workflows/fetch-webmentions.yml +++ b/.forgejo/workflows/fetch-webmentions.yml @@ -12,9 +12,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install jq - run: apk add --no-cache jq - - name: Fetch webmentions env: TOKEN: ${{ secrets.WEBMENTION_IO_TOKEN }} @@ -22,28 +19,56 @@ jobs: run: | mkdir -p data - curl -s "https://webmention.io/api/mentions.jf2?domain=$DOMAIN&token=$TOKEN" \ - | jq ' - .children - | map( - .["wm-target"] |= sub("^https?://[^/]+";"") - ) - | sort_by(."wm-target") - | group_by(."wm-target") - | map({ - (.[0]."wm-target"): - map({ - type: ."wm-property", - author: .author, - url: .url, - source: ."wm-source", - published: .published, - received: ."wm-received", - content: (if has("content") then .content else null end) - }) - }) - | add - ' > data/webmentions.json + curl -s "https://webmention.io/api/mentions.jf2?domain=$DOMAIN&token=$TOKEN" > data/webmentions_raw.json + + cat > /tmp/process_webmentions.py << 'PYTHON_SCRIPT' + import json + import re + import sys + + with open('data/webmentions_raw.json', 'r') as f: + data = json.load(f) + + children = data.get('children', []) + + # Process children + processed = [] + for child in children: + # Remove domain from wm-target + wm_target = child.get('wm-target', '') + wm_target = re.sub(r'^https?://[^/]+', '', wm_target) + child['wm-target'] = wm_target + processed.append(child) + + # Sort by wm-target + processed.sort(key=lambda x: x.get('wm-target', '')) + + # Group by wm-target + from itertools import groupby + result = {} + for target, group in groupby(processed, key=lambda x: x.get('wm-target', '')): + items = [] + for item in group: + processed_item = { + 'type': item.get('wm-property'), + 'author': item.get('author'), + 'url': item.get('url'), + 'source': item.get('wm-source'), + 'published': item.get('published'), + 'received': item.get('wm-received'), + 'content': item.get('content') if 'content' in item else None + } + items.append(processed_item) + result[target] = items + + with open('data/webmentions.json', 'w') as f: + json.dump(result, f, indent=2) + + import os + os.remove('data/webmentions_raw.json') + PYTHON_SCRIPT + + python3 /tmp/process_webmentions.py - name: Commit if changed run: | |
