diff --git a/Makefile b/Makefile index 43c30e5..791e8f0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README-zh-cn.md b/README-zh-cn.md index 6a0e073..ef89758 100644 --- a/README-zh-cn.md +++ b/README-zh-cn.md @@ -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/) ## 相关代码 diff --git a/README.md b/README.md index 6931c84..5249e67 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/epub/en-us/Makefile b/epub/en-us/Makefile new file mode 100644 index 0000000..94039b8 --- /dev/null +++ b/epub/en-us/Makefile @@ -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 ' >> meta.markdown + @echo 'subtitle: |' >> meta.markdown + @echo ' The content in this PDF file may outdated, please check our website or GitHub repository 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 \ No newline at end of file diff --git a/epub/en-us/filter.py b/epub/en-us/filter.py new file mode 100644 index 0000000..65d0a2c --- /dev/null +++ b/epub/en-us/filter.py @@ -0,0 +1,19 @@ +# !/usr/bin/env python3 +# author: changkun + +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) \ No newline at end of file diff --git a/epub/zh-cn/Makefile b/epub/zh-cn/Makefile new file mode 100644 index 0000000..a2b0dcc --- /dev/null +++ b/epub/zh-cn/Makefile @@ -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: 欧长坤 ' >> meta.markdown + @echo 'subtitle: |' >> meta.markdown + @echo ' 此文件的内容可能过期,请检查本书网站 及 GitHub 仓库 以获取最新内容。最后更新:${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 \ No newline at end of file diff --git a/epub/zh-cn/filter.py b/epub/zh-cn/filter.py new file mode 100644 index 0000000..d25143f --- /dev/null +++ b/epub/zh-cn/filter.py @@ -0,0 +1,19 @@ +# !/usr/bin/env python3 +# author: changkun + +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) \ No newline at end of file