Search code examples
pdfgithubmarkdownhugonetlify

Automatically build PDF from markdown using hugo on github/netlify


I'm using hugo (academic theme) to build a website from sources on github, built and hosted on netlify.

In this site I have one particular page which is rendered from a markdown file (.md) and which I would also like to have available as .pdf. Currently I have to manually generate and push the .pdf every time an edit is made to the .md source, but I'd like this to be automated.

An approach I tried is to embed a JavaScript window.print() button in the page, so that users can print the page to file, but this is somewhat inelegant.

I'm not sure if this can be done via hugo, via a github or netlify hook, or something else.

Any pointers to the right approach are much appreciated.


Solution

  • After a bit more research, it seems that the best way to accomplish this would be using a continuous integration tool such as Travis. There are several possible approaches to this, including:

    1. https://harshjv.com/blog/setup-latex-pdf-build-using-travis-ci/
    2. https://github.com/PHPirates/travis-ci-latex-pdf
    3. https://gist.github.com/willprice/e07efd73fb7f13f917ea
    4. https://vaibhavsagar.com/blog/2015/02/26/automate-resume/
    5. https://github.com/livioso/pandoc-travis-setup

    All the approaches are quite similar and basically do the following:

    1. Create a GitHub authorisation token
    2. Instruct Travis-CI to build the PDF on new commits
    3. Upload the PDF to your chosen branch and location