-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_to_markdown.sh
executable file
·37 lines (30 loc) · 1.13 KB
/
json_to_markdown.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
#!/bin/bash
## Add opening comment to mark the start of managed content
echo "<!-- managed_by_embed -->"
# Iterate over each JSON file
for json_file in "$@"; do
if [[ -f "$json_file" ]]; then
# Extract the file name
json_file_name=$(basename "$json_file")
# Read the content of the JSON file
json_file_content=$(cat "$json_file")
# Extract the name from the JSON file. Use the name inside the achievement object
# not the top level name. The latter is optional, the former is required.
name=$(jq -r '.credentialSubject.achievement.name' "$json_file")
# Extract institute name from the JSON file. Use the name inside the issuer
institute=$(jq -r '.issuer.name' "$json_file")
# Print the templated html to the console
echo "<details markdown=\"1\">"
echo "<summary>$institute - $name - $json_file_name</summary>"
echo ""
echo "<a href=\"$json_file\">📥 Download JSON</a>"
echo ""
echo "\`\`\`json"
echo "$json_file_content"
echo "\`\`\`"
echo ""
echo "</details>"
fi
done
# Add closing comment to mark the end of managed content
echo "<!-- /managed_by_embed -->"