Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build PDF on Actions, convert to EPUB and MOBI and expose as artifacts #3515

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ jobs:
uses: actions/checkout@v2

- name: Install pandoc
run: brew install pandoc
run: sudo apt-get -y install pandoc

- name: Install LaTeX dependencies
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get -y install texlive-xetex texlive-science texlive-fonts-extra

- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
Expand All @@ -36,11 +40,37 @@ jobs:
run: opam install dune>=3.4.1

- name: Build HTML book
run: opam exec -- dune build @site
run: opam exec -- dune build

- name: Deploy site
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/master' && runner.os == 'Linux'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_build/default/static

- name: Upload artifacts (html, pdf, md, tex)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v2
with:
name: static
path: ./_build/default/static

- name: Upload PDF artifact
if: runner.os == 'Linux'
uses: actions/upload-artifact@v2
with:
name: book.pdf
path: ./_build/default/static/book.pdf

- name: Convert to EPUB
if: runner.os == 'Linux'
working-directory: ./_build/default/static
run: pandoc --top-level-division=part --filter=../bin/pandoc-rwo/pandoc_rwo_epub.exe --metadata-file=../book/book.yml --listings -o book.epub -t epub -s book.md

- name: Upload EPUB artifact
if: runner.os == 'Linux'
uses: actions/upload-artifact@v2
with:
name: book.epub
path: ./_build/default/static/book.epub
19 changes: 15 additions & 4 deletions bin/pandoc-rwo/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
(library
(name pandoc)
(modules pandoc)
(libraries yojson))

(executable
(public_name pandoc-rwo)
(name pandoc_rwo)
(libraries yojson)
)
(public_name pandoc-rwo)
(name pandoc_rwo)
(modules pandoc_rwo)
(libraries yojson pandoc))

(executable
(public_name pandoc-rwo-epub)
(name pandoc_rwo_epub)
(modules pandoc_rwo_epub)
(libraries yojson pandoc))
17 changes: 17 additions & 0 deletions bin/pandoc-rwo/pandoc_rwo_epub.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(* Rewrite cross-references, untouch notes *)
let () =
let j = Yojson.Basic.from_channel stdin in
let p = Pandoc.of_json j in
let inline = function
(* handle xrefs like [Foo](bar.html#label){data-type="xref"} *)
| Pandoc.Link ((i,c,attr),body,(url,title)) as l -> begin
List.assoc_opt "data-type" attr |> function
| Some "xref" -> (* this is a cross-reference *)
let url = Scanf.sscanf url "%s@#%s" (fun _ t -> t) in
Some [Pandoc.Link ((i,c,attr),body,("#" ^ url,title))]
| Some _ | None -> Some [l]
end
| n -> Some [n] in
let p = Pandoc.map ~inline p in
let s = Yojson.Basic.pretty_to_string (Pandoc.to_json p) in
print_endline s