Skip to content

Instantly share code, notes, and snippets.

@ssbozy
Created April 27, 2022 04:13
Show Gist options
  • Save ssbozy/98c8f2f9e0f7728de736f119d6d65f09 to your computer and use it in GitHub Desktop.
Save ssbozy/98c8f2f9e0f7728de736f119d6d65f09 to your computer and use it in GitHub Desktop.
building a blog using pandoc and markdown files
#!/bin/sh
ROOT_FOLDER=`pwd`
POSTS_FOLDER="posts"
DIST_FOLDER="dist"
function create_destination() {
mkdir -p dist dist/assets dist/posts dist/pages
}
function sync_assets() {
rsync -avz --progress assets dist/
mv dist/assets/index.html dist/index.html
}
function clean_dist() {
rm -rf dist
}
function create_posts() {
echo "GENERATING POSTS \n"
cd posts
for i in `ls *.md`
do
echo "Translating $i to html5"
pandoc -s -f markdown -t html --template ../assets/templates/posts.html -H ../assets/css/pandoc.css -o "../dist/posts/$(basename $i .md).html" $i
done
cd ..
}
function create_pages() {
echo "GENERATING PAGES \n"
cd pages
for i in `ls *.md`
do
echo "Translating $i to html5"
pandoc -s -f markdown -t html --template ../assets/templates/pages.html -H ../assets/css/pandoc.css -o "../dist/pages/$(basename $i .md).html" $i
done
cd ..
}
# Old file name cleanup code. This is replaced by the basename command which creates a new file with updated filename
# for i in `ls *.md.html`
# do
# echo "fixing file name $i to html extension"
# mv "$i" "${i//md.html/html}"
# done
clean_dist
create_destination
sync_assets
create_posts
create_pages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment