Fix missing images in mobi format. (#20)
This commit is contained in:
commit
41c6c3eff2
|
@ -15,6 +15,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
ruby-dev \
|
ruby-dev \
|
||||||
wget \
|
wget \
|
||||||
zlib1g-dev \
|
zlib1g-dev \
|
||||||
|
file \
|
||||||
&& gem install bundler --no-ri --no-rdoc \
|
&& gem install bundler --no-ri --no-rdoc \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
|
@ -39,7 +39,7 @@ Requirements:
|
||||||
|
|
||||||
- Ruby
|
- Ruby
|
||||||
- `gem install bundler`
|
- `gem install bundler`
|
||||||
- `gem install nokogiri`
|
- `bundle install`
|
||||||
- `brew install pandoc`
|
- `brew install pandoc`
|
||||||
- `brew cask install calibre`
|
- `brew cask install calibre`
|
||||||
- `brew install wget`
|
- `brew install wget`
|
||||||
|
|
65
bootstrap.sh
65
bootstrap.sh
|
@ -2,7 +2,13 @@
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
TOC_URL="https://landing.google.com/sre/sre-book/toc/index.html"
|
# Vars.
|
||||||
|
export BOOK_NAME="sre-book"
|
||||||
|
export BOOK_NAME_FULL="Site Reliability Engineering"
|
||||||
|
BOOK_FILE="google-${BOOK_NAME}"
|
||||||
|
TOC_URL="https://landing.google.com/sre/${BOOK_NAME}/toc/index.html"
|
||||||
|
IMGS_DOMAIN="lh3.googleusercontent.com"
|
||||||
|
|
||||||
# Make sure that links are relative \
|
# Make sure that links are relative \
|
||||||
# # Remove the /sre/ directories
|
# # Remove the /sre/ directories
|
||||||
# Save stuff in html/ directory
|
# Save stuff in html/ directory
|
||||||
|
@ -11,36 +17,55 @@ TOC_URL="https://landing.google.com/sre/sre-book/toc/index.html"
|
||||||
# Images are hosted elsewhere, download them as well.
|
# Images are hosted elsewhere, download them as well.
|
||||||
# We need to go up a level from /toc/ where we start
|
# We need to go up a level from /toc/ where we start
|
||||||
wget \
|
wget \
|
||||||
--convert-links \
|
--convert-links \
|
||||||
--directory-prefix=html \
|
--directory-prefix=html \
|
||||||
--page-requisites \
|
--page-requisites \
|
||||||
--adjust-extension \
|
--adjust-extension \
|
||||||
--span-hosts \
|
--span-hosts \
|
||||||
--trust-server-names \
|
--trust-server-names \
|
||||||
--backup-converted \
|
--backup-converted \
|
||||||
--mirror \
|
--mirror \
|
||||||
--no-verbose \
|
--no-verbose \
|
||||||
--recursive \
|
--recursive \
|
||||||
--domains=lh3.googleusercontent.com,landing.google.com https://landing.google.com/sre/sre-book/toc/index.html
|
--domains=${IMGS_DOMAIN},landing.google.com ${TOC_URL}
|
||||||
|
|
||||||
|
#
|
||||||
MODE=${1:-}
|
MODE=${1:-}
|
||||||
|
|
||||||
if [ "$MODE" != "docker" ];then
|
if [ "$MODE" != "docker" ];then
|
||||||
bundle install
|
bundle install
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ruby generate.rb
|
# 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
|
||||||
|
IMGS_FILES="$(ls html/${IMGS_DOMAIN}/*)"
|
||||||
|
for FILE_NAME_FULL in ${IMGS_FILES}; do
|
||||||
|
|
||||||
pushd html/landing.google.com/sre/sre-book/toc
|
# Get file vars.
|
||||||
pandoc --from=html --to=epub --output=../../../../../google-sre.epub \
|
FILE_NAME_BASE="$(basename ${FILE_NAME_FULL})"
|
||||||
--epub-metadata=../../../../../metadata.xml \
|
FILE_TYPE=$(file -b -- "${FILE_NAME_FULL}" | cut -f1 -d " ")
|
||||||
--epub-cover-image=../../../../../cover.jpg \
|
|
||||||
|
# Rename and replace file.
|
||||||
|
mv "${FILE_NAME_FULL}" "${FILE_NAME_FULL}.${FILE_TYPE,,}" &&
|
||||||
|
grep -rl "${FILE_NAME_BASE}" ./html | xargs sed -i "s/${FILE_NAME_BASE}/${FILE_NAME_BASE}.${FILE_TYPE,,}/g"
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
bundle exec ruby generate.rb
|
||||||
|
pushd html/landing.google.com/sre/${BOOK_NAME}/toc
|
||||||
|
pandoc --from=html --to=epub \
|
||||||
|
--output=../../../../../${BOOK_FILE}.epub \
|
||||||
|
--epub-metadata=../../../../../${BOOK_NAME}.xml \
|
||||||
|
--epub-cover-image=../../../../../${BOOK_NAME}.jpg \
|
||||||
complete.html
|
complete.html
|
||||||
popd
|
popd
|
||||||
ebook-convert google-sre.epub google-sre.mobi
|
|
||||||
ebook-convert google-sre.epub google-sre.pdf
|
for EXTENSION in mobi pdf; do
|
||||||
|
ebook-convert ${BOOK_FILE}.epub ${BOOK_FILE}.${EXTENSION}
|
||||||
|
done
|
||||||
|
|
||||||
if [ "$1"=="docker" ]; then
|
if [ "$1"=="docker" ]; then
|
||||||
chown -v $(id -u):$(id -g) google-sre.*
|
chown -v $(id -u):$(id -g) ${BOOK_FILE}.*
|
||||||
mv -f google-sre.* /output
|
mv -f ${BOOK_FILE}.* /output
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -4,7 +4,7 @@ require 'fileutils'
|
||||||
|
|
||||||
# First we get the list of all the book sections:
|
# First we get the list of all the book sections:
|
||||||
|
|
||||||
Dir.chdir("html/landing.google.com/sre/sre-book/toc")
|
Dir.chdir("html/landing.google.com/sre/%s/toc" % ENV['BOOK_NAME'])
|
||||||
chapter_links = Nokogiri::HTML(open("index.html"))
|
chapter_links = Nokogiri::HTML(open("index.html"))
|
||||||
.css('#drop-down a')
|
.css('#drop-down a')
|
||||||
.map {|l| l.attribute('href').value}
|
.map {|l| l.attribute('href').value}
|
||||||
|
@ -13,7 +13,7 @@ html = <<EOT
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Site Reliability Engineering</title>
|
<title>#{ENV['BOOK_NAME_FULL']}</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
Loading…
Reference in New Issue