-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert-tables.sh
executable file
·29 lines (27 loc) · 1.28 KB
/
insert-tables.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
#!/usr/bin/env bash
# Simple shell script to replace yaml file refs with html-ified content of said ref
#
# Yaml refs are always on a line by itself, and is preceded with ! in the first position
# After the script is run, the yaml ref is replaced with html generated from the yaml file.
# Find all .md files:
for file in $(find docs -name '*.md'); do
# for each .md file, check for yaml refs
if grep -lq '^!.*\.yaml$' $file; then
# echo "Fann deg! $file"
# collect all yaml refs in a list, removing the initial !:
yamls=$(grep '^!.*\.yaml$' $file | cut -c2- )
# Loop over that list:
for yamlfile in $yamls; do
# echo Yamlfile: $yamlfile
# Get the full pathname of the yaml file, relative to $file:
yamlpathfile=$(echo $(dirname $file)/$yamlfile)
# echo Yamlpathfile: $yamlpathfile
# convert yaml to html, and store in temp file:
deno run --allow-read ./generate-tables.ts $yamlpathfile > $yamlpathfile.html
# Replace yaml ref with temp html file (actuall: insert after ref, then delete ref):
sed -i '' -e "/$yamlfile/r $yamlpathfile.html" -e "/$yamlfile/d" "$file"
# remove temp file:
rm -f "$yamlpathfile.html"
done
fi
done;