Skip to content

Commit 1bfd8b8

Browse files
authored
Merge pull request #309 from myoshi2891/coderabbitai/docstrings/d6f6fc9
📝 Add docstrings to `dev-from-macmini`
2 parents d6f6fc9 + 3384e80 commit 1bfd8b8

17 files changed

Lines changed: 67 additions & 101 deletions

File tree

generate_index.py

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,36 +77,56 @@ def copy_vendor_files(self, output_dir: str) -> None:
7777

7878
def rewrite_html_content(self, content: str) -> str:
7979
"""
80-
Rewrite known CDN asset URLs in an HTML document to their corresponding local vendor paths.
81-
82-
Replaces specific external CDN links (React, Babel, Tailwind, PrismJS, FontAwesome, etc.) with local /vendor/... paths so the returned HTML references vendored assets.
83-
80+
Rewrite CDN asset URLs in HTML to local /vendor/ paths.
81+
82+
Replaces known external CDN links (React, Babel, Tailwind, PrismJS, FontAwesome, etc.) with corresponding /vendor/... paths and removes `integrity` and `crossorigin` attributes from `<link>` and `<script>` tags that reference those local vendor files.
83+
84+
Parameters:
85+
content (str): HTML document content to rewrite.
86+
8487
Returns:
85-
The input HTML string with matched CDN URLs substituted by local vendor URLs.
88+
str: The HTML content with matching CDN URLs substituted by local vendor URLs and SRI/crossorigin attributes stripped for vendored assets.
8689
"""
8790
replacements = [
8891
# React
89-
('https://unpkg.com/react@18/umd/react.development.js', '/vendor/react/react.development.js'),
90-
('https://unpkg.com/react@18/umd/react.production.min.js', '/vendor/react/react.production.min.js'),
91-
('https://unpkg.com/react-dom@18/umd/react-dom.development.js', '/vendor/react-dom/react-dom.development.js'),
92-
('https://unpkg.com/react-dom@18/umd/react-dom.production.min.js', '/vendor/react-dom/react-dom.production.min.js'),
92+
(r'https://unpkg\.com/react@[^/]+/umd/react\.development\.js', '/vendor/react/react.development.js'),
93+
(r'https://unpkg\.com/react@[^/]+/umd/react\.production\.min\.js', '/vendor/react/react.production.min.js'),
94+
(r'https://unpkg\.com/react-dom@[^/]+/umd/react-dom\.development\.js', '/vendor/react-dom/react-dom.development.js'),
95+
(r'https://unpkg\.com/react-dom@[^/]+/umd/react-dom\.production\.min\.js', '/vendor/react-dom/react-dom.production.min.js'),
9396
# Babel
94-
('https://unpkg.com/@babel/standalone/babel.min.js', '/vendor/babel/babel.min.js'),
95-
('https://unpkg.com/@babel/standalone/babel.js', '/vendor/babel/babel.min.js'),
97+
(r'https://unpkg\.com/@babel/standalone(?:@[^/]+)?/babel\.min\.js', '/vendor/babel/babel.min.js'),
98+
(r'https://unpkg\.com/@babel/standalone(?:@[^/]+)?/babel\.js', '/vendor/babel/babel.min.js'),
9699
# Tailwind
97-
('https://cdn.tailwindcss.com', '/vendor/tailwindcss/script.js'),
100+
(r'https://cdn\.tailwindcss\.com(?:@[^/]+)?', '/vendor/tailwindcss/script.js'),
98101
# PrismJS
99-
# Handle minified vs unminified mapping. Node modules usually has unminified.
100-
# We map the CDN .min.css requests to our local .css files (which we copied from node_modules)
101-
('https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css', '/vendor/prismjs/themes/prism.css'),
102-
('https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.css', '/vendor/prismjs/plugins/line-numbers/prism-line-numbers.css'),
103-
('https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.css', '/vendor/prismjs/plugins/toolbar/prism-toolbar.css'),
102+
(r'https://cdnjs\.cloudflare\.com/ajax/libs/prism/[^/]+/themes/prism\.min\.css', '/vendor/prismjs/themes/prism.css'),
103+
(r'https://cdnjs\.cloudflare\.com/ajax/libs/prism/[^/]+/plugins/line-numbers/prism-line-numbers\.min\.css', '/vendor/prismjs/plugins/line-numbers/prism-line-numbers.css'),
104+
(r'https://cdnjs\.cloudflare\.com/ajax/libs/prism/[^/]+/plugins/toolbar/prism-toolbar\.min\.css', '/vendor/prismjs/plugins/toolbar/prism-toolbar.css'),
104105
# FontAwesome
105-
('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css', '/vendor/fontawesome/css/all.min.css'),
106+
(r'https://cdnjs\.cloudflare\.com/ajax/libs/font-awesome/[^/]+/css/all\.min\.css', '/vendor/fontawesome/css/all.min.css'),
106107
]
107108

