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())