Skip to content

Commit

Permalink
Improve typography by switching to pandoc for PDF generation
Browse files Browse the repository at this point in the history
  • Loading branch information
captn3m0 committed Apr 30, 2020
1 parent af61f95 commit 265d11a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ COPY . /src/

RUN bundle install

ENTRYPOINT ["/src/bootstrap.sh", "docker"]
ENTRYPOINT ["/src/generate.sh", "docker"]

VOLUME ["/output"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The build for the above Docker image can be audited at <https://hub.docker.com/r

## macOS

Review and run the `bootstrap.sh` script to generate the EPUB, MOBI, and PDF files
Review and run the `generate.sh` script to generate the EPUB, MOBI, and PDF files

Requirements:

Expand Down
2 changes: 0 additions & 2 deletions generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@
content = content.children.at_css('div')
end



# replace h1 title
content.at_css('h1').inner_html = title

Expand Down
33 changes: 28 additions & 5 deletions bootstrap.sh → generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export ${BOOKS[${BOOK_SLUG^^}]}
# Common vars.
IMGS_DOMAIN="lh3.googleusercontent.com"

#
# Make sure that links are relative \
# # Remove the /sre/ directories
# Save stuff in html/ directory
Expand Down Expand Up @@ -42,7 +41,6 @@ if [ "$MODE" != "docker" ];then
bundle install
fi

#
# Add extension to files.
# That because `pandoc` cannot generate the right `mime type` without the extension.
# https://github.com/captn3m0/google-sre-ebook/issues/19
Expand All @@ -60,7 +58,11 @@ for FILE_NAME_FULL in ${IMGS_FILES}; do

done

#
if [[ $@ == *'--only-download'* ]]; then
echo "Skipping generation"
exit 0
fi

# Generate epub from html.
echo "Generate book ..."
bundle exec ruby generate.rb
Expand All @@ -69,16 +71,37 @@ pandoc --from=html --to=epub \
--output=../../../../../${BOOK_FILE}.epub \
--epub-metadata=../../../../../metadata/${BOOK_NAME}.xml \
--epub-cover-image=../../../../../cover/${BOOK_NAME}.jpg \
--metadata title="$BOOK_NAME" \
complete.html

pandoc --from=html --to=pdf \
--output=../../../../../${BOOK_FILE}.pdf \
--metadata title="$BOOK_NAME" \
--pdf-engine=xelatex \
--dpi=300 \
-V book \
--top-level-division=chapter \
--toc \
-V lang=en-US \
-V classoption=oneside \
-V titlepage=true \
-V logo=../../../../../cover/${BOOK_NAME}.jpg \
-V titlepage-background=../../../../../cover/${BOOK_NAME}.jpg \
-V toc-own-page=true \
-V footnotes-pretty=true \
-V subparagraph \
-V geometry=margin=2cm \
-V fig_caption=false \
--columns=60 \
complete.html

popd

#
# Generate other format from epub.
for EXTENSION in mobi pdf; do
ebook-convert ${BOOK_FILE}.epub ${BOOK_FILE}.${EXTENSION}
done

#
# If it works inside docker.
if [ "$MODE" == "docker" ]; then
chown -v $(id -u):$(id -g) ${BOOK_FILE}.*
Expand Down

0 comments on commit 265d11a

Please sign in to comment.