Skip to content

Commit e36d625

Browse files
committed
feat(pdf): render book to pdf
Signed-off-by: simonsan <[email protected]>
1 parent cf2ccae commit e36d625

File tree

6 files changed

+444
-8
lines changed

6 files changed

+444
-8
lines changed

.env

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MDBOOK_VERSION=0.4.37
2+
MDBOOK_PANDOC_VERSION=0.6.0
3+
MDBOOK_LAST_CHANGED_VERSION=0.1.4
4+
PANDOC_VERSION=3.1.12.2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Install mdbook and dependencies
2+
3+
description: Install the mdbook with the dependencies we need.
4+
5+
runs:
6+
using: composite
7+
steps:
8+
- name: Read mdbook version from .env
9+
id: mdbook-version
10+
run: |
11+
. ./.env
12+
echo "version=$MDBOOK_VERSION" >> $GITHUB_OUTPUT
13+
shell: bash
14+
15+
- name: Read mdbook-pandoc version from .env
16+
id: mdbook-pandoc-version
17+
run: |
18+
. ./.env
19+
echo "version=$MDBOOK_PANDOC_VERSION" >> $GITHUB_OUTPUT
20+
shell: bash
21+
22+
- name: Read mdbook-last-changed version from .env
23+
id: mdbook-last-changed-version
24+
run: |
25+
. ./.env
26+
echo "version=$MDBOOK_LAST_CHANGED_VERSION" >> $GITHUB_OUTPUT
27+
shell: bash
28+
29+
- name: Install dependencies
30+
uses: taiki-e/install-action@v2
31+
with:
32+
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 }}
33+
34+
- name: Install mdbook-pandoc and related dependencies
35+
run: |
36+
. ./.env
37+
sudo apt-get update
38+
sudo apt-get install -y texlive texlive-latex-extra texlive-luatex texlive-lang-cjk librsvg2-bin fonts-noto
39+
curl -LsSf https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/pandoc-$PANDOC_VERSION-linux-amd64.tar.gz | tar zxf -
40+
echo "$PWD/pandoc-$PANDOC_VERSION/bin" >> $GITHUB_PATH
41+
shell: bash

.github/workflows/mdbook.yml

+11-7
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@ jobs:
2424
# Build job
2525
build:
2626
runs-on: ubuntu-latest
27-
env:
28-
MDBOOK_VERSION: 0.4.21
2927
steps:
3028
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
31-
- uses: taiki-e/install-action@3ed9916b5427bc0679b294607ea47d1d8007b53f
32-
with:
33-
tool: mdbook,mdbook-last-changed
29+
30+
- name: Install mdbook
31+
uses: ./.github/workflows/install-mdbook
32+
3433
- name: Setup Pages
3534
id: pages
3635
uses: actions/configure-pages@1f0c5cde4bc74cd7e1254d0cb4de8d49e9068c7d # v4
37-
- name: Build with mdBook
38-
run: mdbook build
36+
37+
- name: Build course
38+
run: |
39+
mdbook build -d book
40+
mv book/html/* book/pandoc/pdf/*.pdf book/
41+
rm -r book/html book/pandoc
42+
3943
- name: Upload artifact
4044
uses: actions/upload-pages-artifact@0252fc4ba7626f0298f0cf00902a25c6afc77fa8 # v3
4145
with:

Readme.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,32 @@ An open source developers documentation book for
1515
[rustic](https://github.com/rustic-rs/rustic) that you can read
1616
[here](https://rustic.cli.rs/dev-docs).
1717

18-
## Building with mdbook
18+
## Installation
1919

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

23+
### Additional dependencies
24+
25+
- `cargo install mdbook-last-changed` for date changes in the footer
26+
27+
- `cargo install mdbook-pandoc` for rendering the book to PDF
28+
29+
#### Texlive
30+
31+
```sh
32+
# Source the .env file to get the PANDOC_VERSION
33+
. ./.env
34+
35+
sudo apt-get update
36+
37+
sudo apt-get install -y texlive texlive-latex-extra texlive-luatex texlive-lang-cjk librsvg2-bin fonts-noto
38+
39+
curl -LsSf https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/pandoc-$PANDOC_VERSION-linux-amd64.tar.gz | tar zxf -
40+
```
41+
42+
## Building with mdbook
43+
2344
If you want to build it locally you can run one of these two commands in the
2445
root directory of the repository:
2546

book.toml

+17
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,20 @@ additional-css = ["./styles/last-changed.css"]
2323
[output.html.fold]
2424
enable = true
2525
level = 0
26+
27+
[output.pandoc]
28+
optional = true
29+
hosted-html = "https://rustic.cli.rs/dev-docs/"
30+
31+
[output.pandoc.profile.pdf]
32+
output-file = "rustic-dev-docs.pdf"
33+
pdf-engine = "lualatex"
34+
35+
[output.pandoc.profile.pdf.variables]
36+
mainfont = "Noto Serif"
37+
sansfont = "Noto Sans"
38+
monofont = "Noto Sans Mono"
39+
mainfontfallback = ["NotoSerifCJKSC:"]
40+
geometry = ["margin=1.25in"]
41+
linkcolor = "blue"
42+
urlcolor = "red"

0 commit comments

Comments
 (0)