From 71b9193a6d77186c986ff152a8364c68f6998041 Mon Sep 17 00:00:00 2001 From: kp54 Date: Thu, 28 Aug 2025 01:54:41 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF=E3=83=88?= =?UTF-8?q?=E3=83=AA=E6=A7=8B=E9=80=A0=E3=81=AE=E6=A4=9C=E6=9F=BB=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 2 +- test-directory-structure.py | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 test-directory-structure.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 28272a1e..ed62b3fe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,6 +35,7 @@ jobs: # SKIP_BUILD=true bundle exec rake test # NOTE: サイトが仕上がったら、上記テストを走らせると自動検知できる。 # ただ初期は自動検知の通知が多すぎるので手動で実行するのが吉。 + python test-directory-structure.py # Deploy job is triggered only pushed to main branch && CI passed deploy: @@ -86,4 +87,3 @@ jobs: with: personal_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./_site - diff --git a/test-directory-structure.py b/test-directory-structure.py new file mode 100755 index 00000000..63eb2753 --- /dev/null +++ b/test-directory-structure.py @@ -0,0 +1,42 @@ +#!/usr/bin/python +from pathlib import Path + +""" +すべてのページが index.html として生成されているか検査するスクリプト + +foobar/baz/index.html +-> /foobar/baz/ と /foobar/baz の双方がルーティングできる + +foobar/baz.html +-> /foobar/baz/ がルーティングできない +""" + + +def main() -> int: + allowed_names = ["index.html", "404.html"] + errors = list[str]() + + for cwd, _dirs, files in Path("_site").walk(): + for file in files: + if not file.endswith(".html"): + continue + + if file in allowed_names: + continue + + path = cwd.joinpath(file).as_posix() + errors.append(path) + + if 0 < len(errors): + print("index.html でない HTML ファイルが生成されました:") + for i in errors: + print(f"- {i}") + return 1 + + return 0 + + +if __name__ == "__main__": + import sys + + sys.exit(main())