diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..29818c9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +services: + - docker + +before_install: +- openssl aes-256-cbc -K $encrypted_9157553ce13c_key -iv $encrypted_9157553ce13c_iv -in .travis/travis.enc -out ~/.ssh/id_rsa -d +- chmod 600 ~/.ssh/id_rsa +- git config --global user.name "Changkun Ou" +- git config --global user.email "hi@changkun.us" +- make build-env + +addons: + ssh_known_hosts: + - changkun.de + +script: + - make build + +after_success: + scp -r website/public/modern-cpp/* $encrypted_server_user@changkun.de:$encrypted_server_path diff --git a/.travis/travis.enc b/.travis/travis.enc new file mode 100644 index 0000000..220056d Binary files /dev/null and b/.travis/travis.enc differ diff --git a/Makefile b/Makefile index 5bc73e6..a0b76f0 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,26 @@ -all: pdf website +DOCKER_ENV=changkun/modern-cpp-tutorial:build-env +LANGS = zh-cn en-us +ALL_BUILDS = pdf website -pdf: - cd pdf/zh-cn && make - cd pdf/en-us && make +# dep + +all: $(ALL_BUILDS) + +pdf: $(LANGS) +$(LANGS): + cd pdf/$@ && make && make clean website: cd website && make +build: + docker run --rm -v `pwd`:/modern-cpp-tutorial -it $(DOCKER_ENV) make + +# dev + +build-env: + docker build -t $(DOCKER_ENV) -f ./docker/Dockerfile . + serve: cd website && make s @@ -14,5 +28,7 @@ clean: cd pdf/zh-cn && make clean cd pdf/en-us && make clean cd website && make clean + docker images -f "dangling=true" -q | xargs docker rmi -f + docker image prune -f -.PHONY : pdf website clean \ No newline at end of file +.PHONY : $(LANGS) $(ALL_BUILDS) serve build-env build-all clean \ No newline at end of file diff --git a/README-zh-cn.md b/README-zh-cn.md index 110ffc7..3ad98d9 100644 --- a/README-zh-cn.md +++ b/README-zh-cn.md @@ -37,6 +37,14 @@ 本书的[网站](https://changkun.de/modern-cpp)源码可以在[这里](./website)找到,由 [hexo](https://hexo.io) 和 [vuejs](https://vuejs.org) 协同构建而成。网站旨在提供一个除 GitHub 之外的阅读方式,除了在桌面端访问之外,你也可以在移动端上阅读本书。 +## 构建 + +如果你希望在本地编译整个仓库,我们建议使用 [Docker](https://docs.docker.com/install/)。如果 Docker 在你的本地能正常使用,则可以简单的通过运行下面的指令完成构建: + +```bash +$ make build +``` + ## 致谢 笔者时间和水平有限,如果读者发现书中内容的错误,欢迎提 [Issue](https://github.com/changkun/modern-cpp-tutorial/issues),或者直接提 [Pull request](https://github.com/changkun/modern-cpp-tutorial/pulls)。详细贡献指南请参考[如何参与贡献](CONTRIBUTING.md),由衷感谢每一位指出本书中出现错误的读者,包括但不限于 [Contributors](https://github.com/changkun/modern-cpp-tutorial/graphs/contributors)。 diff --git a/README.md b/README.md index a9d0eb7..3426115 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,14 @@ There are few exercises At the end of each chapter of the book. It is for testin The source code of the [website](https://changkun.de/modern-cpp) of this book can be found [here](./website), which is built by [hexo](https://hexo.io) and [vuejs](https://vuejs.org). The website provides you another way of reading the book, it is also adapts to mobile. +## Build + +If you are interested in build everything locally, it is recommended using [Docker](https://docs.docker.com/install/). To build, simply run: + +```bash +$ make build +``` + ## Acknowledgements This book was originally written in Chinese by [Changkun Ou](https://changkun.de). diff --git a/book/zh-cn/10-cpp20.md b/book/zh-cn/10-cpp20.md index 905d464..3c81c8d 100644 --- a/book/zh-cn/10-cpp20.md +++ b/book/zh-cn/10-cpp20.md @@ -55,7 +55,7 @@ void sort(Sortable& c); // c 是一个 Sortable 类型的对象 我们现在来看一个实际的例子。 -TODO: +TODO: https://godbolt.org/z/9liFPD ## 模块 diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..0f78b0e --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,18 @@ +FROM node:latest + +LABEL "maintainer"="Changkun Ou " +LABEL "repository"="https://github.com/changkun/modern-cpp-tutorial" +LABEL "homepage"="https://changkun.de/modern-cpp/" + +# FUCKING UNICODE +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 + +WORKDIR /modern-cpp-tutorial + +# Node & Npm & Python3 are from node:latest +# Install Texlive & Pandoc +RUN apt update && \ + apt install wget texlive-full -y && \ + wget https://github.com/jgm/pandoc/releases/download/2.7.3/pandoc-2.7.3-1-amd64.deb && \ + dpkg -i pandoc-2.7.3-1-amd64.deb diff --git a/pdf/en-us/Makefile b/pdf/en-us/Makefile index a7b3c39..d51fb45 100644 --- a/pdf/en-us/Makefile +++ b/pdf/en-us/Makefile @@ -11,21 +11,21 @@ revision: pdf: markdown @echo "Compiling PDF file..." - @pandoc -f markdown+smart -s $(filename).md -o $(filename).pdf \ + pandoc -f markdown+smart -s $(filename).md -o $(filename).pdf \ --title-prefix $(title) \ --listings -H meta/cpp-listings.tex \ --template=meta/template.tex \ --pdf-engine=`which xelatex` @echo "Done." - @rm *.md revision.tex + rm *.md revision.tex markdown: @echo "Copy markdown files..." - @cp -r ../../book/en-us/* . + cp -r ../../book/en-us/* . @echo "Aggregating markdown files..." - @python3 aggregator.py + python3 aggregator.py clean: - rm -rf revision.tex *.md *.pdf + rm -rf revision.tex *.md .PHONY: markdown pdf clean \ No newline at end of file diff --git a/pdf/en-us/modern-cpp-tutorial.pdf b/pdf/en-us/modern-cpp-tutorial.pdf index 44650f9..317baf9 100644 Binary files a/pdf/en-us/modern-cpp-tutorial.pdf and b/pdf/en-us/modern-cpp-tutorial.pdf differ diff --git a/pdf/zh-cn/Makefile b/pdf/zh-cn/Makefile index fafe598..e8d8d31 100644 --- a/pdf/zh-cn/Makefile +++ b/pdf/zh-cn/Makefile @@ -11,21 +11,21 @@ revision: pdf: markdown @echo "Compiling PDF file..." - @pandoc -f markdown+smart -s $(filename).md -o $(filename).pdf \ + pandoc -f markdown+smart -s $(filename).md -o $(filename).pdf \ --title-prefix $(title) \ --listings -H meta/cpp-listings.tex \ --template=meta/template.tex \ --pdf-engine=`which xelatex` @echo "Done." - @rm *.md revision.tex + rm *.md revision.tex markdown: @echo "Copy markdown files..." - @cp -r ../../book/zh-cn/* . + cp -r ../../book/zh-cn/* . @echo "Aggregating markdown files..." - @python3 aggregator.py + python3 aggregator.py clean: - rm -rf revision.tex *.md *.pdf + rm -rf revision.tex *.md .PHONY: markdown pdf clean \ No newline at end of file diff --git a/pdf/zh-cn/aggregator.py b/pdf/zh-cn/aggregator.py index a5555fa..f8a3c22 100755 --- a/pdf/zh-cn/aggregator.py +++ b/pdf/zh-cn/aggregator.py @@ -1,19 +1,21 @@ # !/usr/bin/env python3 # author: changkun -import os +import os, io 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'] -with open('modern-cpp-tutorial.md', 'w') as outfile: - outfile.write("""--- +head = """--- title: "高速上手 C++11/14/17/20" author: 欧长坤 copyright: cc-by-nc-nd 4.0 --- -""") +""" + +with io.open('modern-cpp-tutorial.md', 'w', encoding='utf8') as outfile: + outfile.write(head) for chapter in chapters: if os.path.isfile(chapter): with open(chapter) as ch: diff --git a/pdf/zh-cn/modern-cpp-tutorial.pdf b/pdf/zh-cn/modern-cpp-tutorial.pdf index 089d003..d716171 100644 Binary files a/pdf/zh-cn/modern-cpp-tutorial.pdf and b/pdf/zh-cn/modern-cpp-tutorial.pdf differ diff --git a/website/Makefile b/website/Makefile index 43561df..1caf86d 100755 --- a/website/Makefile +++ b/website/Makefile @@ -11,19 +11,17 @@ all: clean cp -r ../assets/figures ./src/modern-cpp/assets/figures cp -r ../exercises ./src/modern-cpp/ cp -r ../code ./src/modern-cpp/ - hexo generate + npx hexo generate mv public/index.html public/modern-cpp/index.html s: all node_modules/serve/bin/serve.js ./public clean: - rm -rf ./src/modern-cpp/assets/cover-2nd.png - rm -rf ./src/modern-cpp/assets/figures - rm -rf public db.json src/modern-cpp/zh-cn - rm -rf public db.json src/modern-cpp/en-us - rm -rf ./src/modern-cpp/assets/alipay.jpg - rm -rf ./src/modern-cpp/assets/wechat.jpg - rm -rf ./src/modern-cpp/about/donate.md - rm -rf ./src/modern-cpp/about/community.md - rm -rf ./src/modern-cpp/code - rm -rf ./src/modern-cpp/exercises - \ No newline at end of file + rm -rf ./src/modern-cpp/assets/cover-2nd.png \ + ./src/modern-cpp/assets/figures \ + ./src/modern-cpp/assets/alipay.jpg \ + ./src/modern-cpp/assets/wechat.jpg \ + ./src/modern-cpp/about/donate.md \ + ./src/modern-cpp/about/community.md \ + ./src/modern-cpp/code \ + ./src/modern-cpp/exercises \ + public db.json src/modern-cpp/zh-cn src/modern-cpp/en-us