Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
#!/bin/bash
set -e
#Make directories recursively
mkdir -p "$2"

set -ex
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

# YOUR CODE HERE
#Sources:
#http://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable