Add index.html and maintenance scripts#275
Conversation
|
Important Review skippedToo many files! This PR contains 169 files, which is 19 over the limit of 150. You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughHTMLドキュメントのインデックス生成ワークフローを追加。 Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer
participant Git as Git (commit)
participant Hook as pre-commit hook
participant Sh as update_index.sh
participant Py as generate_index.py
participant FS as Filesystem (index.html)
Dev->>Git: git commit
Git->>Hook: run pre-commit hook
Hook->>Sh: execute ./update_index.sh
Sh->>Py: python3 generate_index.py
Py->>FS: scan HTML files, generate index.html
Py-->>Sh: success
Sh->>Hook: exit (index.html updated)
Hook->>Git: stage index.html and continue commit
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 10
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@generate_index.py`:
- Around line 10-16: Remove the unnecessary explicit mode argument in the file
open call (open(filepath, encoding='utf-8') instead of open(filepath, 'r',
encoding='utf-8')) and narrow the broad except Exception to only the expected
exceptions (catch OSError and UnicodeDecodeError) around the file read/parse
block that uses open(filepath, ...), content = f.read(), re.search(...), and
match.group(1) so you don't accidentally swallow critical system errors; keep
the existing error print but only trigger it for those specific exception types.
- Line 57: The timestamp uses naive local time via current_time =
datetime.datetime.now().strftime(...); change it to use UTC by calling
datetime.datetime.now(datetime.timezone.utc).strftime(...) (or equivalent) so
generated timestamps are consistent across CI; also ensure datetime.timezone is
available/imported or reference datetime as needed so the code compiles (update
the import/use in generate_index.py around the current_time assignment).
- Around line 1-197: The module-level functions should be converted into a
class-based API per guidelines: create class Solution and move
get_html_title(filepath) -> str into a method def get_html_title(self, filepath:
str) -> str and move generate_index() -> None into def generate_index(self) ->
None (or rename to generate(self) -> None) while preserving all logic and
referenced names (get_html_title, generate_index, structure, index_file); add
appropriate type annotations for variables and return types, update calls (the
if __name__ == "__main__" block) to instantiate Solution() and call the method,
and ensure imports and error handling remain unchanged.
- Around line 153-158: Replace the current HTML-escaping of the URL path with
proper percent-encoding: use urllib.parse.quote on the computed url_path
(preserving slashes with safe='/') before inserting into the href, and still
apply html.escape to the visible title/path if needed; update the block that
builds html_content (where url_path is defined and used) to call quote(url_path,
safe='/') for href generation instead of html.escape so spaces and other
URL-reserved characters become percent-encoded while keeping '/' intact.
- Around line 59-131: The HTML/CSS block assigned to html_content is a static
template but is using an f-string (f"""...""") which triggers Ruff F541; change
the assignment to a plain triple-quoted string ("""...""") so literal braces ({{
and }}) remain as-is, and reserve f-strings only where you actually interpolate
variables into html_content or build the template by concatenating/formatting
specific insertion points; update the html_content definition (the variable name
html_content and its current f"""...""" declaration) to use a regular string or
split into a static template plus an f-string for the dynamic pieces.
- Around line 7-17: get_html_title currently returns raw HTML title text which
can contain entities (e.g., "&") and causes double-encoding when later
passed to escape(); update get_html_title to decode HTML entities before
returning by applying html.unescape() to the matched title (and strip the
result) so it returns plain text; ensure the html module is imported if not
already.
In `@INDEX_MAINTENANCE.md`:
- Around line 46-50: The setup docs miss making the wrapper script executable:
before enabling the pre-commit hook that calls ./update_index.sh, add a step to
mark update_index.sh executable (run chmod +x update_index.sh) so the hook can
invoke it; update the INDEX_MAINTENANCE.md steps around the pre-commit
instruction to include this command and a short note that the wrapper must be
executable.
- Around line 35-44: The pre-commit hook unconditionally runs git add index.html
even if ./update_index.sh failed and uses mismatched shebangs; change the hook
to use a single consistent shell (make both shebangs #!/bin/bash or
#!/usr/bin/env bash), run ./update_index.sh and immediately fail the hook if it
exits non‑zero (e.g. propagate its exit status), and only run git add index.html
when index.html was actually modified (check its exit status via git diff or git
status for index.html before adding). Ensure update_index.sh is executable and
its shebang matches the hook.
In `@index.html`:
- Around line 1-737: index.html is a generated artifact and can become stale
when developers lack the pre-commit hook; update project documentation
(README.md) to document required pre-commit hook installation and add a CI check
that validates index.html freshness (e.g. run the same generator and diff
against committed index.html) so failures surface in PRs; reference index.html
and the openCategory() script when describing the generator output and add a
note on where to find/install the hook and the generator command, or
alternatively add a CI workflow step to regenerate and fail the build if the
committed file differs.
In `@update_index.sh`:
- Around line 1-4: このシェルはエラー耐性がなく python3 generate_index.py
の失敗を無視するため、先頭にシェルの堅牢化(set -euo pipefail)を追加してコマンド失敗で即終了するようにし、さらに
generate_index.py が root_dir = "." を使っている点を踏まえ update_index.sh
内で実行前に適切な作業ディレクトリへ移動する(スクリプトの位置またはリポジトリルートを基準にする)処理を追加して、必ず正しいルートで python3
generate_index.py を実行するようにしてください。
---
Duplicate comments:
In `@index.html`:
- Line 506: The index contains double-encoded HTML entities (e.g., "&")
because get_html_title() in generate_index.py is encoding titles twice; update
get_html_title() to stop double-encoding (ensure it returns already-escaped or
raw text consistently, using one HTML-escape pass only or skipping escape if
upstream is already escaped), then re-run the generator to regenerate index.html
so links like the LeetCode 87 entry show correct entities.
| #!/bin/bash | ||
|
|
||
| # Wrapper script to update the index.html file | ||
| python3 generate_index.py |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
set -euo pipefail が未設定のためエラーが無視される
python3 generate_index.py が失敗した場合(構文エラー、権限エラーなど)、シェルスクリプトは終了コード 0 で完了します。INDEX_MAINTENANCE.md のプリコミットフックから呼び出された場合、壊れたインデックス更新を検知できないまま git add index.html が実行されてしまいます。
また、generate_index.py はスクリプトのディレクトリを基準にせず root_dir = "." を使用するため、どちらのスクリプトもリポジトリルートから実行することを前提としています。
♻️ 修正提案
#!/bin/bash
+set -euo pipefail
+
+# スクリプト自身のディレクトリへ移動してから実行する
+cd "$(dirname "$0")"
# Wrapper script to update the index.html file
python3 generate_index.py📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| #!/bin/bash | |
| # Wrapper script to update the index.html file | |
| python3 generate_index.py | |
| #!/bin/bash | |
| set -euo pipefail | |
| # スクリプト自身のディレクトリへ移動してから実行する | |
| cd "$(dirname "$0")" | |
| # Wrapper script to update the index.html file | |
| python3 generate_index.py |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@update_index.sh` around lines 1 - 4, このシェルはエラー耐性がなく python3 generate_index.py
の失敗を無視するため、先頭にシェルの堅牢化(set -euo pipefail)を追加してコマンド失敗で即終了するようにし、さらに
generate_index.py が root_dir = "." を使っている点を踏まえ update_index.sh
内で実行前に適切な作業ディレクトリへ移動する(スクリプトの位置またはリポジトリルートを基準にする)処理を追加して、必ず正しいルートで python3
generate_index.py を実行するようにしてください。
✅ Deploy Preview for algorithm-datastructures-math-studies ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@netlify.toml`:
- Line 3: netlify.toml currently sets publish = "." which exposes the entire
repository (including generate_index.py, update_index.sh, INDEX_MAINTENANCE.md,
source files and netlify.toml); change the deploy to use a dedicated publish
directory (e.g., move index.html and its assets into a new public/ directory and
set publish = "public") and update any tooling that writes to the root (update
generate_index.py output path and any references in update_index.sh) so that
generated artifacts land in public/ instead of the repo root.
- Around line 5-7: netlify の [build] セクションで使われている非標準な設定 "command = \"# no build
command\"" を削除して、ビルドコマンドが不要であることを示すには単に `command` キー自体を省略してください(該当箇所は [build]
セクション内の `command` キーです)。これによりコメント風のシェル行を残さず標準的な構成になります。
- Refactored 'generate_index.py' to a class-based structure, improved error handling, fixed encoding issues, and now outputs to 'public/' directory to prevent source code exposure. - Updated 'netlify.toml' to publish from 'public/' and removed custom command. - Hardened 'update_index.sh' with strict error handling and directory checks. - Updated 'INDEX_MAINTENANCE.md' with new instructions and improved git hook script. - Updated 'README.md' to reference the new 'public/index.html'. - Removed root 'index.html' and generated initial site in 'public/'.
Index Maintenance Refactoring
Secure Deployment
public/directory (copy HTMLs + generate index)public/