Skip to content

Commit

Permalink
feat(pdf): render book to pdf
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Mar 17, 2024
1 parent cf2ccae commit e36d625
Show file tree
Hide file tree
Showing 6 changed files with 444 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MDBOOK_VERSION=0.4.37
MDBOOK_PANDOC_VERSION=0.6.0
MDBOOK_LAST_CHANGED_VERSION=0.1.4
PANDOC_VERSION=3.1.12.2
41 changes: 41 additions & 0 deletions .github/workflows/install-mdbook/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Install mdbook and dependencies

description: Install the mdbook with the dependencies we need.

runs:
using: composite
steps:
- name: Read mdbook version from .env
id: mdbook-version
run: |
. ./.env
echo "version=$MDBOOK_VERSION" >> $GITHUB_OUTPUT
shell: bash

- name: Read mdbook-pandoc version from .env
id: mdbook-pandoc-version
run: |
. ./.env
echo "version=$MDBOOK_PANDOC_VERSION" >> $GITHUB_OUTPUT
shell: bash

- name: Read mdbook-last-changed version from .env
id: mdbook-last-changed-version
run: |
. ./.env
echo "version=$MDBOOK_LAST_CHANGED_VERSION" >> $GITHUB_OUTPUT
shell: bash

- name: Install dependencies
uses: taiki-e/install-action@v2
with:
tool: mdbook@${{ steps.mdbook-version.outputs.version }},mdbook-pandoc@${{ steps.mdbook-pandoc-version.outputs.version }},mdbook-last-changed@${{ steps.mdbook-last-changed-version.outputs.version }}

- name: Install mdbook-pandoc and related dependencies
run: |
. ./.env
sudo apt-get update
sudo apt-get install -y texlive texlive-latex-extra texlive-luatex texlive-lang-cjk librsvg2-bin fonts-noto
curl -LsSf https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/pandoc-$PANDOC_VERSION-linux-amd64.tar.gz | tar zxf -
echo "$PWD/pandoc-$PANDOC_VERSION/bin" >> $GITHUB_PATH
shell: bash
18 changes: 11 additions & 7 deletions .github/workflows/mdbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ jobs:
# Build job
build:
runs-on: ubuntu-latest
env:
MDBOOK_VERSION: 0.4.21
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: taiki-e/install-action@3ed9916b5427bc0679b294607ea47d1d8007b53f
with:
tool: mdbook,mdbook-last-changed

- name: Install mdbook
uses: ./.github/workflows/install-mdbook

- name: Setup Pages
id: pages
uses: actions/configure-pages@1f0c5cde4bc74cd7e1254d0cb4de8d49e9068c7d # v4
- name: Build with mdBook
run: mdbook build

- name: Build course
run: |
mdbook build -d book
mv book/html/* book/pandoc/pdf/*.pdf book/
rm -r book/html book/pandoc
- name: Upload artifact
uses: actions/upload-pages-artifact@0252fc4ba7626f0298f0cf00902a25c6afc77fa8 # v3
with:
Expand Down
23 changes: 22 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,32 @@ An open source developers documentation book for
[rustic](https://github.com/rustic-rs/rustic) that you can read
[here](https://rustic.cli.rs/dev-docs).

## Building with mdbook
## Installation

This book is built with [mdbook](https://rust-lang.github.io/mdBook/). You can
install it by running `cargo install mdbook`.

### Additional dependencies

- `cargo install mdbook-last-changed` for date changes in the footer

- `cargo install mdbook-pandoc` for rendering the book to PDF

#### Texlive

```sh
# Source the .env file to get the PANDOC_VERSION
. ./.env

sudo apt-get update

sudo apt-get install -y texlive texlive-latex-extra texlive-luatex texlive-lang-cjk librsvg2-bin fonts-noto

curl -LsSf https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/pandoc-$PANDOC_VERSION-linux-amd64.tar.gz | tar zxf -
```

## Building with mdbook

If you want to build it locally you can run one of these two commands in the
root directory of the repository:

Expand Down
17 changes: 17 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,20 @@ additional-css = ["./styles/last-changed.css"]
[output.html.fold]
enable = true
level = 0

[output.pandoc]
optional = true
hosted-html = "https://rustic.cli.rs/dev-docs/"

[output.pandoc.profile.pdf]
output-file = "rustic-dev-docs.pdf"
pdf-engine = "lualatex"

[output.pandoc.profile.pdf.variables]
mainfont = "Noto Serif"
sansfont = "Noto Sans"
monofont = "Noto Sans Mono"
mainfontfallback = ["NotoSerifCJKSC:"]
geometry = ["margin=1.25in"]
linkcolor = "blue"
urlcolor = "red"
Loading

0 comments on commit e36d625

Please sign in to comment.