-
Notifications
You must be signed in to change notification settings - Fork 13
/
json_to_md.sh
executable file
·54 lines (45 loc) · 1.64 KB
/
json_to_md.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
#!/bin/bash
#Parses the operation description file and generates an indivdiual md file for each
# Check if a JSON file argument is provided
if [ -z "$1" ]; then
echo "Usage: $0 <path_to_json_file>"
exit 1
fi
# Define the input JSON file and output directory
json_file="$1"
output_dir="../AdaCADdocs/docs/howtouse/operations/"
# Create the output directory if it doesn't exist
mkdir -p "$output_dir"
# Use jq to parse each operation and create separate markdown files
jq -c '.operation[]' "$json_file" | while read -r operation; do
# Extract fields from JSON
echo "parsing"
name=$(echo "$operation" | jq -r '.name')
displayname=$(echo "$operation" | jq -r '.displayname')
tags=$(echo "$operation" | jq -r '.tags | join(", ")')
description=$(echo "$operation" | jq -r '.description')
application=$(echo "$operation" | jq -r '.application')
# Set filename based on the operation name
filename="${output_dir}/$(echo "$name" | tr ' /' '__' | tr '[:upper:]' '[:lower:]').md"
# Write content to the Markdown file
{
echo "---"
echo "title: $displayname"
echo "sidebar_label: $displayname"
echo "tags: [${tags}]"
echo "draft: true"
echo "---"
echo "# $name"
echo "<!--![file](./img/$name.png)-->"
echo "## Parameters"
echo "- tbd"
echo "## Description"
echo "$description"
echo "## Application"
echo "$application"
echo "## Developer"
echo "adacad id: $name"
} > "$filename"
echo "Created $filename"
done
echo "All operations have been parsed into separate Markdown files in $output_dir"