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
·40 lines (37 loc) · 924 Bytes
/
generate.sh
File metadata and controls
executable file
·40 lines (37 loc) · 924 Bytes
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
#!/bin/bash
set -e
#Make directories recursively
mkdir -p "$2"
for f in $1/*
do
count=0
filename=$(basename "$f" .txt)
echo "Converting $f to $filename.html"
#Read line by line
while IFS='' read -r temp || [[ -n "$temp" ]]; do
#echo "Text read from file: $temp"
if [ $count == 0 ]
then
title=$temp
elif [ $count -ge 2 ]
then
body="$temp" #concatenate each subsequent line
fi
count=$((count+1))
done < "$f"
#Export using template
echo "
<!DOCTYPE html>
<html>
<head>
<meta charset=\"utf-8\">
<title>$title</title>
</head>
<body>
$body
</body>
</html>
" > "$2/$filename.html"
done
#Sources:
#http://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable