Skip to content

Commit 8287cbc

Browse files
committed
どこからも参照されていないページ (リンクミスと思われる) のチェックを追加
1 parent e5eb048 commit 8287cbc

7 files changed

Lines changed: 77 additions & 2 deletions

File tree

.github/workflows/script/link_check.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,34 @@ def add_link(origin_link: str):
156156
for m in re.finditer(r'[\*-] (.*?)\[link (.*?)\]', line):
157157
add_link(m.group(2))
158158

159+
# Markdownの参照スタイルリンク定義 (`[label]: url`) も参照として扱う。
160+
# 例: `[max_size]: ./scoped_allocator_adaptor/max_size.md`
161+
# (脚注 `[^label]:` は除外)
162+
for line in text.split("\n"):
163+
m = re.match(r'\s{0,3}\[([^\^\]][^\]]*)\]:\s+(\S+)', line)
164+
if m:
165+
add_link(m.group(2))
166+
159167
return inner_links, outer_links
160168

169+
# --- 孤立ページ (lonely page) チェック用 ---
170+
# 「孤立ページ」とは、どのページからもリンクされていない .md のこと。
171+
# reference/ 配下の .md は、リンク先パスをtypoすると「ページは存在するのに
172+
# どこからもリンクされない」孤立ページになる。そうしたリンクミスを検出するため、
173+
# 内部リンクチェックの一部として、reference/ 配下の全 .md が最低1箇所から
174+
# 参照されているかを確認する。
175+
176+
# どこからもリンクされていなくてよいページ (意図的に他ページから参照されないもの)。
177+
# ここに載せるのは「意図的にスタンドアロンなページ」だけにすること。
178+
# リンクミスで孤立したページは、ここに登録せず親ページ側のリンクを修正すること。
179+
LONELY_PAGE_ALLOWLIST = {
180+
"reference.md", # リファレンスのトップ索引 (index.md からのリンクはグローバルナビ扱い)
181+
"reference/node_handle.md", # node_handleを説明する説明用カテゴリ概要ページ
182+
# C++26の説明専用ヘルパー。Senderアルゴリズムの仕様定義で用いられるが、
183+
# 現状どのアルゴリズムページの仕様記述からも参照されていない。
184+
"reference/execution/execution/query-with-default.md",
185+
}
186+
161187
def check(check_inner_link: bool, check_outer_link: bool, url: str) -> bool:
162188
if not check_inner_link and not check_outer_link:
163189
print("unchecked", file=sys.stderr)
@@ -166,6 +192,7 @@ def check(check_inner_link: bool, check_outer_link: bool, url: str) -> bool:
166192
found_error = False
167193
current_dir = os.getcwd()
168194
outer_link_dict = dict()
195+
referenced = set() # 内部リンクの参照先 (repo相対パスに正規化)。孤立ページ検出用
169196
if len(url) <= 0:
170197
path_list = [(p, False) for p in glob.glob("**/*.md", recursive=True)]
171198
path_list.append(("GLOBAL_QUALIFY_LIST.txt", True))
@@ -198,6 +225,25 @@ def check(check_inner_link: bool, check_outer_link: bool, url: str) -> bool:
198225
if not os.path.exists(rel_link):
199226
print("{} href {} not found.".format(p, link), file=sys.stderr)
200227
found_error = True
228+
# 孤立ページ検出用に、.md への参照先をrepo相対で記録する
229+
if link.endswith(".md"):
230+
if link.startswith("/"):
231+
referenced.add(os.path.normpath(link.lstrip("/")))
232+
else:
233+
referenced.add(os.path.normpath(os.path.join(dirname, link)))
234+
235+
# 孤立ページ (lonely page) チェック: reference/ 配下に、どのページからも
236+
# リンクされていない .md ファイルが無いか確認する (リンク先パスのtypo等で発生する)。
237+
if check_inner_link:
238+
for p in sorted(glob.glob("reference/**/*.md", recursive=True)):
239+
norm = os.path.normpath(p)
240+
if norm in LONELY_PAGE_ALLOWLIST:
241+
continue
242+
if norm not in referenced:
243+
print("{} is a lonely page (どこからもリンクされていない孤立ページです。"
244+
"リンク先のtypo等が原因の可能性があります)".format(p),
245+
file=sys.stderr)
246+
found_error = True
201247

