Skip to content

Commit 9cc0571

Browse files
committed
chore: minor fixes to pagination and search clear logic in index page
1 parent 93d0799 commit 9cc0571

3 files changed

Lines changed: 49 additions & 21 deletions

File tree

CLAUDE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ bunx prettier -w . # prettier 修正
2727
# 実行
2828
bunx tsx path/to/file.ts # TypeScript実行
2929
make lab # JupyterLab起動
30+
python generate_index.py # public/index.html 再生成
3031
```
3132

3233
パッケージマネージャは**Bun**`npm`ではなく`bun install`を使用。
@@ -77,6 +78,19 @@ make lab # JupyterLab起動
7778
- **Prettier**: semi, singleQuote, tabWidth: 4, printWidth: 100
7879
- **Python**: ruff + black
7980

81+
### インデックスページ生成
82+
83+
- `public/index.html``python generate_index.py` で自動生成。直接編集禁止
84+
- テンプレートは `generate_index.py` 内に埋め込み(Python `.format()` 使用、`{{`/`}}` でブレースエスケープ)
85+
- `public/` 配下の全ファイルは生成物。変更は必ずジェネレータ側で行う
86+
- テンプレート内JS で `innerHTML` 禁止(セキュリティフックがブロック)→ `textContent` + DOM API を使用
87+
- HTML出力に埋め込む文字列は `html.escape()` 必須(XSS防止)
88+
89+
### ブラウザテスト(Playwright MCP)
90+
91+
- `file://` URLはブロックされる → `python -m http.server 8765 --directory public` でローカルサーバー起動
92+
- `ruff` / `black` はグローバル未インストールの場合あり → `python -c "import py_compile; ..."` でシンタックスチェック代替
93+
8094
## SVGフローチャートガイドライン
8195

8296
`.agent/workflows/svg_flowchart_guidelines.md` に詳細あり。主要ポイント:

generate_index.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def generate_index(self) -> None:
177177
'SQL': '\U0001F5C3\uFE0F',
178178
}
179179
total_count = sum(len(v) for v in structure.values())
180+
domain_count = len(sorted_categories)
180181
current_time = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
181182

182183
# HTML Template — "Refined Lab" デザイン
@@ -598,7 +599,7 @@ def generate_index(self) -> None:
598599
\U0001F9EA Algorithm Study
599600
<span class="title-accent">Index</span>
600601
</h1>
601-
<p class="site-subtitle">{total_count} interactive lessons across 6 domains</p>
602+
<p class="site-subtitle">{total_count} interactive lessons across {domain_count} domains</p>
602603
</header>
603604
604605
<div class="search-container">
@@ -677,17 +678,20 @@ def generate_index(self) -> None:
677678
678679
function renderPaginationControls(tabId, totalPages, currentPage) {{
679680
const tab = document.getElementById(tabId);
680-
let container = tab.querySelector('.pagination');
681+
const existing = tab.querySelector('.pagination');
681682
682-
if (!container) {{
683-
container = document.createElement('div');
683+
if (totalPages <= 1) {{
684+
if (existing) existing.remove();
685+
return;
686+
}}
687+
688+
const container = existing || document.createElement('div');
689+
if (!existing) {{
684690
container.className = 'pagination';
685691
tab.appendChild(container);
686692
}}
687693
while (container.firstChild) container.removeChild(container.firstChild);
688694
689-
if (totalPages <= 1) return;
690-
691695
const prevBtn = document.createElement('button');
692696
prevBtn.className = 'page-button';
693697
prevBtn.textContent = '\u00AB Prev';
@@ -755,7 +759,9 @@ def generate_index(self) -> None:
755759
input.value = '';
756760
document.getElementById('searchClear').style.display = 'none';
757761
document.getElementById('searchCount').textContent = '';
758-
clearSearchFilter(categoryName);
762+
document.querySelectorAll('.tab-content').forEach(tc => {{
763+
clearSearchFilter(tc.id);
764+
}});
759765
}}
760766
761767
currentPages[categoryName] = currentPages[categoryName] || 1;
@@ -865,7 +871,9 @@ def generate_index(self) -> None:
865871
file_list_html = '<ul class="file-list">\n'
866872
for title, path in files:
867873
encoded_path = urllib.parse.quote(path)
868-
item_html = f'<li class="file-item" data-category="{css_cat}"><a class="file-link" href="{encoded_path}"><span class="card-header"><span class="card-icon">{icon}</span><span class="card-title">{title}</span></span><span class="file-path">{path}</span></a></li>\n'
874+
safe_title = html.escape(title)
875+
safe_path = html.escape(path)
876+
item_html = f'<li class="file-item" data-category="{css_cat}"><a class="file-link" href="{encoded_path}"><span class="card-header"><span class="card-icon">{icon}</span><span class="card-title">{safe_title}</span></span><span class="file-path">{safe_path}</span></a></li>\n'
869877
file_list_html += item_html
870878
all_files_html += item_html
871879
file_list_html += '</ul>'
@@ -878,6 +886,7 @@ def generate_index(self) -> None:
878886
tab_contents=tab_contents_html,
879887
timestamp=current_time,
880888
total_count=total_count,
889+
domain_count=domain_count,
881890
)
882891

883892
output_index_path = os.path.join(output_dir, index_file)

0 commit comments

Comments
 (0)