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
34 changes: 32 additions & 2 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
#!/bin/bash

set -ex
#set -ex

# YOUR CODE HERE
# Create Target directories recursively

mkdir -p "$2"

# Loop through all files in Input directory

for file in "$1"/*
do
fname=$(basename "$file")
printf "\nProcessing %s...\n" "$fname"
str=$(echo "$fname" | rev | cut -d"." -f2- | rev)
cp template.html "$2/$str.html"

# Parse all files line by line and save to an array

i=0

while IFS=$'\n' read -r line || [[ -n "$line" ]];
do
if [ "$line" != "" ]; then

if [ "$i" == 0 ]; then
sed -i "s/{{title}}/$line/g" "$2/$str.html"
else
sed -i "s/{{body}}/$line/g" "$2/$str.html"
fi

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