epub: support epub version

This commit is contained in:
Changkun Ou
2019-09-08 11:55:29 +02:00
parent 4b1181f233
commit 6914acc324
7 changed files with 150 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
DOCKER_ENV=changkun/modern-cpp-tutorial:build-env
LANGS = zh-cn en-us
ALL_BUILDS = website pdf
ALL_BUILDS = website pdf epub
# dep
@@ -12,6 +12,12 @@ $(LANGS):
mkdir -p website/public/modern-cpp/pdf
mv pdf/$@/modern-cpp-tutorial.pdf website/public/modern-cpp/pdf/modern-cpp-tutorial-$@.pdf
epub: $(LANGS)
$(LANGS):
cd epub/$@ && make && make clean
mkdir -p website/public/modern-cpp/epub
mv epub/$@/modern-cpp-tutorial.epub website/public/modern-cpp/epub/modern-cpp-tutorial-$@.epub
website:
cd website && make

View File

@@ -23,7 +23,8 @@
1. [GitHub 在线](./book/zh-cn/toc.md)
2. [PDF 文档](https://changkun.de/modern-cpp/modern-cpp-tutorial-zh-cn.pdf)
3. [网站](https://changkun.de/modern-cpp/)
3. [EPUB 文档](https://changkun.de/modern-cpp/epub/modern-cpp-tutorial-zh-cn.epub)
4. [网站](https://changkun.de/modern-cpp/)
## 相关代码

View File

@@ -26,6 +26,7 @@ You can choose from the following reading methods:
- [GitHub Online](./book/en-us/toc.md)
- [PDF document](https://changkun.de/modern-cpp/pdf/modern-cpp-tutorial-en-us.pdf)
- [EPUB document](https://changkun.de/modern-cpp/epub/modern-cpp-tutorial-en-us.epub)
- [Website](https://changkun.de/modern-cpp)
## Code

51
epub/en-us/Makefile Normal file
View File

@@ -0,0 +1,51 @@
title = 'Modern C++ Tutorial: C++11/14/17/20 On the Fly'
filename = 'modern-cpp-tutorial'
outputname='modern-cpp-tutorial'
revision = $(shell git describe --always --tags)
date = $(shell date +'%Y.%m.%d-%H:%M')
all: revision epub
revision:
@echo '---' >> meta.markdown
@echo 'title: "Modern C++ Tutorial: C++11/14/17/20 On the Fly"' >> meta.markdown
@echo 'author: Changkun Ou <hi@changkun.us>' >> meta.markdown
@echo 'subtitle: |' >> meta.markdown
@echo ' The content in this PDF file may outdated, please check our website <https://changkun.de/modern-cpp> or GitHub repository <https://github.com/changkun/modern-cpp-tutorial> for the latest book updates. Last update: ${date}' >> meta.markdown
@echo 'rights: © Ou Changkun, CC BY-NC-ND 4.0.' >> meta.markdown
@echo 'ibooks:' >> meta.markdown
@echo ' - version: ${revision}' >> meta.markdown
@echo '---' >> meta.markdown
epub: markdown
@echo "Compiling PDF file..."
pandoc -f markdown+smart --toc -t epub -o $(filename).epub \
--highlight-style haddock \
--epub-cover-image ../../assets/cover-2nd-en.png \
--title-prefix $(title) \
meta.markdown \
00-preface.md.markdown \
01-intro.md.markdown \
02-usability.md.markdown \
03-runtime.md.markdown \
04-containers.md.markdown \
05-pointers.md.markdown \
06-regex.md.markdown \
07-thread.md.markdown \
08-filesystem.md.markdown \
09-others.md.markdown \
10-cpp20.md.markdown \
appendix1.md.markdown \
appendix2.md.markdown
@echo "Done."
rm -f *.md *.markdown
markdown:
@echo "Copy markdown files..."
cp -r ../../book/en-us/* .
@echo "Aggregating markdown files..."
python3 filter.py
clean:
rm -rf *.md *.markdown
.PHONY: markdown epub clean

19
epub/en-us/filter.py Normal file
View File

@@ -0,0 +1,19 @@
# !/usr/bin/env python3
# author: changkun<hi@changkun.us>
import os
chapters = ['00-preface.md', '01-intro.md', '02-usability.md', '03-runtime.md', '04-containers.md', '05-pointers.md', '06-regex.md', '07-thread.md', '08-filesystem.md', '09-others.md', '10-cpp20.md', 'appendix1.md', 'appendix2.md']
ignores = ['TOC', 'Table of Content', 'License', 'license']
for chapter in chapters:
with open(chapter+'.markdown', 'w') as outfile:
if os.path.isfile(chapter):
with open(chapter) as ch:
outfile.write('\n')
for line in ch:
if any(keyword in line for keyword in ignores):
continue
else:
outfile.write(line)

51
epub/zh-cn/Makefile Normal file
View File

@@ -0,0 +1,51 @@
title = '现代 C++ 教程:高速上手 C++11/14/17/20'
filename = 'modern-cpp-tutorial'
outputname='modern-cpp-tutorial'
revision = $(shell git describe --always --tags)
date = $(shell date +'%Y.%m.%d-%H:%M')
all: revision epub
revision:
@echo '---' >> meta.markdown
@echo 'title: "现代 C++ 教程:高速上手 C++11/14/17/20"' >> meta.markdown
@echo 'author: 欧长坤 <hi@changkun.us>' >> meta.markdown
@echo 'subtitle: |' >> meta.markdown
@echo ' 此文件的内容可能过期,请检查本书网站 <https://changkun.de/modern-cpp> 及 GitHub 仓库<https://github.com/changkun/modern-cpp-tutorial> 以获取最新内容。最后更新:${date}' >> meta.markdown
@echo 'rights: © Ou Changkun, CC BY-NC-ND 4.0.' >> meta.markdown
@echo 'ibooks:' >> meta.markdown
@echo ' - version: ${revision}' >> meta.markdown
@echo '---' >> meta.markdown
epub: markdown
@echo "Compiling PDF file..."
pandoc -f markdown+smart --toc -t epub -o $(filename).epub \
--highlight-style haddock \
--epub-cover-image ../../assets/cover-2nd.png \
--title-prefix $(title) \
meta.markdown \
00-preface.md.markdown \
01-intro.md.markdown \
02-usability.md.markdown \
03-runtime.md.markdown \
04-containers.md.markdown \
05-pointers.md.markdown \
06-regex.md.markdown \
07-thread.md.markdown \
08-filesystem.md.markdown \
09-others.md.markdown \
10-cpp20.md.markdown \
appendix1.md.markdown \
appendix2.md.markdown
@echo "Done."
rm -f *.md *.markdown
markdown:
@echo "Copy markdown files..."
cp -r ../../book/zh-cn/* .
@echo "Aggregating markdown files..."
python3 filter.py
clean:
rm -rf *.md *.markdown
.PHONY: markdown epub clean

19
epub/zh-cn/filter.py Normal file
View File

@@ -0,0 +1,19 @@
# !/usr/bin/env python3
# author: changkun<hi@changkun.us>
import os
chapters = ['00-preface.md', '01-intro.md', '02-usability.md', '03-runtime.md', '04-containers.md', '05-pointers.md', '06-regex.md', '07-thread.md', '08-filesystem.md', '09-others.md', '10-cpp20.md', 'appendix1.md', 'appendix2.md']
ignores = ['TOC', '返回目录', '许可', 'license']
for chapter in chapters:
with open(chapter+'.markdown', 'w') as outfile:
if os.path.isfile(chapter):
with open(chapter) as ch:
outfile.write('\n')
for line in ch:
if any(keyword in line for keyword in ignores):
continue
else:
outfile.write(line)