Skip to content

Instantly share code, notes, and snippets.

@brunoamaral
Last active September 22, 2022 17:55
Show Gist options
  • Save brunoamaral/5030f34404bf27dbf9bb5398d81b3d2a to your computer and use it in GitHub Desktop.
Save brunoamaral/5030f34404bf27dbf9bb5398d81b3d2a to your computer and use it in GitHub Desktop.
This bash script takes the export of a Notion page and converts to a PDF with a cover page and table of contents
#!/bin/zsh
####
# This script assumes that you have installed https://github.com/Wandmalfarbe/pandoc-latex-template and that your input is a markdown file from https://www.notion.so/
# Converting to PDF requires MacTex or equivalent to be installed.
# Cover page background is hardcoded to "~/.pandoc/backgrounds/background7.pdf", change it.
# Author is hardcoded to "Lisbon Collective", https://lisboncollective.com/
# Usage: ./notion2pdf.sh inputFile.md
# Questions: mail@brunoamaral.eu
###
input=$1
output=${input%".md"}.pdf
h1="# "
title=$(grep '^# .*$' "$input")
title=${title#"$h1"}
echo "Add a subtitle?"
read subtitle
lines=$(grep --line-number '^## .*$' "$1" | cut -d ':' -f1 | head -n1) && lines=$(expr $lines - 1) && tail -n +${lines} "$1" >> tempfile.md
pandoc tempfile.md -o "$output" --from markdown --template eisvogel --listings \
--metadata author="Lisbon Collective" \
--metadata title="${title}" \
--metadata date=$(date "+%F") \
--metadata subtitle="${subtitle}" \
--variable titlepage='true' \
--variable titlepage-rule-color="360049" \
--variable toc='true' --variable toc-own-page='true' \
--variable titlepage-background="~/.pandoc/backgrounds/background7.pdf"
rm tempfile.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment