-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom2activity.sh
64 lines (55 loc) · 1.54 KB
/
atom2activity.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
PUBLIC=public
ATOM=$PUBLIC/atom.xml
BASE_URL=https://<YOUR_HOST>
mapfile -t dates < <(grep -Po '<published>\K[^<]*(?=</published>)' $ATOM)
mapfile -t titles < <(grep -Po '<title>\K[^<]*(?=</title>)' $ATOM)
mapfile -t slugs < <(grep -Po "<link href=\"$BASE_URL/\K[^/]*" $ATOM)
# Remove the top level <title> & <link>
titles=("${titles[@]:1}")
slugs=("${slugs[@]:1}")
read -r -d '' outbox <<EOF
{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "$BASE_URL/outbox",
"type": "OrderedCollection",
"totalItems": ${#dates[@]},
"orderedItems": [
EOF
mkdir -p $PUBLIC/note
mkdir -p $PUBLIC/create
mkdir -p $PUBLIC/likes
mkdir -p $PUBLIC/replies
for i in "${!dates[@]}"; do
SLUG=${slugs[i]}
PATH_CREATE=create/$SLUG
PATH_NOTE=note/$SLUG
read -r -d '' NOTE <<EOF
{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "$BASE_URL/$PATH_NOTE",
"url": "$BASE_URL/$SLUG",
"attributedTo": "$BASE_URL/actor",
"likes": "$BASE_URL/likes/$SLUG",
"replies": "$BASE_URL/replies/$SLUG",
"type": "Note",
"published": "${dates[i]}",
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"cc": ["$BASE_URL/followers"],
"content": "New post: <a href=\"$BASE_URL/$SLUG\">${titles[i]}</a>."
}
EOF
echo "$NOTE" >$PUBLIC/"$PATH_NOTE"
read -r -d '' CREATE <<EOF
{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "$BASE_URL/$PATH_CREATE",
"type": "Create",
"actor": "$BASE_URL/actor",
"object": "$BASE_URL/$PATH_NOTE"
}
EOF
echo "$CREATE" >$PUBLIC/"$PATH_CREATE"
outbox="$outbox$CREATE,"
done
echo "${outbox::-1}]}" >$PUBLIC/outbox