Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6629382
Remove DigitalOcean sponsorship blocks
changkun Jun 7, 2026
66b1a38
website: show one language at a time on the homepage
changkun Jun 7, 2026
add210d
code: sync structured-binding example with rewritten book
changkun Jun 7, 2026
78d2505
website: rebrand version strings to C++11 to C++26
changkun Jun 7, 2026
f6faf02
website: hygiene pass on the theme
changkun Jun 7, 2026
74755a1
website: upgrade Hexo toolchain to patch npm vulnerabilities
changkun Jun 7, 2026
a88a18a
docker: pin build-env base to node:22-bookworm
changkun Jun 7, 2026
726fd10
website: make landing single-language with a link switcher
changkun Jun 21, 2026
e5b9509
website: localize page title and de-underline the landing switcher
changkun Jun 21, 2026
490a6ac
website: patch dompurify and form-data via npm audit fix
changkun Jun 21, 2026
dab1a01
ci: rebuild website workflow without the texlive Docker image
changkun Jun 21, 2026
845f01f
website: auto-route root by browser language; harden landing flag
changkun Jun 21, 2026
79f8a66
website: make the About section properly bilingual
changkun Jun 21, 2026
f0c133d
website: language switch goes to the same page, not the preface
changkun Jun 21, 2026
4151837
website: fix English book sidebar heading (was 'Book-en-us')
changkun Jun 21, 2026
ee052b3
website: drop the duplicate landing language switch
changkun Jun 21, 2026
39c975e
website: real SEO/i18n head — hreflang, OG/Twitter, canonical, favicon
changkun Jun 21, 2026
dd5e8bd
website: shell cleanup — dead config, alt text, stray tags, vestigial…
changkun Jun 21, 2026
bf50489
website: stop emitting the stray /2026 dated post
changkun Jun 21, 2026
24f9dd5
website,book: fix link rewriting that mangled external URLs
changkun Jun 21, 2026
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,38 @@ jobs:
build:
name: Website
runs-on: ubuntu-latest
timeout-minutes: 60
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: build
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '22'
cache: npm
cache-dependency-path: website/package-lock.json

# The Hexo site only needs Node and Python 3 (preinstalled on the
# runner). The old pipeline shelled out to a hand-maintained 3.4 GB
# texlive Docker image just to also build the PDF/epub; that image
# silently drifted to a 2019 Node and broke the build. We deploy the
# website only here. The PDF/epub already on the server are left in
# place (scp overwrites, never deletes), so their download links keep
# working until those artifacts are rebuilt separately.
- name: Install website dependencies
run: npm ci --prefix website

- name: Build website
run: cd website && make

