|
| 1 | +# Local Leanpub |
| 2 | + |
| 3 | +We don't need to use Leanpub to render our Leanpub book previews. We can do |
| 4 | +that locally using [Pandoc](http://johnmacfarlane.net/pandoc/) and save about |
| 5 | +ninety seconds each time. |
| 6 | + |
| 7 | +This repo is an extraction of some work I did to stitch together a local |
| 8 | +preview of my book on [Writing With Vim](https://leanpub.com/vim-for-writers). |
| 9 | +Here is a way to get your own book previews without the need to send your work |
| 10 | +up to Leanpub every time. |
| 11 | + |
| 12 | +The setup in this repo takes care of some of the work of moving files and |
| 13 | +normalizing differences between Leanpub and Pandoc so that you can easily and |
| 14 | +quickly preview the book contents. |
| 15 | + |
| 16 | +## Local previewing |
| 17 | + |
| 18 | +You need to [have Pandoc installed](http://johnmacfarlane.net/pandoc/installing.html). |
| 19 | + |
| 20 | +At the command-line, run `./build` to generate a PDF locally manually. This |
| 21 | +will look at the contents of contents.txt to generate a `Book.txt` file, which |
| 22 | +is what Leanpub looks at to stitch together your book correctly. |
| 23 | + |
| 24 | +To automate this process, install the Ruby gems locally with `bundle install`. |
| 25 | +Then you can run `bundle exec guard` to automatically regenerate the PDF |
| 26 | +whenever the text contents of the book change or you add or remove a chapter |
| 27 | +from the book. (For my project, I also use `./build` script to correctly |
| 28 | +generate the changes for Leanpub, since I do some post processing to insert |
| 29 | +images, etc.) |
| 30 | + |
| 31 | +Open up the `local-preview.pdf` file to see an approximation of what your book |
| 32 | +will look like when rendered by Leanpub. Many PDF readers have an auto-refresh |
| 33 | +setting, so when your book changes you will see the changes update in the book. |
| 34 | + |
| 35 | +## How book contents are laid out |
| 36 | + |
| 37 | +Leanpub looks at certain files to compile the book in question: |
| 38 | + |
| 39 | + * `Book.txt` lists all of the chapters of the final book |
| 40 | + * `Sample.txt` lists the chapters in the sample PDF |
| 41 | + |
| 42 | +We have a file called `contents.txt` that holds the values of things in the book. |
| 43 | + |
| 44 | +My convention is that the book contents are located in `chapter[digit].markdown` |
| 45 | +files. You can always change the scripts if this does not suit you. |
| 46 | + |
| 47 | +## Installing |
| 48 | + |
| 49 | +Clone this repo and put it into your Dropbox folder that Leanpub looks at. |
| 50 | +Then you should be able to run the commands above and see a local preview, and |
| 51 | +publish to Leanpub and have a preview up there. |
| 52 | + |
| 53 | +## Pandoc vs. Leanpub |
| 54 | + |
| 55 | +Leanpub used to use the Pandoc rendering system, but they switched to use their |
| 56 | +own system to have better control over the rendering process. and they support |
| 57 | +many of the same conventions. You should still check your book against |
| 58 | +Leanpub's preview feature before publishing, since there are some differences. |
| 59 | +For example, For example, Leanpub automatically inserts page breaks between chapters |
| 60 | +(depending on your settings) while Pandoc needs the explicit `\\pagebreak` |
| 61 | +command (this repo takes care of this difference.) |
| 62 | + |
| 63 | +## Disclaimer |
| 64 | + |
| 65 | +This project is not affiliated with Leanpub or Pandoc. It just uses Pandoc to |
| 66 | +approximate the preview function of Leanpub. |
| 67 | + |
| 68 | +## License |
| 69 | + |
| 70 | +This code released under the [MIT License](http://en.wikipedia.org/wiki/MIT_License). |
0 commit comments