Skip to content

Commit fb8f83a

Browse files
Add ePUB format (mainmatter#130)
1 parent f9a1d42 commit fb8f83a

File tree

3 files changed

+54
-15
lines changed

3 files changed

+54
-15
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ jobs:
2020
run: cargo install --path helpers/mdbook-exercise-linker
2121
- name: Install link shortener plugin
2222
run: cargo install --path helpers/mdbook-link-shortener
23-
- name: Install mdbook-pandoc and related dependencies
23+
- name: Install mdbook-pandoc, calibre and related dependencies
2424
run: |
2525
cargo install mdbook-pandoc --locked --version 0.7.1
2626
sudo apt-get update
27-
sudo apt-get install -y fonts-noto
27+
sudo apt-get install -y fonts-noto calibre
2828
2929
export PANDOC_VERSION=3.3
3030
curl -LsSf https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/pandoc-${PANDOC_VERSION}-linux-amd64.tar.gz | tar zxf -
@@ -70,6 +70,13 @@ jobs:
7070
run: |
7171
cd book
7272
mdbook build
73+
- name: Convert HTML to ePUB
74+
run: |
75+
cd book/book/pandoc/html
76+
sed -i 's|<code>\\newpage</code>{=latex}||g' 100-exercises-to-learn-rust.html
77+
ebook-convert 100-exercises-to-learn-rust.html 100-exercises-to-learn-rust.epub \
78+
--embed-all-fonts \
79+
--subset-embedded-fonts
7380
- name: Link Checker
7481
uses: lycheeverse/lychee-action@v1
7582
with:
@@ -94,6 +101,10 @@ jobs:
94101
with:
95102
name: paperback
96103
path: book/book/pandoc/paperback/100-exercises-to-learn-rust.pdf
104+
- uses: actions/upload-artifact@v4
105+
with:
106+
name: ePUB
107+
path: book/book/pandoc/html/100-exercises-to-learn-rust.epub
97108

98109
is_fresh:
99110
runs-on: ubuntu-latest

book/book.toml

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ multilingual = false
55
src = "src"
66
title = "100 Exercises To Learn Rust"
77

8+
[preprocessor.exercise-linker]
9+
exercise_root_url = "https://github.com/mainmatter/100-exercises-to-learn-rust/tree/main/exercises"
10+
11+
[preprocessor.link-shortener]
12+
base_url = "https://ruex.io"
13+
renderers = ["pandoc"]
14+
mapping = "link2alias.json"
15+
verify = false
16+
after = ["exercise-linker"]
17+
18+
[output.html]
19+
git-repository-url = "https://github.com/mainmatter/100-exercises-to-learn-rust"
20+
821
[output.pandoc]
922
optional = true
1023
hosted-html = "https://rust-exercises.com/100-exercises/"
@@ -16,9 +29,9 @@ highlight-style = "tango"
1629
# We use `lualatext` because, right now, it's the only engine
1730
# that supports fallback fonts, which we need for emojis.
1831
pdf-engine = "lualatex"
32+
metadata-file = "metadata.yml"
1933

2034
[output.pandoc.profile.pdf.variables]
21-
subtitle = "A hands-on course by Mainmatter"
2235
# You can get these fonts here: https://fonts.google.com/selection?query=noto+color+
2336
mainfont = "Noto Serif"
2437
sansfont = "Noto Sans"
@@ -43,12 +56,12 @@ header-includes = [
4356
output-file = "100-exercises-to-learn-rust.pdf"
4457
to = "latex"
4558
highlight-style = "monochrome"
59+
metadata-file = "metadata.yml"
4660
# We use `lualatext` because, right now, it's the only engine
4761
# that supports fallback fonts, which we need for emojis.
4862
pdf-engine = "lualatex"
4963

5064
[output.pandoc.profile.paperback.variables]
51-
subtitle = "A hands-on course by Mainmatter"
5265
# You can get these fonts here: https://fonts.google.com/selection?query=noto+color+
5366
mainfont = "Noto Serif"
5467
sansfont = "Noto Sans"
@@ -68,15 +81,26 @@ header-includes = [
6881
]
6982
links-as-notes = true
7083

71-
[output.html]
72-
git-repository-url = "https://github.com/mainmatter/100-exercises-to-learn-rust"
73-
74-
[preprocessor.exercise-linker]
75-
exercise_root_url = "https://github.com/mainmatter/100-exercises-to-learn-rust/tree/main/exercises"
84+
# We go through HTML, rather than directly to ePUB, since routing
85+
# Pandoc's HTML through Calibre's ePUB converter gives us better results.
86+
[output.pandoc.profile.html]
87+
output-file = "100-exercises-to-learn-rust.html"
88+
to = "html"
89+
highlight-style = "monochrome"
90+
embed-resources = true
91+
standalone = true
92+
metadata-file = "metadata.yml"
7693

77-
[preprocessor.link-shortener]
78-
base_url = "https://ruex.io"
79-
renderers = ["pandoc"]
80-
mapping = "link2alias.json"
81-
verify = false
82-
after = ["exercise-linker"]
94+
[output.pandoc.profile.html.variables]
95+
# You can get these fonts here: https://fonts.google.com/selection?query=noto+color+
96+
mainfont = "Noto Serif"
97+
sansfont = "Noto Sans"
98+
monofont = "Noto Sans Mono"
99+
mainfontfallback = ["Noto Color Emoji:mode=harf"]
100+
sansfontfallback = ["Noto Color Emoji:mode=harf"]
101+
monofontfallback = [
102+
"Noto Color Emoji:mode=harf",
103+
]
104+
linkcolor = "blue"
105+
urlcolor = "blue"
106+
urlstyle = "rm"

book/metadata.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
title: "100 Exercises To Learn Rust"
2+
subtitle: "A hands-on course by Mainmatter"
3+
author: "Luca Palmieri"
4+
keywords: ["Rust", "Programming"]

0 commit comments

Comments
 (0)