Skip to content

Instantly share code, notes, and snippets.

@anotheremily
Created June 6, 2016 14:35
Show Gist options
  • Save anotheremily/003cb3dcd52a4eb46eaad1f0943b8628 to your computer and use it in GitHub Desktop.
Save anotheremily/003cb3dcd52a4eb46eaad1f0943b8628 to your computer and use it in GitHub Desktop.
Simple Templater in Bash
#!/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