Skip to content

Commit 6914acc

Browse files
committed
epub: support epub version
1 parent 4b1181f commit 6914acc

File tree

7 files changed

+150
-2
lines changed

7 files changed

+150
-2
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
DOCKER_ENV=changkun/modern-cpp-tutorial:build-env
22
LANGS = zh-cn en-us
3-
ALL_BUILDS = website pdf
3+
ALL_BUILDS = website pdf epub
44

55
# dep
66

@@ -12,6 +12,12 @@ $(LANGS):
1212
mkdir -p website/public/modern-cpp/pdf
1313
mv pdf/$@/modern-cpp-tutorial.pdf website/public/modern-cpp/pdf/modern-cpp-tutorial-$@.pdf
1414

15+
epub: $(LANGS)
16+
$(LANGS):
17+
cd epub/$@ && make && make clean
18+
mkdir -p website/public/modern-cpp/epub
19+
mv epub/$@/modern-cpp-tutorial.epub website/public/modern-cpp/epub/modern-cpp-tutorial-$@.epub
20+
1521
website:
1622
cd website && make
1723

README-zh-cn.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
1. [GitHub 在线](./book/zh-cn/toc.md)
2525
2. [PDF 文档](https://changkun.de/modern-cpp/modern-cpp-tutorial-zh-cn.pdf)
26-
3. [网站](https://changkun.de/modern-cpp/)
26+
3. [EPUB 文档](https://changkun.de/modern-cpp/epub/modern-cpp-tutorial-zh-cn.epub)
27+
4. [网站](https://changkun.de/modern-cpp/)
2728

2829
## 相关代码
2930

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ You can choose from the following reading methods:
2626

2727
- [GitHub Online](./book/en-us/toc.md)
2828
- [PDF document](https://changkun.de/modern-cpp/pdf/modern-cpp-tutorial-en-us.pdf)
29+
- [EPUB document](https://changkun.de/modern-cpp/epub/modern-cpp-tutorial-en-us.epub)
2930
- [Website](https://changkun.de/modern-cpp)
3031

3132
## Code

epub/en-us/Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
title = 'Modern C++ Tutorial: C++11/14/17/20 On the Fly'
2+
filename = 'modern-cpp-tutorial'
3+
outputname='modern-cpp-tutorial'
4+
revision = $(shell git describe --always --tags)
5+
date = $(shell date +'%Y.%m.%d-%H:%M')
6+
all: revision epub
7+
8+
revision:
9+
@echo '---' >> meta.markdown
10+
@echo 'title: "Modern C++ Tutorial: C++11/14/17/20 On the Fly"' >> meta.markdown
11+
@echo 'author: Changkun Ou <hi@changkun.us>' >> meta.markdown
12+
@echo 'subtitle: |' >> meta.markdown
13+
@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
14+
@echo 'rights: © Ou Changkun, CC BY-NC-ND 4.0.' >> meta.markdown
15+
@echo 'ibooks:' >> meta.markdown
16+
@echo ' - version: ${revision}' >> meta.markdown
17+
@echo '---' >> meta.markdown
18+
19+
epub: markdown
20+
@echo "Compiling PDF file..."
21+
pandoc -f markdown+smart --toc -t epub -o $(filename).epub \
22+
--highlight-style haddock \
23+
--epub-cover-image ../../assets/cover-2nd-en.png \
24+
--title-prefix $(title) \
25+
meta.markdown \
26+
00-preface.md.markdown \
27+
01-intro.md.markdown \
28+
02-usability.md.markdown \
29+
03-runtime.md.markdown \
30+
04-containers.md.markdown \
31+
05-pointers.md.markdown \
32+
06-regex.md.markdown \
33+
07-thread.md.markdown \
34+
08-filesystem.md.markdown \
35+
09-others.md.markdown \
36+
10-cpp20.md.markdown \
37+
appendix1.md.markdown \
38+
appendix2.md.markdown
39+
@echo "Done."
40+
rm -f *.md *.markdown
41+
42+
markdown:
43+
@echo "Copy markdown files..."
44+
cp -r ../../book/en-us/* .
45+
@echo "Aggregating markdown files..."
46+
python3 filter.py
47+
48+
clean:
49+
rm -rf *.md *.markdown
50+
51+
.PHONY: markdown epub clean

epub/en-us/filter.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# !/usr/bin/env python3
2+
# author: changkun<hi@changkun.us>
3+
4+
import os
5+
6+
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']
7+
8+
ignores = ['TOC', 'Table of Content', 'License', 'license']
9+
10+
for chapter in chapters:
11+
with open(chapter+'.markdown', 'w') as outfile:
12+
if os.path.isfile(chapter):
13+
with open(chapter) as ch:
14+
outfile.write('\n')
15+
for line in ch:
16+
if any(keyword in line for keyword in ignores):
17+
continue
18+
else:
19+
outfile.write(line)

epub/zh-cn/Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
title = '现代 C++ 教程:高速上手 C++11/14/17/20'
2+
filename = 'modern-cpp-tutorial'
3+
outputname='modern-cpp-tutorial'
4+
revision = $(shell git describe --always --tags)
5+
date = $(shell date +'%Y.%m.%d-%H:%M')
6+
all: revision epub
7+
8+
revision:
9+
@echo '---' >> meta.markdown
10+
@echo 'title: "现代 C++ 教程:高速上手 C++11/14/17/20"' >> meta.markdown
11+
@echo 'author: 欧长坤 <hi@changkun.us>' >> meta.markdown
12+
@echo 'subtitle: |' >> meta.markdown
13+
@echo ' 此文件的内容可能过期,请检查本书网站 <https://changkun.de/modern-cpp> 及 GitHub 仓库<https://github.com/changkun/modern-cpp-tutorial> 以获取最新内容。最后更新:${date}' >> meta.markdown
14+
@echo 'rights: © Ou Changkun, CC BY-NC-ND 4.0.' >> meta.markdown
15+
@echo 'ibooks:' >> meta.markdown
16+
@echo ' - version: ${revision}' >> meta.markdown
17+
@echo '---' >> meta.markdown
18+
19+
epub: markdown
20+
@echo "Compiling PDF file..."
21+
pandoc -f markdown+smart --toc -t epub -o $(filename).epub \
22+
--highlight-style haddock \
23+
--epub-cover-image ../../assets/cover-2nd.png \
24+
--title-prefix $(title) \
25+
meta.markdown \
26+
00-preface.md.markdown \
27+
01-intro.md.markdown \
28+
02-usability.md.markdown \
29+
03-runtime.md.markdown \
30+
04-containers.md.markdown \
31+
05-pointers.md.markdown \
32+
06-regex.md.markdown \
33+
07-thread.md.markdown \
34+
08-filesystem.md.markdown \
35+
09-others.md.markdown \
36+
10-cpp20.md.markdown \
37+
appendix1.md.markdown \
38+
appendix2.md.markdown
39+
@echo "Done."
40+
rm -f *.md *.markdown
41+
42+
markdown:
43+
@echo "Copy markdown files..."
44+
cp -r ../../book/zh-cn/* .
45+
@echo "Aggregating markdown files..."
46+
python3 filter.py
47+
48+
clean:
49+
rm -rf *.md *.markdown
50+
51+
.PHONY: markdown epub clean

epub/zh-cn/filter.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# !/usr/bin/env python3
2+
# author: changkun<hi@changkun.us>
3+
4+
import os
5+
6+
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']
7+
8+
ignores = ['TOC', '返回目录', '许可', 'license']
9+
10+
for chapter in chapters:
11+
with open(chapter+'.markdown', 'w') as outfile:
12+
if os.path.isfile(chapter):
13+
with open(chapter) as ch:
14+
outfile.write('\n')
15+
for line in ch:
16+
if any(keyword in line for keyword in ignores):
17+
continue
18+
else:
19+
outfile.write(line)

0 commit comments

Comments
 (0)