forked from startup-systems/static
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.sh
More file actions
executable file
·79 lines (60 loc) · 1.51 KB
/
generate.sh
File metadata and controls
executable file
·79 lines (60 loc) · 1.51 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#set -ex
# YOUR CODE HERE
# MYVAR="/var/cpanel/users/joebloggs:DNS9=domain.com"
# NAME=${MYVAR%:*} # retain the part before the colon
# NAME=${NAME##*/} # retain the part after the last slash
# echo $NAME
if [ "$3" ]; then
echo "Too many arguments... "
echo "Aborting operation"
echo "---- Usage Help ----"
echo "COMMAND input-dir out-dir"
exit 1
fi
if [ "$1" ] && [ "$2" ]; then
#Check if input directory exists
if [ -d "$1" ]; then
echo "Parsing files in: $1"
else
echo "$1 does not exist!"
echo "Aborting operation!"
exit 1
fi
#Filepath ending check
# case "$2" in
# */)
# echo "has slash"
# ;;
# *)
# echo "doesn't have a slash"
# ;;
#esac
echo "Creating output directory: $2"
mkdir -pv "$2"
for file in "$1"/*.txt
do
echo "parsing ${file##*/}"
fname=${file##*/}
fname=${fname%.*}
fname="$fname".html
#Create HTML files
echo "-- creating $fname"
touch "$2"/"$fname"
# Extract title and body
title="$(head -n 1 "$file")"
body="$(tail -n +3 "$file")"
#Copy content
#cp template.html "$2"/"$fname"
sed "s/{{title}}/$title/g" template.html > "$2"/"$fname".temp
sed "s/{{body}}/$body/g" "$2"/"$fname".temp > "$2"/"$fname"
done
rm "$2"/*.temp
echo "--------------------------"
echo "HTML generation completed!"
echo "--------------------------"
else
echo "Arguments misssing... "
echo "Aborting operation!"
exit 1
fi