@@ -163,7 +163,10 @@ def generate_index(self) -> None:
163163 if category .startswith ('.' ):
164164 continue
165165
166- title = self .get_html_title (filepath )
166+ try :
167+ title = self .get_html_title (filepath )
168+ except Exception :
169+ title = os .path .basename (filepath )
167170 structure [category ].append ((title , rel_path ))
168171
169172 # Sort categories and files
@@ -611,13 +614,14 @@ def generate_index(self) -> None:
611614 <span class="search-icon">\U0001F50D </span>
612615 <input type="text" id="searchInput" class="search-input"
613616 placeholder="Search problems... (e.g. Binary Search, DP, LeetCode 91)"
617+ aria-label="Search problems"
614618 autocomplete="off">
615619 <span id="searchCount" class="search-count"></span>
616620 <button id="searchClear" class="search-clear" aria-label="Clear search">\u00D7 </button>
617621 </div>
618622
619623 <div class="tabs" id="categoryTabs">
620- <button class="tab-button active" data-category="all" onclick="openTab(event, ' All') ">
624+ <button class="tab-button active" data-category="all" data-tab-target=" All">
621625 <span class="tab-icon">\U0001F30D </span> All <span class="tab-count">{total_count}</span>
622626 </button>
623627 {tabs}
@@ -736,16 +740,16 @@ def generate_index(self) -> None:
736740 function applyStaggerAnimation(tabId) {{
737741 const tab = document.getElementById(tabId);
738742 const items = tab.querySelectorAll('.file-item:not(.hidden-item)');
743+ items.forEach(item => {{ item.style.animation = 'none'; }});
744+ tab.offsetHeight;
739745 items.forEach((item, i) => {{
740- item.style.animation = 'none';
741- item.offsetHeight;
742746 item.style.animation = '';
743747 item.style.animationDelay = (i * 0.04) + 's';
744748 }});
745749 }}
746750
747751 /* Tab Navigation */
748- function openTab(evt, categoryName) {{
752+ function openTab(categoryName) {{
749753 document.querySelectorAll('.tab-content').forEach(tc => {{
750754 tc.style.display = 'none';
751755 tc.classList.remove('active');
@@ -757,7 +761,8 @@ def generate_index(self) -> None:
757761 const target = document.getElementById(categoryName);
758762 target.style.display = 'block';
759763 target.classList.add('active');
760- evt.currentTarget.classList.add('active');
764+ const btn = document.querySelector('.tab-button[data-tab-target="' + categoryName + '"]');
765+ if (btn) btn.classList.add('active');
761766
762767 const input = document.getElementById('searchInput');
763768 if (input.value) {{
@@ -850,9 +855,20 @@ def generate_index(self) -> None:
850855 }});
851856 }}
852857
858+ /* Tab Delegation */
859+ function initTabs() {{
860+ document.getElementById('categoryTabs').addEventListener('click', (evt) => {{
861+ const btn = evt.target.closest('.tab-button');
862+ if (btn && btn.dataset.tabTarget) {{
863+ openTab(btn.dataset.tabTarget);
864+ }}
865+ }});
866+ }}
867+
853868 /* Init */
854869 window.addEventListener('DOMContentLoaded', () => {{
855870 initTheme();
871+ initTabs();
856872 initPagination();
857873 initSearch();
858874 }});
@@ -870,8 +886,9 @@ def generate_index(self) -> None:
870886 count = len (files )
871887 icon = category_icons .get (category , '' )
872888 css_cat = category .lower ()
889+ safe_category = html .escape (category , quote = True )
873890
874- tabs_html += f'<button class="tab-button" data-category="{ css_cat } " onclick="openTab(event, \' { category } \' ) "><span class="tab-icon">{ icon } </span> { category } <span class="tab-count">{ count } </span></button>\n '
891+ tabs_html += f'<button class="tab-button" data-category="{ css_cat } " data-tab-target=" { safe_category } "><span class="tab-icon">{ icon } </span> { safe_category } <span class="tab-count">{ count } </span></button>\n '
875892
876893 file_list_html = '<ul class="file-list">\n '
877894 for title , path in files :
@@ -883,7 +900,7 @@ def generate_index(self) -> None:
883900 all_files_html += item_html
884901 file_list_html += '</ul>'
885902
886- tab_contents_html += f'<div id="{ category } " class="tab-content">\n { file_list_html } \n <div class="no-results"><span class="no-results-icon">\U0001F50E </span>No results found</div>\n </div>\n '
903+ tab_contents_html += f'<div id="{ safe_category } " class="tab-content">\n { file_list_html } \n <div class="no-results"><span class="no-results-icon">\U0001F50E </span>No results found</div>\n </div>\n '
887904
888905 final_html = html_template .format (
889906 tabs = tabs_html ,
0 commit comments