Skip to content

Commit 97e1e05

Browse files
committed
Merge branch 'main' into bug_fix
2 parents 818286f + a35ceb1 commit 97e1e05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3733
-53
lines changed

.github/workflows/generate_release_pdf.yml

+39-13
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,31 @@ on:
77
- main
88
paths-ignore:
99
- '.gitignore'
10-
- '**.md'
1110

1211
env:
13-
TYPST_FILE_NAME: cppguidebook
14-
TYPST_FONT_PATH: fonts
1512
MIRROR_SITE_URL: https://142857.red/files
1613
MIRROR_SITE_HOOK: https://142857.red/hooks/update_cppguidebook
1714
MIRROR_SITE_TOKEN: ${{ secrets.SEVEN_TOKEN }}
1815

1916
jobs:
20-
build_typst:
17+
build_mkdocs:
2118
runs-on: ubuntu-latest
2219
permissions:
2320
contents: write
2421
steps:
25-
- name: Set up Git repository for secondary repo
22+
- name: Set up Git repository
2623
uses: actions/checkout@v4
2724

25+
- name: Prepare Mkdocs environment
26+
run: |
27+
pip install mkdocs
28+
pip install mkdocs-print-site-plugin
29+
pip install mkdocs-macros-plugin
30+
31+
- name: Compile Mkdocs document
32+
run: |
33+
mkdocs build
34+
2835
- name: Cache Fonts
2936
uses: actions/cache@v4
3037
id: cache-fonts
@@ -63,13 +70,29 @@ jobs:
6370
curl -L "https://github.com/lxgw/LxgwWenKai/releases/download/v1.330/LXGWWenKai-$form.ttf" -o "${{ env.TYPST_FONT_PATH }}/LXGWWenKai-$form.ttf"
6471
done
6572
66-
- name: Prepare Typst environment
67-
uses: typst-community/setup-typst@v3
73+
- name: Install Fonts
74+
run: |
75+
sudo apt-get install -yq --allow-unauthenticated ttf-mscorefonts-installer
76+
sudo apt-get install -yyq fonts-liberation
6877
69-
- name: Compile Typst document
78+
- name: Prepare Puppeteer environment
7079
run: |
71-
typst fonts --variants --font-path ${{ env.TYPST_FONT_PATH }}
72-
typst compile ${{ env.TYPST_FILE_NAME }}.typ ${{ env.TYPST_FILE_NAME }}.pdf --font-path ${{ env.TYPST_FONT_PATH }}
80+
npm install puppeteer
81+
82+
- name: Compile PDF document
83+
run: |
84+
node misc/export_to_pdf.js file://$PWD/site/print_page/index.html cppguidebook.pdf "小彭老师的现代 C++ 大典"
85+
du -h cppguidebook.pdf
86+
87+
- name: Generate ZIP site
88+
run: |
89+
zip -r cppguidebook-site.zip site
90+
91+
- name: Deploy
92+
uses: peaceiris/actions-gh-pages@v4
93+
with:
94+
github_token: ${{ secrets.GITHUB_TOKEN }}
95+
publish_dir: ./site
7396

