From 15ba3a80c52cca9fcc8af2a09a0c76643ce94825 Mon Sep 17 00:00:00 2001 From: Ahmed AbouZaid Date: Thu, 31 Jan 2019 08:47:14 +0100 Subject: [PATCH] set images extension to fix missing images in mobi format --- Dockerfile | 1 + bootstrap.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Dockerfile b/Dockerfile index 6085fe3..f0147c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ ruby-dev \ wget \ zlib1g-dev \ + file \ && gem install bundler --no-ri --no-rdoc \ && bundle install \ && apt-get clean \ diff --git a/bootstrap.sh b/bootstrap.sh index b29a07f..fa687d6 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -36,6 +36,22 @@ 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 +IMGS_FILES="$(ls /src/html/${IMGS_DOMAIN}/*)" +for FILE_NAME_FULL in ${IMGS_FILES}; do + + # Get file vars. + FILE_NAME_BASE="$(basename ${FILE_NAME_FULL})" + FILE_TYPE=$(file -b -- "${FILE_NAME_FULL}" | cut -f1 -d " ") + + # 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 + # ruby generate.rb