Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
Open
Show file tree
Hide file tree
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
67 changes: 65 additions & 2 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
#!/bin/bash

set -ex
#set -ex

# YOUR CODE HERE
input=$1
output=$2


echo "Input Dir: $input"
echo "Output Dir: $output"

#Create output directory structure if it doesn't exist.
mkdir -p "$output"

#Embedbed template
template='<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{title}}</title>
</head>
<body>
{{body}}
</body>
</html>
'

for filename in $input/*.txt; do
message=""
title=""
i=0
destFilename="$(basename "$filename" | sed 's/.txt/.html/')"

#echo "File: $filename"
#echo "Dest Filename: $destFilename"
echo "Archivo:"
cat "$filename"
echo -e "\n"

while read -r line
do
echo "$i Linea: $line"
if [ $i -eq 0 ]
then
title=$line
fi
if [ $i -gt 1 ]
then
if [ -z "$message" ]
then
message="$line"
else
message="$message\n$line"
fi

fi
i=$((i+1))
done < "$filename"


#echo "TITLE: $title"
#echo "Message: $message"

#Tricks to allow multiline messages with sed...
echo -e "$(echo -e "$template" | sed "s@{{title}}@$title@" | sed "s@{{body}}@$message@")" > "$output/$destFilename"

#echo "_____________________"
done
4 changes: 2 additions & 2 deletions template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html>
<head>
<meta charset="utf-8">
<title>{{title}}</title>
<title></title>
</head>
<body>
{{body}}

</body>
</html>
2 changes: 1 addition & 1 deletion tests/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def write_to(self, dirpath):
with open(filepath, 'w') as f:
f.write(self.title)
f.write("\n\n")
f.write(self.body)
f.write(self.body+"\n")

@pytest.fixture
def input_dir():
Expand Down