7497
- name: Delete old Release
7598
uses: actions/github-script@v7
@@ -85,7 +108,7 @@ jobs:
85108
- name: Generate release tag
86109
id: tag
87110
run: |
88-
echo "release_date=$(date +"%Y 年 %m 月 %d 日 %H 点 %M 分")" >> $GITHUB_OUTPUT
111+
echo "release_date=$(TZ=Asia/Shanghai date +"%Y 年 %m 月 %d 日 %H 点 %M 分")" >> $GITHUB_OUTPUT
89112
echo "release_tag=latest_$(date +"%Y-%m-%d_%H-%M")" >> $GITHUB_OUTPUT
90113
91114
- name: Release
@@ -94,9 +117,12 @@ jobs:
94117
name: 伟大,无需多言
95118
body: |
96119
小彭老师发布的最新 C++ 大典,更新时间 ${{ steps.tag.outputs.release_date }}
97-
> Release 页面太慢?GitHub 卡顿,无法下载?访问 [小彭老师自己维护的镜像](${{ env.MIRROR_SITE_URL }}/${{ env.TYPST_FILE_NAME }}.pdf)。
120+
> GitHub 卡顿,无法下载?访问 [小彭老师自己维护的镜像](${{ env.MIRROR_SITE_URL }}/cppguidebook.pdf)。
121+
> 喜欢在线阅读?访问 [GitHub Pages](https://parallel101.github.io/cppguidebook)
98122
tag_name: ${{ steps.tag.outputs.release_tag }}
99-
files: ${{ env.TYPST_FILE_NAME }}.pdf
123+
files: |
124+
cppguidebook.pdf
125+
cppguidebook-site.zip
100126
101127
- name: Publish to mirror site
102128
continue-on-error: true

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build/
2+
site/
3+
__pycache__/
24
*.pdf
3-
unicode.typ

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ endif()
1313
find_package(fmt REQUIRED)
1414
find_package(Boost REQUIRED COMPONENTS locale)
1515

16-
file(GLOB sources CONFIGURE_DEPENDS "*.cpp")
16+
file(GLOB sources CONFIGURE_DEPENDS "examples/*.cpp")
1717
foreach(source IN LISTS sources)
1818
get_filename_component(name ${source} NAME_WE)
1919
add_executable(${name} ${source})

README.md

+19-33
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,31 @@
55
> [!NOTE]
66
> 敢承诺:土木老哥也能看懂!
77
8-
## 下载 PDF
8+
## 在哪里可以看?
99

10-
[点击开始在线阅读](https://142857.red/files/cppguidebook.pdf)
10+
无需下载,[点击开始在线阅读](https://parallel101.github.io/cppguidebook)
11+
12+
> [!TIP]
13+
> GitHub Pages 是实时更新的,每当小彭老师推送了新章节,网页都会自动更新哦。
1114
1215
也可以前往 [GitHub Release 页面](https://github.com/parallel101/cppguidebook/releases) 下载 PDF 文件。
1316

1417
> [!NOTE]
15-
> 感谢 [Derived Cat](https://github.com/hooyuser) 大佬提供智能脚本!每当小彭老师推送了修改后,Release 页面和小水管服务器上的 PDF 文件都会自动更新。只要看到小彭老师提交新 commit,你就可以随时重新下载最新版。(如果看到没有变化,是浏览器缓存导致的,建议电脑端按 F5 或者手机屏幕下拉刷新一下)
16-
17-
## 你也可以参与编写的开源小册
18+
> 要追番的话,点一下 GitHub 右上角的 `Watch` 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一峰电子邮件,提醒你小彭老师更新了。
1819
19-
本书完全开源,源文件为 [`cppguidebook.typ`](cppguidebook.typ)
20+
如果你在阅读过程中遇到任何问题,可以在 [GitHub Issues](https://github.com/parallel101/cppguidebook/issues) 中提出,小彭老师会尽力解答
2021

21-
如果发现书写问题,或者你有想加入的新章节,有关于 C++ 新想法,新技巧分享给大家,可以提交 [Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) 来帮助小彭老师一起写书。合并后,GitHub 的机器人讲自动重新编译出 PDF。
22-
23-
添加新章节,可以从下面的“大纲 / Roadmap”中挑选,认领其中的一个章节,开始编写。也可以选择一个大纲里没有,但你认为很重要的方面来写。
22+
## 你也可以参与编写的开源小册
2423

25-
# 大纲 / Roadmap
24+
本书完全开源,Markdown 源文件在 [`docs/`](docs/) 文件夹下。
2625

27-
- 前言 (完成)
28-
- 开发环境与平台选择 (小彭老师施工中)
29-
- 你好,世界 (小彭老师施工中)
30-
- 变量与类型 (待认领)
31-
- 认识标准库 (待认领)
32-
- 自定义函数 (待认领)
33-
- 自定义类型 (待认领)
34-
- 标准库容器 (待认领)
35-
- 成员函数 (待认领)
36-
- 我们需要多态 (待认领)
37-
- 自定义模板 (待认领)
38-
- TODO: 更多章节
26+
如果发现书写问题,或者你有想加入的新章节,有关于 C++ 新想法,新技巧分享给大家,可以提交 [Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) 来帮助小彭老师一起写书。合并后,GitHub 的机器人将自动重新编译和部署网页。
3927

4028
## 赞助名单
4129

42-
感谢以下小彭友的赞助
30+
小彭大典的持续编写离不开以下小彭友的赞助
4331

44-
[![Thanks list](pic/thanks.png)](https://afdian.net/a/archibate)
32+
[![Thanks list](docs/img/thanks.png)](https://afdian.net/a/archibate)
4533

4634
> [!NOTE]
4735
> 小彭老师的大典是免费下载的,不用赞助也可以查看哦。
@@ -60,20 +48,18 @@
6048

6149
> 救命……爱发电似乎关停了!?小彭老师赶紧贴出支付宝收款码作为替代……
6250
63-
<img src="misc/zfb-qrcode.jpg" alt="misc/zfb-qrcode.jpg" width="400px"/>
51+
<img src="docs/img/zfb-qrcode.jpg" alt="docs/img/zfb-qrcode.jpg" width="400px"/>
6452

6553
> [!TIP]
6654
> 如果你也处于失业状态,就不用勉强赞助了……也可以先给小彭老师点一颗⭐Star⭐表示心意。
6755
68-
## Typst 真好用,家人们
69-
70-
本书使用 [Typst 语言](https://github.com/typst/typst) 书写,类似于 LaTeX 或 Markdown。和 Markdown 相比,Typst 的排版功能更加丰富。和 LaTeX 相比,Typst 更加轻量级,语法简单明了。最重要的是,Typst 支持宏编程,可以在文本中书写代码,实现批量生成结构化的文本。
56+
## Mkdocs 真好用,家人们
7157

72-
![Typst](https://user-images.githubusercontent.com/17899797/228031796-ced0e452-fcee-4ae9-92da-b9287764ff25.png)
58+
本书使用 [Mkdocs](https://www.mkdocs.org/) 构建,是一种基于 Markdown 的静态网站生成器,可以把一堆 Markdown 文件编译成一个网站,非常适合用于写书。
7359

74-
Typst 语言书写的 `.typ` 源文件编译后,得到可供阅读的 `.pdf` 文件
60+
克隆本仓库后,可以用 `mkdocs build` 命令编译生成 `site` 文件夹,打开其中的 `site/index.html` 就可以开始看了。也可以用 `mkdocs serve` 命令,在 `http://127.0.0.1:8000` 开启实时预览服务,每当你修改 `.md` 文件时都会自动刷新
7561

76-
克隆本仓库后,可以用 `typst compile cppguidebook.typ` 命令编译生成 `cppguidebook.pdf` 文件,也可以用 [`typst-preview`](https://github.com/Enter-tainer/typst-preview`) 等工具,一边修改源文件,一边实时预览效果
62+
每当小彭老师提交新的代码,GitHub 的机器人就会自动调用 Mkdocs 重新编译和部署网页。这样,小彭老师只需要关心写作本书,不用再操心排版、发布等问题
7763

7864
> 以下是第一章节的内容预览,要查看全文,请前往 Release 页面下载完整 PDF 文件。
7965
@@ -83,7 +69,7 @@ Typst 语言书写的 `.typ` 源文件编译后,得到可供阅读的 `.pdf`
8369

8470
用电脑看的话,可以按 `WIN + ←`,把本书的浏览器窗口放在屏幕左侧,右侧是你的 IDE。一边看一边自己动手做实验。
8571

86-
![split view](pic/slide.jpg)
72+
![split view](docs/img/slide.jpg)
8773

8874
> 请坐和放宽。
8975
@@ -120,4 +106,4 @@ Typst 语言书写的 `.typ` 源文件编译后,得到可供阅读的 `.pdf`
120106
121107
# 开发环境与平台选择
122108

123-
[>> 继续阅读剩余章节](https://142857.red/files/cppguidebook.pdf)
109+
[>> 继续阅读剩余章节](https://parallel101.github.io/cppguidebook)

0 commit comments

Comments
 (0)