ecallen

How this site is generated using Pandoc

Not going to lie. Most of this was adapted from https://www.romangeber.com/static_websites_with_pandoc/.

My needs are simpler so the process is stripped down a little. Here is my script to generate the blog.


#! /bin/bash

# clear out the html dir before regeneration
rm html/*

# Copy a fresh index file into place
cp index.md.tmpl index.md

# Regenerate the sections for notes
cd sections/

# Remove the old files
rm section*

# Take the Notes dump file and split it up by header
csplit ../notes.md --prefix='section.' --suffix-format='%04d.md' --elide-empty-files '/^# /' {*}
cd ../

# Run pandoc in sections/ to convert to html
for f in $(find ./sections -name '*.md' | grep -v templates | grep -v drafts)
do
    fn=$(echo "$f" | cut -c3-)
    bn=$(basename -s .md $fn)
    echo "filename: $fn output: html/${bn}.html" 
    pandoc ${fn}  -o html/${bn}.html --standalone --template=./default.html5 --css "https://latex.now.sh/style.css" --include-after-body="license.html" --metadata title="ecallen" --variable=lastUpdated:$( stat -c %y ${fn} | cut -f 1 -d ' ' ) --variable=creationDate:$( stat -c %w ${fn} | cut -f 1 -d ' ' ) 
done

# For each section.*.html create a link in the index.md
for section in $(grep 'h1 id=' html/section.000*.html | grep -v ecallen | htmlq --text | sed -r 's/.{4}//')
do 
    echo ${section} | awk -F: '{print "- ["$2"]("$1")"}' >> index.md
done

# Add all the Zettelkasten to the index so it can be searched
echo "" >> index.md
cat notes.md >> index.md

# Generate the index.html from index.md and any blog entries
for f in $(find . -name '*.md' | grep -v templates | grep -v drafts | grep -v sections)
do
    fn=$(echo "$f" | cut -c3-)
    bn=$(basename -s .md $fn)
    echo "filename: $fn output: html/${bn}.html" 
    pandoc ${fn}  -o html/${bn}.html --standalone --template=./default.html5 --css "https://latex.now.sh/style.css" --include-after-body="license.html" --metadata title="ecallen" --variable=lastUpdated:$( stat -c %y ${fn} | cut -f 1 -d ' ' ) --variable=creationDate:$( stat -c %w ${fn} | cut -f 1 -d ' ' ) 
done

The workflow is like this, create a markdown file/blog entry in the drafts directory. Once the file is ready then copy it up to the parent dir and add a entry in the index.md file. Note that the css is from latex.now.sh. The templates were cloned from the pandoc templates repo.

In order to look a the blog locally I use a quick Flask script to serve the page and check it out real quick.


from flask import Flask, request, send_from_directory

# set the project root directory as the static folder, you can set others.
app = Flask(__name__, static_url_path='/html')

@app.route('/<path:path>')
def send_html(path):
    return send_from_directory('html', path)

if __name__ == "__main__":
    app.run()

That’s it. Sweet, simple and beautiful.




Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.