-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.sh
107 lines (101 loc) · 3.64 KB
/
publish.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# shellcheck shell=dash
CHARACTER_ID=57410
fp="README.md"
flag=0
while read -r line; do
if [ "$line" = "---" ] || [ "$line" = "---" ]; then
if [ "$flag" -eq 0 ]; then
flag=1
elif [ "$flag" -eq 1 ]; then
content="$(cat)"
break
fi
else
if [ "$flag" -eq 1 ]; then
key="$(printf "%s\n" "$line" | awk '{print $1}')"
case "$key" in
title:)
title="$(printf "%s\n" "$line" | awk -F ': ' '{print $2}')"
eval "title=\"$title\""
;;
summary:)
summary="$(printf "%s\n" "$line" | awk -F ': ' '{print $2}')"
eval "summary=\"$summary\""
;;
cover:)
cover="$(printf "%s\n" "$line" | awk -F ': ' '{print $2}')"
eval "cover=\"$cover\""
;;
slug:)
slug="$(printf "%s\n" "$line" | awk -F ': ' '{print $2}')"
eval "slug=\"$slug\""
;;
tags:)
tags="$(printf "%s\n" "$line" | awk -F ': ' '{print $2}' | jq -c '.[]' | tr '\n' ',' | sed 's/,$//')"
;;
note_id:)
note_id="$(printf "%s\n" "$line" | awk -F ': ' '{print $2}')"
eval "note_id=\"$note_id\""
;;
esac
fi
fi
done < "$fp"
content="$(echo "$content" | jq -Rs -r '@json')"
if [ -z "$title" ] || [ -z "$summary" ] || [ -z "$cover" ] || [ -z "$slug" ] || [ -z "$tags" ]; then
echo "Error: Missing required metadata。"
exit 1
fi
if [ -n "$note_id" ]; then
echo Update note
curl -X POST -v \
-H "Authorization: Bearer $XLOG_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"metadata": {
"tags": ["post", '"$tags"'],
"type": "note",
"title": "'"$title"'",
"content": '"$content"',
"summary": "'"$summary"'",
"sources": ["xlog"],
"date_published": "2024-03-04T00:00:00.000Z",
"attributes": [{
"value": "'"$slug"'",
"trait_type": "xlog_slug"
}],
"attachments": [{
"name": "cover",
"address": "'"$cover"'",
"mime_type": ""
}]
}
}' \
"https://indexer.crossbell.io/v1/siwe/contract/characters/$CHARACTER_ID/notes/${note_id}/metadata"
else
echo Create note
curl -X PUT -v \
-H "Authorization: Bearer $XLOG_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"metadata": {
"tags": ["post", '"$tags"'],
"type": "note",
"title": "'"$title"'",
"content": '"$content"',
"summary": "'"$summary"'",
"sources": ["xlog"],
"date_published": "2024-05-13T00:00:00.000Z",
"attributes": [{
"value": "'"$slug"'",
"trait_type": "xlog_slug"
}],
"attachments": [{
"name": "cover",
"address": "'"$cover"'",
"mime_type": ""
}]
}
}' \
"https://indexer.crossbell.io/v1/siwe/contract/characters/${CHARACTER_ID}/notes"
fi