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

set -ex
#set -ex

# YOUR CODE HERE
if [ $# -lt 2 ]
then
echo "Invalid args. Two expected."
exit 1
fi

input=$1
output=$2

if [ ! -d "$input" ]
then
echo "Input directory does not exist."
exit 1
fi


if [ ! -d "$output" ]
then
mkdir -p "$output"
fi

files=$( ls "$input" )
for f in $files
do
fbasename=$( basename "$f" | cut -d. -f1)
ftype='.html'
name=$fbasename$ftype
title=$( head --lines=1 "$input/$f" )
body=$( tail --lines=1 "$input/$f")
sed "s/{{title}}/$title/g" template.html > temp.html
sed "s/{{body}}/$body/g" temp.html > "$output/$name"
done

10 changes: 10 additions & 0 deletions outputdir/postone.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Post One Title</title>
</head>
<body>
This is the body of Post One.
</body>
</html>
10 changes: 10 additions & 0 deletions outputdir/some-other-post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Some Other Post Title</title>
</head>
<body>
This is the body of the other post.
</body>
</html>
10 changes: 10 additions & 0 deletions temp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Some Other Post Title</title>
</head>
<body>
{{body}}
</body>
</html>
10 changes: 10 additions & 0 deletions test/test/postone.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Post One Title</title>
</head>
<body>
This is the body of Post One.
</body>
</html>
10 changes: 10 additions & 0 deletions test/test/some-other-post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Some Other Post Title</title>
</head>
<body>
This is the body of the other post.
</body>
</html>
Binary file added tests/helpers.pyc
Binary file not shown.
Binary file added tests/test_hyperlink.pyc
Binary file not shown.
Binary file added tests/test_paragraphs.pyc
Binary file not shown.
Binary file added tests/test_random.pyc
Binary file not shown.
Binary file added tests/test_simple.pyc
Binary file not shown.