DEV Community

Pavol Z. Kutaj
Pavol Z. Kutaj

Posted on

How I'm Automating `resume.pdf` creation with Git Hooks and Pandoc

USECASE

The aim of this pageđź“ť is to explain how I automatically convert a Markdown file with my resume into a PDF using with a Git hook. My resume is available at https://pavol.kutaj.com. It is running on Github Pages (i.e. on Jekyll). I am trying to have a short NOW section on the top of the CV that I'm updating at least every querted. With this tiny automatin, each time I edit an index.markdown file, an accompanying .pdf is generated locally with pandoc and the pushed together with the commit of index.markdown. The pdf for download is available at https://pavol.kutaj.com/assets/Pavol-Kutaj-Resume.pdf.

  • Install Pandoc: Use Homebrew to install Pandoc:
  brew install pandoc
Enter fullscreen mode Exit fullscreen mode
  • Install MacTeX: Use Homebrew to install MacTeX for PDF generation:
  brew install --cask basictex
Enter fullscreen mode Exit fullscreen mode
  • Convert Markdown to PDF: Use Pandoc with custom geometry settings:
  pandoc -V geometry:"top=2cm, bottom=1.5cm, left=2cm, right=2cm" -f markdown-implicit_figures -o "./assets/Pavol-Kutaj-Resume.pdf" index.markdown
Enter fullscreen mode Exit fullscreen mode
  • Create Git Hook: Navigate to the Git hooks directory:
  cd .git/hooks
Enter fullscreen mode Exit fullscreen mode
  • Create Pre-commit Hook: Create a pre-commit file and open it:
  touch pre-commit
  nano pre-commit
Enter fullscreen mode Exit fullscreen mode
  • Add Script to Pre-commit Hook: Add the following script:
  #!/bin/sh

  # Check if index.markdown is being committed
  if git diff --cached --name-only | grep -q 'index.markdown'; then
    # Run Pandoc command to convert Markdown to PDF
    pandoc -V geometry:"top=2cm, bottom=1.5cm, left=2cm, right=2cm" -f markdown-implicit_figures -o "./assets/Placeholder-Resume.pdf" index.markdown

    # Add the generated PDF to the commit
    git add "./assets/Placeholder-Resume.pdf"
  fi
Enter fullscreen mode Exit fullscreen mode
  • Make Pre-commit Hook Executable: Set executable permissions for the hook:
  chmod +x pre-commit
Enter fullscreen mode Exit fullscreen mode
  • Testing the Setup: Ensure index.markdown and the ./assets/ directory exist. Run the commit process to verify the hook works.

LINKS

Top comments (0)