Add ePUB format (#130)

This commit is contained in:
Luca Palmieri 2024-08-13 15:53:43 +02:00 committed by GitHub
parent f9a1d427b2
commit fb8f83a518
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 15 deletions

View File

@ -20,11 +20,11 @@ jobs:
run: cargo install --path helpers/mdbook-exercise-linker run: cargo install --path helpers/mdbook-exercise-linker
- name: Install link shortener plugin - name: Install link shortener plugin
run: cargo install --path helpers/mdbook-link-shortener run: cargo install --path helpers/mdbook-link-shortener
- name: Install mdbook-pandoc and related dependencies - name: Install mdbook-pandoc, calibre and related dependencies
run: | run: |
cargo install mdbook-pandoc --locked --version 0.7.1 cargo install mdbook-pandoc --locked --version 0.7.1
sudo apt-get update sudo apt-get update
sudo apt-get install -y fonts-noto sudo apt-get install -y fonts-noto calibre
export PANDOC_VERSION=3.3 export PANDOC_VERSION=3.3
curl -LsSf https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/pandoc-${PANDOC_VERSION}-linux-amd64.tar.gz | tar zxf - 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:
run: | run: |
cd book cd book
mdbook build mdbook build
- name: Convert HTML to ePUB
run: |
cd book/book/pandoc/html
sed -i 's|<code>\\newpage</code>{=latex}||g' 100-exercises-to-learn-rust.html
ebook-convert 100-exercises-to-learn-rust.html 100-exercises-to-learn-rust.epub \
--embed-all-fonts \
--subset-embedded-fonts
- name: Link Checker - name: Link Checker
uses: lycheeverse/lychee-action@v1 uses: lycheeverse/lychee-action@v1
with: with:
@ -94,6 +101,10 @@ jobs:
with: with:
name: paperback name: paperback
path: book/book/pandoc/paperback/100-exercises-to-learn-rust.pdf path: book/book/pandoc/paperback/100-exercises-to-learn-rust.pdf
- uses: actions/upload-artifact@v4
with:
name: ePUB
path: book/book/pandoc/html/100-exercises-to-learn-rust.epub
is_fresh: is_fresh:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -5,6 +5,19 @@ multilingual = false
src = "src" src = "src"
title = "100 Exercises To Learn Rust" title = "100 Exercises To Learn Rust"
[preprocessor.exercise-linker]
exercise_root_url = "https://github.com/mainmatter/100-exercises-to-learn-rust/tree/main/exercises"
[preprocessor.link-shortener]
base_url = "https://ruex.io"
renderers = ["pandoc"]
mapping = "link2alias.json"
verify = false
after = ["exercise-linker"]
[output.html]
git-repository-url = "https://github.com/mainmatter/100-exercises-to-learn-rust"
[output.pandoc] [output.pandoc]
optional = true optional = true
hosted-html = "https://rust-exercises.com/100-exercises/" hosted-html = "https://rust-exercises.com/100-exercises/"
@ -16,9 +29,9 @@ highlight-style = "tango"
# We use `lualatext` because, right now, it's the only engine # We use `lualatext` because, right now, it's the only engine
# that supports fallback fonts, which we need for emojis. # that supports fallback fonts, which we need for emojis.
pdf-engine = "lualatex" pdf-engine = "lualatex"
metadata-file = "metadata.yml"
[output.pandoc.profile.pdf.variables] [output.pandoc.profile.pdf.variables]
subtitle = "A hands-on course by Mainmatter"
# You can get these fonts here: https://fonts.google.com/selection?query=noto+color+ # You can get these fonts here: https://fonts.google.com/selection?query=noto+color+
mainfont = "Noto Serif" mainfont = "Noto Serif"
sansfont = "Noto Sans" sansfont = "Noto Sans"
@ -43,12 +56,12 @@ header-includes = [
output-file = "100-exercises-to-learn-rust.pdf" output-file = "100-exercises-to-learn-rust.pdf"
to = "latex" to = "latex"
highlight-style = "monochrome" highlight-style = "monochrome"
metadata-file = "metadata.yml"
# We use `lualatext` because, right now, it's the only engine # We use `lualatext` because, right now, it's the only engine
# that supports fallback fonts, which we need for emojis. # that supports fallback fonts, which we need for emojis.
pdf-engine = "lualatex" pdf-engine = "lualatex"
[output.pandoc.profile.paperback.variables] [output.pandoc.profile.paperback.variables]
subtitle = "A hands-on course by Mainmatter"
# You can get these fonts here: https://fonts.google.com/selection?query=noto+color+ # You can get these fonts here: https://fonts.google.com/selection?query=noto+color+
mainfont = "Noto Serif" mainfont = "Noto Serif"
sansfont = "Noto Sans" sansfont = "Noto Sans"
@ -68,15 +81,26 @@ header-includes = [
] ]
links-as-notes = true links-as-notes = true
[output.html] # We go through HTML, rather than directly to ePUB, since routing
git-repository-url = "https://github.com/mainmatter/100-exercises-to-learn-rust" # Pandoc's HTML through Calibre's ePUB converter gives us better results.
[output.pandoc.profile.html]
output-file = "100-exercises-to-learn-rust.html"
to = "html"
highlight-style = "monochrome"
embed-resources = true
standalone = true
metadata-file = "metadata.yml"
[preprocessor.exercise-linker] [output.pandoc.profile.html.variables]
exercise_root_url = "https://github.com/mainmatter/100-exercises-to-learn-rust/tree/main/exercises" # You can get these fonts here: https://fonts.google.com/selection?query=noto+color+
mainfont = "Noto Serif"
[preprocessor.link-shortener] sansfont = "Noto Sans"
base_url = "https://ruex.io" monofont = "Noto Sans Mono"
renderers = ["pandoc"] mainfontfallback = ["Noto Color Emoji:mode=harf"]
mapping = "link2alias.json" sansfontfallback = ["Noto Color Emoji:mode=harf"]
verify = false monofontfallback = [
after = ["exercise-linker"] "Noto Color Emoji:mode=harf",
]
linkcolor = "blue"
urlcolor = "blue"
urlstyle = "rm"

4
book/metadata.yml Normal file
View File

@ -0,0 +1,4 @@
title: "100 Exercises To Learn Rust"
subtitle: "A hands-on course by Mainmatter"
author: "Luca Palmieri"
keywords: ["Rust", "Programming"]