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
Binary file added .DS_Store
Binary file not shown.
Empty file added .html
Empty file.
30 changes: 29 additions & 1 deletion generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,32 @@

set -ex

# YOUR CODE HERE
# Declaring arguments. The script takes two arguments:
# The input directory
# The output directory
inputDir="$1"
outputDir="$2"


template="$(<template.html)"
#Creating output directory if it does not exist.
if [ ! -d "$outputDir" ]; then
mkdir -p "$outputDir"
fi



#For each file in input directory..
for file in "$inputDir"/*
do

#Extracting file name from input file
filename=$(basename "$file" ".txt")

#Saving template to output directory
echo "$template" > "$outputDir/""$filename.html"

#Replacing title and body
sed -i -e "s/{{title}}/$( head -n 1 "$file")/g" "$outputDir/$filename.html"
sed -i -e "s/{{body}}/$( tail -n +3 "$file")/g" "$outputDir/$filename.html" #line 2 is empty
done
Empty file added outputDirpostone.html
Empty file.
Empty file added outputDirsome-other-post.html
Empty file.
Empty file added postone.html
Empty file.
Empty file added some-other-post.html
Empty file.
Binary file added tests/.DS_Store
Binary file not shown.