From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:53:43 +0000 (+0200) Subject: Add ePUB format (#130) X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=fb8f83a51871c2cf411b47c00f3232bf0cbd450e;p=rust_exercises.git Add ePUB format (#130) --- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ccd0bd..74683de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,11 +20,11 @@ jobs: run: cargo install --path helpers/mdbook-exercise-linker - name: Install link shortener plugin run: cargo install --path helpers/mdbook-link-shortener - - name: Install mdbook-pandoc and related dependencies + - name: Install mdbook-pandoc, calibre and related dependencies run: | cargo install mdbook-pandoc --locked --version 0.7.1 sudo apt-get update - sudo apt-get install -y fonts-noto + sudo apt-get install -y fonts-noto calibre 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 - @@ -70,6 +70,13 @@ jobs: run: | cd book mdbook build + - name: Convert HTML to ePUB + run: | + cd book/book/pandoc/html + sed -i 's|\\newpage{=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 uses: lycheeverse/lychee-action@v1 with: @@ -94,6 +101,10 @@ jobs: with: name: paperback 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: runs-on: ubuntu-latest diff --git a/book/book.toml b/book/book.toml index e1abf43..c739aa6 100644 --- a/book/book.toml +++ b/book/book.toml @@ -5,6 +5,19 @@ multilingual = false src = "src" 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] optional = true 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 # that supports fallback fonts, which we need for emojis. pdf-engine = "lualatex" +metadata-file = "metadata.yml" [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+ mainfont = "Noto Serif" sansfont = "Noto Sans" @@ -43,12 +56,12 @@ header-includes = [ output-file = "100-exercises-to-learn-rust.pdf" to = "latex" highlight-style = "monochrome" +metadata-file = "metadata.yml" # We use `lualatext` because, right now, it's the only engine # that supports fallback fonts, which we need for emojis. pdf-engine = "lualatex" [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+ mainfont = "Noto Serif" sansfont = "Noto Sans" @@ -68,15 +81,26 @@ header-includes = [ ] links-as-notes = true -[output.html] -git-repository-url = "https://github.com/mainmatter/100-exercises-to-learn-rust" - -[preprocessor.exercise-linker] -exercise_root_url = "https://github.com/mainmatter/100-exercises-to-learn-rust/tree/main/exercises" +# We go through HTML, rather than directly to ePUB, since routing +# 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.link-shortener] -base_url = "https://ruex.io" -renderers = ["pandoc"] -mapping = "link2alias.json" -verify = false -after = ["exercise-linker"] +[output.pandoc.profile.html.variables] +# You can get these fonts here: https://fonts.google.com/selection?query=noto+color+ +mainfont = "Noto Serif" +sansfont = "Noto Sans" +monofont = "Noto Sans Mono" +mainfontfallback = ["Noto Color Emoji:mode=harf"] +sansfontfallback = ["Noto Color Emoji:mode=harf"] +monofontfallback = [ + "Noto Color Emoji:mode=harf", +] +linkcolor = "blue" +urlcolor = "blue" +urlstyle = "rm" diff --git a/book/metadata.yml b/book/metadata.yml new file mode 100644 index 0000000..0ab8aaf --- /dev/null +++ b/book/metadata.yml @@ -0,0 +1,4 @@ +title: "100 Exercises To Learn Rust" +subtitle: "A hands-on course by Mainmatter" +author: "Luca Palmieri" +keywords: ["Rust", "Programming"] \ No newline at end of file