108-
for old, new in replacements:
109-
content = content.replace(old, new)
109+
for pattern_str, new in replacements:
110+
content = re.sub(pattern_str, new, content)
111+
112+
# Strip integrity and crossorigin attributes from tags referencing local /vendor/ files
113+
def strip_sri(match):
114+
"""
115+
Remove Subresource Integrity (`integrity`) and `crossorigin` attributes from an HTML <link> or <script> tag if the tag references a `/vendor/` path.
116+
117+
Parameters:
118+
match (re.Match): A regex match object whose matched text is the full HTML tag.
119+
120+
Returns:
121+
str: The original tag text with `integrity` and `crossorigin` attributes removed when the tag contains `/vendor/`; otherwise the original tag text unchanged.
122+
"""
123+
tag_text = match.group(0)
124+
if '/vendor/' in tag_text:
125+
tag_text = re.sub(r'\s*integrity="[^"]+"', '', tag_text)
126+
tag_text = re.sub(r'\s*crossorigin="[^"]+"', '', tag_text)
127+
return tag_text
128+
129+
content = re.sub(r'<(?:link|script)[^>]+>', strip_sri, content)
110130

111131
return content
112132

@@ -174,6 +194,12 @@ def generate_index(self) -> None:
174194
title = self.get_html_title(filepath)
175195
except Exception:
176196
title = os.path.basename(filepath)
197+
198+
# Append disambiguator if 'detailed' is in the filename
199+
if 'detailed' in filename.lower():
200+
if '(detailed)' not in title.lower():
201+
title += ' (detailed)'
202+
177203
structure[category].append((title, rel_path))
178204

