Skip to content

Commit 24f9dd5

Browse files
committed
website,book: fix link rewriting that mangled external URLs
filter.py rewrote cross-chapter links with the loose regex (./)(.*?)(.md), whose unescaped dots matched any ':/ … md' span — so a chapter line with an external URL like '#cmdoption-…' got corrupted into 'https..//…' on the built site. Anchor the rewrite to the ](./NN-name.md) link syntax with a simple filename so external URLs are never touched; chapter cross-links and #anchors still resolve. Also repoint the preface Code/Exercises links at the GitHub tree (they were relative dir links that 404 on the static site — no directory index — and the English one had an 'exercise' typo); GitHub URLs work on the site, on GitHub, and in the PDF.
1 parent bf50489 commit 24f9dd5

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

book/en-us/00-preface.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ Also, the author would like to encourage that readers should be able to use mode
5151

5252
## Code
5353

54-
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.
54+
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.
5555

5656
## Exercises
5757

58-
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.
58+
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.
5959

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

book/zh-cn/00-preface.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ C++17 则是近三年依赖 C++ 社区一致推进的方向,也指出了 **现
4848

4949
## 相关代码
5050

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

5353
## 随书习题
5454

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

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

website/filter.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@
2929
if any(keyword in line for keyword in ignores):
3030
continue
3131
else:
32-
output_file.write(re.sub(r'(./)(.*?)(.md)', r'../\2/index.html', line))
32+
# Rewrite relative cross-chapter links `](./NN-name.md)`
33+
# (optionally with a #anchor) to the website's
34+
# `](../NN-name/index.html)` form. The pattern is anchored
35+
# to the `](./…md)` link syntax with a simple filename so it
36+
# cannot corrupt external URLs — the previous loose regex
37+
# `(./)(.*?)(.md)` matched any `:/ … md` span and mangled
38+
# links like `#cmdoption-…` into `https..//…`.
39+
output_file.write(re.sub(r'\]\(\./([\w-]+)\.md(#[^)]*)?\)', r'](../\1/index.html\2)', line))

0 commit comments

Comments
 (0)