Created
June 6, 2016 14:35
-
-
Save anotheremily/003cb3dcd52a4eb46eaad1f0943b8628 to your computer and use it in GitHub Desktop.
Simple Templater in Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TEMPLATE_DIR='src/templates/' | |
PAGE_DIR='src/pages/' | |
DEST_DIR='src/' | |
for page in `ls ${PAGE_DIR}` | |
do | |
echo ${page} | |
contents=`cat ${PAGE_DIR}${page}` | |
for template in `grep {{.*}} ${PAGE_DIR}${page}` | |
do | |
template_file=`echo ${template} | sed s/{{//g | sed s/}}/.frag/g` | |
template_contents=`cat ${TEMPLATE_DIR}${template_file} | tr '\n' '\r'` | |
temp=`echo "${contents}" | sed -e s/${template}/"%s"/g` | |
contents=`printf "${temp}" "${template_contents}"` | |
done | |
echo "${contents}" > ${DEST_DIR}${page} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment