Translate this page

Convert Markdown Website To Ebook 🔗

This is how I’ve converted this website, which is written in Markdown using the Hugo framework, to an ebook with epub format, that I uploaded to https://leanpub.com/kaueswayoflife.

Customize 🔗

Customized the site to hide:

Customized the logic using a HUGO_BOOK environment variable and a hide_from_book page parameter:

{{- $isBook := getenv "HUGO_BOOK" -}}
{{- if not $isBook -}}
  ...
{{- end -}}
...
{{- if and $isBook .Params.hide_from_book -}}
{{- else -}}
  ...
{{- end -}}

Hiding certain pages with:

hide_from_book: true

Cover 🔗

Designed the cover on https://www.canva.com .

Generate 🔗

Generated with two terminals.

First terminal runs a local Hugo server setting the HUGO_BOOK environment variable:

$ cd hugo
$ HUGO_BOOK=1 hugo server

Second terminal crawls the pages of the local Hugo server and converts them:

$ cd book
$ pandoc -o dist/book.epub \
  --table-of-contents \
  --epub-cover-image cover.png \
  --epub-metadata meta.xml \
  -f html \
  http://localhost:1313/ \
  $(lynx -dump -listonly \
      http://localhost:1313/all/ \
    | grep -oh 'http.*' \
    | grep -v '\(.me/feed.xml\|/all/\)') \
  http://localhost:1313/

Pages:

Using a simple metadata file:

<dc:title>Kaue's Way Of Life</dc:title>
<dc:language>en-US</dc:language>

Test 🔗

Tested on https://play.google.com/books/uploads?type=ebooks .

Share 🔗

Shared on https://leanpub.com/kaueswayoflife .


Download my free ebook


Subscribe to my mailing list and get a free email course

* indicates required

Interests



Translate this page

Updated on 2023 Jun 17.

DISCLAIMER: This is not professional advice. The ideas and opinions presented here are my own, not necessarily those of my employer.