- name: Deploy to server
env:
USER: ${{ secrets.SERVER_USER }}
TARGET: ${{ secrets.SERVER_PATH }}
KEY: ${{ secrets.SERVER_KEY }}
DOMAIN: ${{ secrets.SERVER_DOMAIN }}
run: |
make build
mkdir ~/.ssh
mkdir -p ~/.ssh
echo "$KEY" | tr -d '\r' > ~/.ssh/id_ed25519
chmod 400 ~/.ssh/id_ed25519
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh-keyscan -H $DOMAIN >> ~/.ssh/known_hosts
scp -r website/public/modern-cpp/* $USER@$DOMAIN:$TARGET
ssh-keyscan -H "$DOMAIN" >> ~/.ssh/known_hosts
scp -i ~/.ssh/id_ed25519 -r website/public/modern-cpp/* "$USER@$DOMAIN:$TARGET"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ website/src/modern-cpp/zh-cn/*
website/src/modern-cpp/en-us/*
website/src/modern-cpp/exercises
website/src/modern-cpp/code
website/src/modern-cpp/about/donate.md
website/src/modern-cpp/assets/alipay.jpg
website/src/modern-cpp/assets/cover-2nd-en.png
website/src/modern-cpp/assets/cover-2nd.png
Expand Down
9 changes: 1 addition & 8 deletions README-zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## 本书目的

本书号称『高速上手』,从内容上对二十一世纪二十年代之前产生 C++ 的相关特性做了非常相对全面的介绍,读者可以自行根据下面的目录选取感兴趣的内容进行学习,快速熟悉需要了解的内容。这些特性并不需要全部掌握,只需针对自己的使用需求和特定的应用场景,学习、查阅最适合自己的新特性即可。
本书号称『高速上手』,从内容上对现代 C++(从 C++11 到 C++26)的相关特性做了相对全面的介绍,读者可以自行根据下面的目录选取感兴趣的内容进行学习,快速熟悉需要了解的内容。这些特性并不需要全部掌握,只需针对自己的使用需求和特定的应用场景,学习、查阅最适合自己的新特性即可。

同时,本书在介绍这些特性的过程中,尽可能简单明了的介绍了这些特性产生的历史背景和技术需求,这为理解这些特性、运用这些特性提供了很大的帮助。

Expand Down Expand Up @@ -50,13 +50,6 @@ $ 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)。

<p>本项目还由以下产品提供赞助支持:</p>
<p>
<a href="https://www.digitalocean.com/?refcode=834a3bbc951b&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=CopyPaste">
<img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg" width="201px">
</a>
</p>

## 许可

<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="知识共享许可协议" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/80x15.png" /></a>
Expand Down
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![](https://img.shields.io/github/actions/workflow/status/changkun/modern-cpp-tutorial/website.yml?branch=master&style=flat-square)](https://github.com/changkun/modern-cpp-tutorial/actions/workflows/website.yml) [![](https://img.shields.io/badge/language-English-blue.svg?style=flat-square)](./README.md) [![](https://img.shields.io/badge/language-简体中文-red.svg?style=flat-square)](./README-zh-cn.md) [![](https://img.shields.io/badge/€-donate-ff69b4.svg?style=flat-square)](./assets/donate.md)
## Purpose

The book claims to be "On the Fly". Its intent is to provide a comprehensive introduction to the relevant features regarding modern C++ (before 2020s).
The book claims to be "On the Fly". Its intent is to provide a comprehensive introduction to the relevant features of modern C++ (from C++11 through C++26).
Readers can choose interesting content according to the following table of content to learn and quickly familiarize the new features you would like to learn.
Readers should be aware that not all of these features are required. Instead, it should be learned when you really need it.

Expand Down Expand Up @@ -56,13 +56,6 @@ The author has limited time and language skills. If readers find any mistakes in

The author is grateful to all contributors, including but not limited to [Contributors](https://github.com/changkun/modern-cpp-tutorial/graphs/contributors).

<p>This project is also supported by:</p>
<p>
<a href="https://www.digitalocean.com/?refcode=834a3bbc951b&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=CopyPaste">
<img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg" width="201px">
</a>
</p>

## Licenses

<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" /></a><br />This work was written by [Ou Changkun](https://changkun.de) and licensed under a <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License</a>. The code of this repository is open sourced under the [MIT license](./LICENSE).
4 changes: 2 additions & 2 deletions book/en-us/00-preface.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ Also, the author would like to encourage that readers should be able to use mode

## Code

Each chapter of this book has a lot of code. If you encounter problems when writing your own code with the introductory features of the book, you might as well read the source code attached to the book. You can find the book [here](../../code). All the code is organized by chapter, the folder name is the chapter number.
Each chapter of this book has a lot of code. If you encounter problems when writing your own code with the introductory features of the book, you might as well read the source code attached to the book. You can find the book [here](https://github.com/changkun/modern-cpp-tutorial/tree/master/code). All the code is organized by chapter, the folder name is the chapter number.

## Exercises

There are few exercises At the end of each chapter of the book. It is for testing whether you can use the knowledge points in the current chapter. You can find the possible answer to the problem from [here](../../exercise). The folder name is the chapter number.
There are few exercises At the end of each chapter of the book. It is for testing whether you can use the knowledge points in the current chapter. You can find the possible answer to the problem from [here](https://github.com/changkun/modern-cpp-tutorial/tree/master/exercises). The folder name is the chapter number.

[Table of Content](./toc.md) | [Next Chapter: Towards Modern C++](./01-intro.md)

Expand Down
2 changes: 1 addition & 1 deletion book/en-us/09-others.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Chapter 09: Minor Features
title: "Chapter 09: Minor Features"
type: book-en-us
order: 9
---
Expand Down
4 changes: 2 additions & 2 deletions book/zh-cn/00-preface.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ C++17 则是近三年依赖 C++ 社区一致推进的方向,也指出了 **现

## 相关代码

本书每章中都出现了大量的代码,如果你在跟随本书介绍特性的思路编写自己的代码遇到问题时,不妨读一读随书附上的源码,你可以在[这里](../../code)中找到书中介绍过的全部的源码,所有代码按章节组织,文件夹名称为章节序号。
本书每章中都出现了��量的代码,如果你在跟随本书介绍特性的思路编写自己的代码遇到问题时,不妨读一读随书附上的源码,你可以在[这里](https://github.com/changkun/modern-cpp-tutorial/tree/master/code)中找到书中介绍过的全部的源码,所有代码按章节组织,文件夹名称为章节序号。

## 随书习题

本书每章最后还加入了少量难度极小的习题,仅用于检验你是否能混合运用当前章节中的知识点。你可以在[这里](../../exercises)找到习题的答案,文件夹名称为章节序号。
本书每章最后还加入了少量难度极小的习题,仅用于检验你是否能混合运用当前章节中的知识点。你可以在[这里](https://github.com/changkun/modern-cpp-tutorial/tree/master/exercises)找到习题的答案,文件夹名称为章节序号。

[返回目录](./toc.md) | [下一章 迈向现代 C++](./01-intro.md)

Expand Down
9 changes: 9 additions & 0 deletions code/2/2.05.structured.binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
#include <iostream>
#include <tuple>
#include <string>
#include <map>

std::tuple<int, double, std::string> f() {
return std::make_tuple(1, 2.3, "456");
}

int main() {
// Unpack a tuple straight into named variables.
auto [x, y, z] = f();
std::cout << x << ", " << y << ", " << z << std::endl;

// Bind each key/value pair while iterating an associative container,
// instead of writing it->first / it->second.
std::map<std::string, int> scores{{"alice", 90}, {"bob", 80}};
for (const auto& [name, score] : scores) {
std::cout << name << ": " << score << '\n';
}
return 0;
}
5 changes: 4 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM node:latest
# Pin to a concrete, current Node LTS. The toolchain (Hexo 8) requires
# Node >= 20.19; an unpinned `node:latest` silently drifts, and the build-env
# image was last rebuilt in 2020 (Node 15), which Hexo 8 will not run on.
FROM node:22-bookworm

LABEL "maintainer"="Changkun Ou <hi[at]changkun.de>"
LABEL "repository"="https://github.com/changkun/modern-cpp-tutorial"
Expand Down
3 changes: 1 addition & 2 deletions website/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ all: clean
cp ../assets/cover-2nd-en-logo.png ./src/modern-cpp/assets/cover-2nd-en-logo.png
cp ../assets/alipay.jpg ./src/modern-cpp/assets/alipay.jpg
cp ../assets/wechat.jpg ./src/modern-cpp/assets/wechat.jpg
cp ../assets/donate.md ./src/modern-cpp/about/
cp -r ../assets/figures ./src/modern-cpp/assets/figures
cp -r ../exercises ./src/modern-cpp/
cp -r ../code ./src/modern-cpp/
npx hexo generate
mv public/index.html public/modern-cpp/index.html
rm -rf public/_generated_home_stub
s: all
node_modules/serve/bin/serve.js ./public
clean:
Expand All @@ -23,7 +23,6 @@ clean:
./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/code \
./src/modern-cpp/exercises \
public db.json src/modern-cpp/zh-cn src/modern-cpp/en-us
8 changes: 6 additions & 2 deletions website/_config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Site Configuration
title: "现代 C++ 教程: 高速上手 C++11 到 C++26"
subtitle: C++11 to C++26 On the Fly
description: "欧长坤"
description: "现代 C++ 教程:高速上手 C++11 到 C++26 | Modern C++ Tutorial: C++11 to C++26 On the Fly"
author: 欧长坤
email: hi[at]changkun.de
language: zh-CN
Expand Down Expand Up @@ -68,4 +68,8 @@ marked:
tables: true
breaks: false
smartLists: true
smartypants: false
smartypants: false
# hexo-renderer-marked 6+ prepends the site root to relative image paths
# by default, which turns the book's ../../assets/... figures into a broken
# /../../assets/... absolute path. Keep the original relative paths.
prependRoot: false
9 changes: 8 additions & 1 deletion website/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@
if any(keyword in line for keyword in ignores):
continue
else:
output_file.write(re.sub(r'(./)(.*?)(.md)', r'../\2/index.html', line))
# Rewrite relative cross-chapter links `](./NN-name.md)`
# (optionally with a #anchor) to the website's
# `](../NN-name/index.html)` form. The pattern is anchored
# to the `](./…md)` link syntax with a simple filename so it
# cannot corrupt external URLs — the previous loose regex
# `(./)(.*?)(.md)` matched any `:/ … md` span and mangled
# links like `#cmdoption-…` into `https..//…`.
output_file.write(re.sub(r'\]\(\./([\w-]+)\.md(#[^)]*)?\)', r'](../\1/index.html\2)', line))
Loading