179205
# Sort categories and files
@@ -891,11 +917,11 @@ def generate_index(self) -> None:
891917
def render_category_files(structure, sorted_categories):
892918
"""
893919
Builds HTML fragments for category tabs, per-category file lists, and an aggregated all-files list.
894-
920+
895921
Parameters:
896922
structure (Dict[str, List[Tuple[str, str]]]): Mapping from category name to a list of (title, relative_path) pairs for files in that category.
897923
sorted_categories (List[str]): Ordered list of category names to render; determines the iteration order and tab order.
898-
924+
899925
Returns:
900926
Tuple[str, str, str]: A 3-tuple with:
901927
- tabs_html: HTML for the category tab buttons (includes icon and item count for each category).
@@ -925,7 +951,8 @@ def render_category_files(structure, sorted_categories):
925951
safe_title = html.escape(title)
926952
safe_github_path = html.escape(github_path) # Escape path for display
927953

928-
item_html = f'<li class="file-item" data-category="{css_cat}"><a class="file-link" href="{encoded_path}">' \
954+
safe_encoded_path = html.escape(encoded_path, quote=True)
955+
item_html = f'<li class="file-item" data-category="{css_cat}"><a class="file-link" href="{safe_encoded_path}">' \
929956
f'<span class="card-header"><span class="card-icon">{icon}</span>' \
930957
f'<span class="card-title">{safe_title}</span></span><span class="file-path">{safe_github_path}</span></a></li>\n'
931958
category_files.append(item_html)
@@ -955,4 +982,4 @@ def render_category_files(structure, sorted_categories):
955982
print(f"Successfully updated {output_index_path} with vendored assets at {current_time}")
956983

957984
if __name__ == "__main__":
958-
Solution().generate_index()
985+
Solution().generate_index()

public/Algorithm/Other/leetcode/66. Plus One/Claude Sonnet 4.5/README_react.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ <h4 class="font-bold text-blue-900 mb-2">💡 最適化ポイント</h4>
931931
></script>
932932

933933
<!-- Babel Standalone -->
934-
<script src="https://unpkg.com/@babel/standalone@7.24.0/babel.min.js"></script>
934+
<script src="/vendor/babel/babel.min.js"></script>
935935

936936
<!-- Prism.js -->
937937
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>

public/DataStructures/LinkedLists/leetcode/86. Partition List/GPT/README.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<!-- Icons -->
3232
<link
3333
rel="stylesheet"
34-
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
34+
href="/vendor/fontawesome/css/all.min.css"
3535
/>
3636

3737
<style>

public/DataStructures/Stacks/leetcode/84. Largest Rectangle in Histogram/Claude/README_tailwind.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
rel="stylesheet"
6969
/>
7070
<link
71-
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
71+
href="/vendor/fontawesome/css/all.min.css"
7272
rel="stylesheet"
7373
/>
7474

public/DataStructures/Stacks/leetcode/84. Largest Rectangle in Histogram/GPT/README.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
/>
1313
<link
1414
rel="stylesheet"
15-
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
16-
crossorigin="anonymous"
15+
href="/vendor/fontawesome/css/all.min.css"
1716
referrerpolicy="no-referrer"
1817
/>
1918

public/DataStructures/Stacks/leetcode/84. Largest Rectangle in Histogram/GPT/README_tailwind.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@
6464
/>
6565
<link
6666
rel="stylesheet"
67-
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
68-
crossorigin="anonymous"
67+
href="/vendor/fontawesome/css/all.min.css"
6968
referrerpolicy="no-referrer"
7069
/>
7170

public/DataStructures/Stacks/leetcode/85. Maximal Rectangle/GPT/README.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
<!-- Font Awesome (icons) -->
3030
<link
31-
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
31+
href="/vendor/fontawesome/css/all.min.css"
3232
rel="stylesheet"
3333
/>
3434

public/DataStructures/Trees/BFS・DFS/leetcode/87. Scramble String/GPT/README.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<!-- Font Awesome (任意 / SRIなし) -->
1818
<link
1919
rel="stylesheet"
20-
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
20+
href="/vendor/fontawesome/css/all.min.css"
2121
/>
2222

2323
<!-- Prism CSS (SRIなし) -->

public/JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/README_react.html

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@
2626
<link
2727
href="/vendor/prismjs/plugins/line-numbers/prism-line-numbers.css"
2828
rel="stylesheet"
29-
integrity="sha384-nUkTNLI8COlMCRJ0FHIdX76If83145OTCLUx4gQyfnO0gGeO/sD9czGEUBxtkcUv"
30-
crossorigin="anonymous"
3129
/>
3230
<link
3331
href="/vendor/prismjs/plugins/toolbar/prism-toolbar.css"
3432
rel="stylesheet"
35-
integrity="sha384-EUzJ34/1CCeefTGUKLgvA5Z/vYIwi+Jyu8aAaCfFDxfwZ3Xs3OfkkIeegsLRM11e"
36-
crossorigin="anonymous"
3733
/>
3834

3935
<style>
@@ -1149,18 +1145,14 @@ <h3 class="text-xl font-semibold text-teal-800 mt-8 mb-4">実装方法の比較<
11491145

11501146
<!-- React & ReactDOM -->
11511147
<script
1152-
src="https://unpkg.com/react@18.3.1/umd/react.production.min.js"
1153-
integrity="sha384-DGyLxAyjq0f9SPpVevD6IgztCFlnMF6oW/XQGmfe+IsZ8TqEiDrcHkMLKI6fiB/Z"
1154-
crossorigin="anonymous"
1148+
src="/vendor/react/react.production.min.js"
11551149
></script>
11561150
<script
1157-
src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js"
1158-
integrity="sha384-gTGxhz21lVGYNMcdJOyq01Edg0jhn/c22nsx0kyqP0TxaV5WVdsSH1fSDUf5YJj1"
1159-
crossorigin="anonymous"
1151+
src="/vendor/react-dom/react-dom.production.min.js"
11601152
></script>
11611153

11621154
<!-- Babel Standalone -->
1163-
<script src="https://unpkg.com/@babel/standalone@7.23.5/babel.min.js" integrity="sha384-1qlE7MZPM2pHD/pBZCU/yB8UCP52RYL8bge/qNdfNBCWToySp8/M+JL2waXU4hjJ" crossorigin="anonymous"></script>
1155+
<script src="/vendor/babel/babel.min.js"></script>
11641156

11651157
<!-- Prism.js & Plugins (SRI Protected) -->
11661158
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js" integrity="sha384-06z5D//U/xpvxZHuUz92xBvq3DqBBFi7Up53HRrbV7Jlv7Yvh/MZ7oenfUe9iCEt" crossorigin="anonymous"></script>

public/JavaScript/2625. Flatten Deeply Nested Array/Claude Code Sonnet 4.5 extended/README_react.html

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,23 @@
2626
<link
2727
rel="stylesheet"
2828
href="/vendor/prismjs/plugins/line-numbers/prism-line-numbers.css"
29-
integrity="sha384-nUkTNLI8COlMCRJ0FHIdX76If83145OTCLUx4gQyfnO0gGeO/sD9czGEUBxtkcUv"
30-
crossorigin="anonymous"
3129
/>
3230
<link
3331
rel="stylesheet"
3432
href="/vendor/prismjs/plugins/toolbar/prism-toolbar.css"
35-
integrity="sha384-EUzJ34/1CCeefTGUKLgvA5Z/vYIwi+Jyu8aAaCfFDxfwZ3Xs3OfkkIeegsLRM11e"
36-
crossorigin="anonymous"
3733
/>
3834

3935
<!-- React & ReactDOM (Production) -->
4036
<script
41-
crossorigin="anonymous"
42-
src="https://unpkg.com/react@18.3.1/umd/react.production.min.js"
43-
integrity="sha384-DGyLxAyjq0f9SPpVevD6IgztCFlnMF6oW/XQGmfe+IsZ8TqEiDrcHkMLKI6fiB/Z"
37+
src="/vendor/react/react.production.min.js"
4438
></script>
4539
<script
46-
crossorigin="anonymous"
47-
src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js"
48-
integrity="sha384-gTGxhz21lVGYNMcdJOyq01Edg0jhn/c22nsx0kyqP0TxaV5WVdsSH1fSDUf5YJj1"
40+
src="/vendor/react-dom/react-dom.production.min.js"
4941
></script>
5042

5143
<!-- Babel Standalone -->
5244
<script
53-
src="https://unpkg.com/@babel/standalone@7.26.9/babel.min.js"
54-
integrity="sha384-pKNXKj7jF9BNMkQyGWg5YLfoPyqBa/gf7wjTSoTGQlwxbZB+sabJuKyOHR6JQvTd"
55-
crossorigin="anonymous"
45+
src="/vendor/babel/babel.min.js"
5646
></script>
5747

5848
<style>

0 commit comments

Comments
 (0)