Skip to content

maelle/testbook

Repository files navigation

testbook

Netlify Status Project Status: Concept – Minimal or no implementation has been done yet, or the repository is only intended to be a limited example, demo, or proof-of-concept.

The goal of testbook is to try and generate a beautiful book as html and PDF using Hugo and paged.js. It's a proof-of-concept.

The .md files could be created from .Rmd, therefore making this an alternative to the excellent bookdown. Compared to creating a gitbook with bookdown, one could customize the html website more easily, and use any Hugo feature.

This proof-of-concept is based on the great hugo-book theme. This repo just adds a bit of setup magic (Netlify config, config/ dir) to work with existing great tools.

The idea is to run two Hugo builds with different configurations

  • One of them, hugo -d public --environment 'website', creates the html website with a link to "book.pdf" somewhere, in the public/ folder.
  • The second one, hugo -d public2 --environment 'pdf', creates a website with a special page containing all the book content, and potentially a print CSS stylesheet.
  • Then that page is printed to PDF using pagedjs-cli and copied as "book.pdf" to public/. pagedjs-cli public2/all/index.html -o public/book.pdf"
  • The live website uses public so it has the website and the PDF.

Netlify can run all these commands

[build]
publish = "/public"
command = "hugo -d public --environment 'website' && hugo -d public2 --environment 'pdf' && pagedjs-cli public2/all/index.html -o public/book.pdf"

The dependency on pagedjs-cli is indicated with packages.json.

Further work

If I decide to take this further, that is!

  • Actually work on the CSS print sheet.
  • Make Katex, Mermaid etc. work for the PDF version.
  • Make hugo-book features for ordering/including content work.
  • Try and embed a tweet.
  • Try the idea with another book theme?
  • Write some content from Rmd.

Related work

To get a paged.js button in your Hugo website (i.e. not pre-generating the PDF, letting the reader do that from their browser) check out the Hugo paged-js theme that you could use as a theme component.

About

⚠️ CONCEPT! ⚠️ beautiful book as html and PDF using Hugo and paged.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published