forked from bahamas10/ysap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-episodes-json
More file actions
executable file
·62 lines (56 loc) · 1.23 KB
/
Copy pathmake-episodes-json
File metadata and controls
executable file
·62 lines (56 loc) · 1.23 KB
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
#!/usr/bin/env bash
#
# Convert the list of episodes into JSON format - pass an argument to make it
# JSONP instead.
#
# Author: Dave Eddy <dave@daveeddy.com>
# Date: March 17, 2024
# License: MIT
varname=$1
baselink='https://ysap.sh'
# this is an "episode" object in the final json
read -d '' -r json <<-"EOF"
{
"title": $title,
"desc": $desc,
"link": $link,
"num": $num,
"external": {
"tiktok": $tiktok,
"youtube": $youtube,
"instagram": $instagram
}
}
EOF
# read data
objects=()
while IFS=$'\t' read -r num title desc link tt yt ig; do
object=$(jq -nc \
--arg title "$title" \
--arg desc "$desc" \
--arg link "$baselink$link" \
--argjson num "$num" \
--arg tiktok "$tt" \
--arg youtube "$yt" \
--arg instagram "$ig" \
"$json"
) || exit
objects+=("$object")
done < <(./make-list)
# generate output JSON
printf -v now '%(%s)T' -1
output=$(printf '%s\n' "${objects[@]}" | jq -n \
--argjson date "$now" \
--arg link "$baselink" \
'{
"name": "You Suck at Programming",
"site": $link,
"generated": $date,
"episodes": [inputs]
}'
)
# print the data (optionally as jsonp if the first arg is set)
if [[ -n $varname ]]; then
output="const $varname = $output;"
fi
echo "$output"