202248
if check_outer_link:
203249
# GitHub-hosted runnerはIPv6アウトバウンド経路を持たない

reference/chrono/year_month.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace std::chrono {
5757
5858
| 名前 | 説明 | 対応バージョン |
5959
|------|------|----------------|
60-
| [`operator/`](month_day/op_append.md) | カレンダー要素同士をつなぎ合わせる | C++20 |
60+
| [`operator/`](year_month/op_append.md) | カレンダー要素同士をつなぎ合わせる | C++20 |
6161
6262
6363
### 算術演算

reference/execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
| 名前 | 説明 | 対応バージョン |
2020
|------|------|----------------|
2121
| [`execution`](execution/execution.md) | 実行制御ライブラリの名前空間 (namespace) | C++26 |
22-
| [`this_thread`](execution/execution.md) | 実行制御ライブラリ/Senderコンシューマの名前空間 (namespace) | C++26 |
22+
| [`this_thread`](execution/this_thread.md) | 実行制御ライブラリ/Senderコンシューマの名前空間 (namespace) | C++26 |
2323

2424

2525
## バージョン

reference/execution/execution/counting_scope.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ namespace std::execution {
3232
| [`join`](counting_scope/join.md) | 非同期スコープを合流する[Sender](sender.md)取得 | C++26 |
3333
| [`request_stop`](counting_scope/request_stop.md) | 停止要求を作成する | C++26 |
3434
35+
### 説明専用メンバ関数
36+
37+
| 名前 | 説明 | 対応バージョン |
38+
|------|------|----------------|
39+
| [`try-associate`](counting_scope/try-associate.md) | 関連付けを試行 | C++26 |
40+
| [`disassociate`](counting_scope/disassociate.md) | 関連付けを解除 | C++26 |
41+
| [`start-join-sender`](counting_scope/start-join-sender.md) | 合流[Sender](sender.md)を開始 | C++26 |
42+
3543
## メンバ型
3644
3745
| 名前 | 説明 | 対応バージョン |

reference/execution/execution/let_value.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ struct let-state {
238238
```
239239
* connect_result_t[link connect_result_t.md]
240240
* connect[link connect.md]
241+
* emplace-from[link emplace-from.md]
241242
* start[link start.md]
242243
* receiver_tag[link receiver.md]
243244
* execution::set_value[link set_value.md]

reference/random/piecewise_constant_distribution.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ namespace std {
6060
| `param_type` | 分布パラメータの型。未規定。 | C++11 |
6161
6262
63+
## 非メンバ関数
64+
65+
| 名前 | 説明 | 対応バージョン |
66+
|------------------------------------------------------------------|----------------------|-------|
67+
| [`operator==`](piecewise_constant_distribution/op_equal.md) | 等値比較 | C++11 |
68+
| [`operator!=`](piecewise_constant_distribution/op_not_equal.md) | 非等値比較 | C++11 |
69+
| [`operator<<`](piecewise_constant_distribution/op_ostream.md) | ストリームへの出力 | C++11 |
70+
| [`operator>>`](piecewise_constant_distribution/op_istream.md) | ストリームからの入力 | C++11 |
71+
72+
6373
## 例
6474
```cpp example
6575
#include <fstream>

reference/random/piecewise_linear_distribution.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ namespace std {
6060
| `param_type` | 分布パラメータの型。未規定。 | C++11 |
6161
6262
63+
## 非メンバ関数
64+
65+
| 名前 | 説明 | 対応バージョン |
66+
|--------------------------------------------------------------|----------------------|-------|
67+
| [`operator==`](piecewise_linear_distribution/op_equal.md) | 等値比較 | C++11 |
68+
| [`operator!=`](piecewise_linear_distribution/op_not_equal.md) | 非等値比較 | C++11 |
69+
| [`operator<<`](piecewise_linear_distribution/op_ostream.md) | ストリームへの出力 | C++11 |
70+
| [`operator>>`](piecewise_linear_distribution/op_istream.md) | ストリームからの入力 | C++11 |
71+
72+
6373
## 例
6474
```cpp example
6575
#include <fstream>

0 commit comments

Comments
 (0)