Creating a website with pandoc and make
2026-06-22
Getting started
Create your GitHub Pages website
Add an empty
.nojekyllfile to bypass Jekyll processingCreate
index.mdwith Markdown contentConvert to HTML:
pandoc index.md -o index.html --standalonePrint the default HTML template with
pandoc --print-default-template html. Notice the use of variables like title, author, date, etc.Add a metadata block at the top of
index.md. For example:--- title: "Creating a website with pandoc" date: 2026-06-22 ---
Add custom template and CSS
Output the default HTML template to a file:
pandoc -o template.html --print-default-template htmlEdit
template.htmland remove the<style>blockCreate
style.csswith your custom stylesheetGenerate the HTML using the custom template and CSS stylesheet:
pandoc index.md -o index.html --standalone --template template.html --css style.css
Add header and footer
The
--include-before-bodyand--include-after-bodyoptions can be used to add a site header and footerCreate
footer.htmlwith HTML content. For example:<footer style="margin-top: 4em; text-align: center;"> <hr> <p>Generated with pandoc</p> </footer>After generating the HTML with
--include-after-body footer.html, notice the contents are included before the</body>closing tagIf using
--include-before-bodyto add a site header, you may need to amend the template file since the default already contains a<header>elementEdit
template.htmlto add the<main>element. For example:<body> $for(include-before)$ $include-before$ $endfor$ <main> <!-- snip --> $body$ </main> $for(include-after)$ $include-after$ $endfor$ </body>
Configure publishing source
The problem is that currently everything in the repository will be
published, including files like template.html which
shouldn’t be public.
Configure a publishing source for your GitHub Pages site:
Change the source folder to
/docsin your GitHub repository Pages settingsMove
.nojekylland all public website files to a new/docsdirectory:mkdir docs mv .nojekyll index.html style.css docs/
Add directory structure
Organise other files into separate directories:
.
├── content
│ └── index.md
├── docs
│ ├── index.html
│ └── style.css
├── includes
│ └── footer.html
└── templates
└── template.html
Add Makefile
The pandoc command is becoming a bit unwieldly.
Create a Makefile to help automate building the
website:
CONTENT_DIR = ./content
OUTPUT_DIR = ./docs
CONTENT = $(shell find $(CONTENT_DIR) -name '*.md')
HTML = $(patsubst $(CONTENT_DIR)/%.md, $(OUTPUT_DIR)/%.html, $(CONTENT))
PANDOC_OPTS = --standalone \
--template templates/template.html \
--include-after-body includes/footer.html \
--css style.css
.PHONY: build
build: $(HTML)
$(OUTPUT_DIR)/%.html: $(CONTENT_DIR)/%.md
@mkdir -p $(@D)
pandoc $(PANDOC_OPTS) $< -o $@