diff --git a/generate.sh b/generate.sh index 51652b1..ef60db4 100755 --- a/generate.sh +++ b/generate.sh @@ -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 + diff --git a/outputdir/postone.html b/outputdir/postone.html new file mode 100644 index 0000000..4fbb953 --- /dev/null +++ b/outputdir/postone.html @@ -0,0 +1,10 @@ + + + + + Post One Title + + + This is the body of Post One. + + diff --git a/outputdir/some-other-post.html b/outputdir/some-other-post.html new file mode 100644 index 0000000..414f126 --- /dev/null +++ b/outputdir/some-other-post.html @@ -0,0 +1,10 @@ + + + + + Some Other Post Title + + + This is the body of the other post. + + diff --git a/temp.html b/temp.html new file mode 100644 index 0000000..b3fa268 --- /dev/null +++ b/temp.html @@ -0,0 +1,10 @@ + + + + + Some Other Post Title + + + {{body}} + + diff --git a/test/test/postone.html b/test/test/postone.html new file mode 100644 index 0000000..4fbb953 --- /dev/null +++ b/test/test/postone.html @@ -0,0 +1,10 @@ + + + + + Post One Title + + + This is the body of Post One. + + diff --git a/test/test/some-other-post.html b/test/test/some-other-post.html new file mode 100644 index 0000000..414f126 --- /dev/null +++ b/test/test/some-other-post.html @@ -0,0 +1,10 @@ + + + + + Some Other Post Title + + + This is the body of the other post. + + diff --git a/tests/helpers.pyc b/tests/helpers.pyc new file mode 100644 index 0000000..109d868 Binary files /dev/null and b/tests/helpers.pyc differ diff --git a/tests/test_hyperlink.pyc b/tests/test_hyperlink.pyc new file mode 100644 index 0000000..d5e930d Binary files /dev/null and b/tests/test_hyperlink.pyc differ diff --git a/tests/test_paragraphs.pyc b/tests/test_paragraphs.pyc new file mode 100644 index 0000000..19de0ba Binary files /dev/null and b/tests/test_paragraphs.pyc differ diff --git a/tests/test_random.pyc b/tests/test_random.pyc new file mode 100644 index 0000000..fc5fdc3 Binary files /dev/null and b/tests/test_random.pyc differ diff --git a/tests/test_simple.pyc b/tests/test_simple.pyc new file mode 100644 index 0000000..7899618 Binary files /dev/null and b/tests/test_simple.pyc differ