-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate-readme.sh
executable file
·64 lines (53 loc) · 1.78 KB
/
generate-readme.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
#!/usr/bin/env bash
set -Eeuo pipefail
declare -A sharedTags
declare -a simpleTags=()
while read -r line; do
if [[ "$line" == "Tags: "* ]]; then
line="${line#Tags: }"
line="$(echo "$line" | tr -d ,)"
canonicalTag="${line%% *}"
simpleTags+=( "$line" )
elif [[ "$line" == "SharedTags: "* ]]; then
line="${line#SharedTags: }"
line="$(echo "$line" | tr -d ,)"
for sharedTag in $line; do
if [ -z "${sharedTags[$sharedTag]+set}" ]; then
sharedTags[$sharedTag]="$canonicalTag"
else
sharedTags[$sharedTag]="${sharedTags[$sharedTag]} $canonicalTag"
fi
done
else
unset canonicalTag
fi
done
simpleTagSection=""
for line in "${simpleTags[@]}"; do
simpleTagSection="$simpleTagSection- "
for tag in $line; do
simpleTagSection="$simpleTagSection \`$tag\`"
done
simpleTagSection="$simpleTagSection
"
done
sharedTagSection=""
declare -A skip=()
for sharedTag in "${!sharedTags[@]}"; do
[ -z "${skip[$sharedTag]+set}" ] || continue
sharedTagSection="$sharedTagSection- \`$sharedTag\`"
for sharedTag2 in "${!sharedTags[@]}"; do
! [ "$sharedTag" = "$sharedTag2" ] || continue
if [ "${sharedTags[$sharedTag]}" = "${sharedTags[$sharedTag2]}" ]; then
skip[$sharedTag2]="yes"
sharedTagSection="$sharedTagSection, \`$sharedTag2\`"
fi
done
sharedTagSection="$sharedTagSection
"
for tag in ${sharedTags[$sharedTag]}; do
sharedTagSection="$sharedTagSection - \`$tag\`
"
done
done
awk -v r="$simpleTagSection" '{gsub(/INSERT-SIMPLE-TAGS/,r)}1' hub-description-template.md | awk -v r="$sharedTagSection" '{gsub(/INSERT-SHARED-TAGS/,r)}1' | sed -e "s,%%IMAGE%%,$1,g"