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
·51 lines (42 loc) · 1.27 KB
/
generate.sh
File metadata and controls
executable file
·51 lines (42 loc) · 1.27 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
#!/bin/bash
set -ex
#YOUR CODE HERE
#python3 generate.py $1 $2
inputFolder=$1
outputFolder=$2
if [ ! -d "$outputFolder" ]; then
mkdir -p "$outputFolder"
fi
find "$inputFolder" -name '*.txt' > file.txt
while IFS='' read -r file || [[ -n "$file" ]]; do
fullFilePath=$file
baseFileName=$(basename "$fullFilePath" .txt)
#baseFileName=`echo $baseFileName | cut -f 1 -d .`
title=''
body=''
flag=0
fileWithNewline=$(cat "$fullFilePath")\\n
echo "$fileWithNewline" > tempFile.txt
#echo "\n" >> "$fullFilePath"
while read -r line; do
#check=$(echo "$line" | wc -c)
check=${#line}
if [ "$check" -eq 0 ] && [ "$flag" -eq 0 ]; then
flag=1
elif [ $flag -eq 0 ]; then
title="${line}"
else
if [ "$check" -eq 0 ];then
body="<p>${line}<\/p>"
else
body="${body}${line}"
fi
fi
done < tempFile.txt
#body="${body}"
cp template.html "${outputFolder}/${baseFileName}.html"
sed -i -e "s/{{title}}/$title/g" -e "s/{{body}}/$body/g" "${outputFolder}/${baseFileName}.html"
done < file.txt
#References:
#http://stackoverflow.com/questions/4321456/find-exec-a-shell-function
#http://tldp.org/LDP/abs/html/x23170.html