Skip to content

Commit ea827a2

Browse files
committed
update
1 parent 726fdb5 commit ea827a2

File tree

4 files changed

+148
-46
lines changed

4 files changed

+148
-46
lines changed

.github/workflows/verify.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,21 @@ jobs:
201201
- name: Commit minified versions
202202
shell: bash
203203
run: |
204+
git config user.name "github-actions[bot]"
205+
git config user.email "github-actions[bot]@users.noreply.github.com"
206+
changes=false
207+
204208
if [ -n "$(git status cp-algo/min/ --porcelain)" ]; then
205-
git config user.name "github-actions[bot]"
206-
git config user.email "github-actions[bot]@users.noreply.github.com"
207209
git add cp-algo/min/
210+
changes=true
211+
fi
212+
213+
if [ -n "$(git status cp-algo/min-bundled/ --porcelain)" ]; then
214+
git add cp-algo/min-bundled/
215+
changes=true
216+
fi
217+
218+
if [ "$changes" = true ]; then
208219
git commit -m "chore: update minified library versions"
209220
git push
210221
else

.verify-helper/docs/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
exclude: ['images']
1+
exclude: ['images', 'cp-algo/min', 'cp-algo/min-bundled']
22
title: CP-Algorithms Library

.verify-helper/scripts/generate_minified.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,32 +133,37 @@ def process_file(bundled_path, minified_path, committed_path=None):
133133
def main():
134134
# Source directory to minify
135135
source_dir = Path('cp-algo')
136+
bundled_dir = Path('.competitive-verifier/bundled')
136137

137138
# Output directories
138139
minified_ci_dir = Path('.competitive-verifier/minified')
140+
minified_bundled_ci_dir = Path('.competitive-verifier/minified-bundled')
139141
minified_committed_dir = Path('cp-algo/min')
142+
minified_bundled_committed_dir = Path('cp-algo/min-bundled')
140143

141144
# Verify source directory exists
142145
if not source_dir.exists():
143146
print(f"Error: {source_dir} does not exist", file=sys.stderr)
144147
sys.exit(1)
145148

146149
# Clear output directories
147-
if minified_ci_dir.exists():
148-
import shutil
149-
shutil.rmtree(minified_ci_dir)
150+
for d in [minified_ci_dir, minified_bundled_ci_dir]:
151+
if d.exists():
152+
import shutil
153+
shutil.rmtree(d)
154+
d.mkdir(parents=True, exist_ok=True)
150155

151-
minified_ci_dir.mkdir(parents=True, exist_ok=True)
152-
minified_committed_dir.mkdir(parents=True, exist_ok=True)
156+
for d in [minified_committed_dir, minified_bundled_committed_dir]:
157+
d.mkdir(parents=True, exist_ok=True)
153158

154159
print("Generating minified versions from source files...")
155160

156161
total_files = 0
157162
processed_files = 0
158163

159-
# Process all source files in cp-algo (but not in cp-algo/min itself)
164+
# Process all source files in cp-algo (but not in cp-algo/min* itself)
160165
for src_file in source_dir.rglob('*'):
161-
# Skip files in min directory
166+
# Skip files in min directories
162167
if 'min' in src_file.parts:
163168
continue
164169

@@ -168,18 +173,43 @@ def main():
168173
# Calculate relative path within cp-algo
169174
rel_path = src_file.relative_to(source_dir)
170175

171-
# Output paths
176+
# Output paths for minified source
172177
minified_ci_file = minified_ci_dir / 'cp-algo' / rel_path
173178
minified_committed_file = minified_committed_dir / rel_path
174179

175180
if process_file(src_file, minified_ci_file, minified_committed_file):
176181
processed_files += 1
177182

178-
print(f"\nProcessed {processed_files}/{total_files} files")
179-
print(f"Generated in:")
183+
print(f"\nProcessed {processed_files}/{total_files} source files")
184+
print(f"Generated source minified in:")
180185
print(f" - .competitive-verifier/minified/cp-algo/")
181186
print(f" - cp-algo/min/")
182187

188+
# Now process bundled versions if they exist
189+
if bundled_dir.exists():
190+
print(f"\nGenerating minified bundled versions from bundled files...")
191+
total_bundled = 0
192+
processed_bundled = 0
193+
194+
for bundled_file in bundled_dir.rglob('*'):
195+
if bundled_file.is_file() and bundled_file.suffix in ['.hpp', '.cpp', '.h']:
196+
total_bundled += 1
197+
198+
# Calculate relative path within bundled
199+
rel_path = bundled_file.relative_to(bundled_dir)
200+
201+
# Output paths for minified bundled
202+
minified_bundled_ci_file = minified_bundled_ci_dir / rel_path
203+
minified_bundled_committed_file = minified_bundled_committed_dir / rel_path
204+
205+
if process_file(bundled_file, minified_bundled_ci_file, minified_bundled_committed_file):
206+
processed_bundled += 1
207+
208+
print(f"\nProcessed {processed_bundled}/{total_bundled} bundled files")
209+
print(f"Generated bundled minified in:")
210+
print(f" - .competitive-verifier/minified-bundled/")
211+
print(f" - cp-algo/min-bundled/")
212+
183213
if processed_files < total_files and total_files > 0:
184214
sys.exit(1)
185215

.verify-helper/scripts/inject_minified_docs.py

Lines changed: 94 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_minified_code(file_path, minified_dir):
2929
return None
3030

3131

32-
def inject_minified_to_markdown(markdown_file, minified_code):
32+
def inject_minified_to_markdown(markdown_file, minified_code=None, minified_bundled_code=None):
3333
"""Inject minified code into markdown file's front matter."""
3434
try:
3535
with open(markdown_file, 'r', encoding='utf-8') as f:
@@ -47,27 +47,65 @@ def inject_minified_to_markdown(markdown_file, minified_code):
4747
front_matter = parts[1]
4848
body = parts[2]
4949

50-
# Parse front matter to check if minifiedCode already exists
51-
if 'minifiedCode:' in front_matter:
52-
# Replace existing minifiedCode
53-
front_matter = re.sub(
54-
r' minifiedCode: ".*?"(?=\n [a-zA-Z_]|\n$)',
55-
f' minifiedCode: "{minified_code}"',
56-
front_matter,
57-
flags=re.DOTALL
58-
)
59-
else:
60-
# Add minifiedCode after bundledCode if it exists
61-
if 'bundledCode:' in front_matter:
50+
updated = False
51+
52+
# Handle minifiedCode
53+
if minified_code:
54+
if 'minifiedCode:' in front_matter:
55+
# Replace existing minifiedCode
6256
front_matter = re.sub(
63-
r'( bundledCode: ".*?")(\n [a-zA-Z_]|\n$)',
64-
rf'\1\n minifiedCode: "{minified_code}"\2',
57+
r' minifiedCode: ".*?"(?=\n [a-zA-Z_]|\n$)',
58+
f' minifiedCode: "{minified_code}"',
6559
front_matter,
6660
flags=re.DOTALL
6761
)
6862
else:
69-
# Add at the end of front matter
70-
front_matter = front_matter.rstrip() + f'\n minifiedCode: "{minified_code}"'
63+
# Add minifiedCode after bundledCode if it exists
64+
if 'bundledCode:' in front_matter:
65+
front_matter = re.sub(
66+
r'( bundledCode: ".*?")(\n [a-zA-Z_]|\n$)',
67+
rf'\1\n minifiedCode: "{minified_code}"\2',
68+
front_matter,
69+
flags=re.DOTALL
70+
)
71+
else:
72+
# Add at the end of front matter
73+
front_matter = front_matter.rstrip() + f'\n minifiedCode: "{minified_code}"'
74+
updated = True
75+
76+
# Handle minifiedBundledCode
77+
if minified_bundled_code:
78+
if 'minifiedBundledCode:' in front_matter:
79+
# Replace existing minifiedBundledCode
80+
front_matter = re.sub(
81+
r' minifiedBundledCode: ".*?"(?=\n [a-zA-Z_]|\n$)',
82+
f' minifiedBundledCode: "{minified_bundled_code}"',
83+
front_matter,
84+
flags=re.DOTALL
85+
)
86+
else:
87+
# Add minifiedBundledCode after minifiedCode if it exists
88+
if 'minifiedCode:' in front_matter:
89+
front_matter = re.sub(
90+
r'( minifiedCode: ".*?")(\n [a-zA-Z_]|\n$)',
91+
rf'\1\n minifiedBundledCode: "{minified_bundled_code}"\2',
92+
front_matter,
93+
flags=re.DOTALL
94+
)
95+
elif 'bundledCode:' in front_matter:
96+
front_matter = re.sub(
97+
r'( bundledCode: ".*?")(\n [a-zA-Z_]|\n$)',
98+
rf'\1\n minifiedBundledCode: "{minified_bundled_code}"\2',
99+
front_matter,
100+
flags=re.DOTALL
101+
)
102+
else:
103+
# Add at the end of front matter
104+
front_matter = front_matter.rstrip() + f'\n minifiedBundledCode: "{minified_bundled_code}"'
105+
updated = True
106+
107+
if not updated:
108+
return False
71109

72110
# Write updated content
73111
new_content = f'---{front_matter}---{body}'
@@ -81,12 +119,19 @@ def inject_minified_to_markdown(markdown_file, minified_code):
81119

82120

83121
def main():
84-
markdown_dir = Path('.verify-helper/markdown')
122+
markdown_dir = Path('_jekyll')
85123
minified_dir = Path('cp-algo/min')
124+
minified_bundled_dir = Path('cp-algo/min-bundled')
125+
126+
# If _jekyll doesn't exist, try the verify-helper path (for local testing)
127+
if not markdown_dir.exists():
128+
markdown_dir = Path('.verify-helper/markdown')
86129

87130
if not minified_dir.exists():
88131
print(f"Warning: {minified_dir} does not exist", file=sys.stderr)
89-
return 0
132+
133+
if not minified_bundled_dir.exists():
134+
print(f"Warning: {minified_bundled_dir} does not exist", file=sys.stderr)
90135

91136
if not markdown_dir.exists():
92137
print(f"Error: {markdown_dir} does not exist", file=sys.stderr)
@@ -95,29 +140,45 @@ def main():
95140
print("Injecting minified code into documentation...")
96141

97142
count = 0
98-
# Find all markdown files with bundledCode
143+
# Find all markdown files
99144
for md_file in markdown_dir.rglob('*.md'):
100145
# Get relative path without .md extension
101146
rel_path = md_file.relative_to(markdown_dir)
102147
path_without_ext = str(rel_path)[:-3] # Remove .md
103148

104-
# Try to find corresponding minified file
105-
possible_extensions = ['hpp', 'cpp', 'h']
106149
minified_code = None
150+
minified_bundled_code = None
151+
152+
# Try to find corresponding minified source file
153+
possible_extensions = ['hpp', 'cpp', 'h']
154+
155+
for ext in possible_extensions:
156+
if minified_code is None and minified_dir.exists():
157+
minified_file = minified_dir / f"{path_without_ext}.{ext}"
158+
if minified_file.exists():
159+
with open(minified_file, 'r', encoding='utf-8') as f:
160+
code = f.read()
161+
# Escape for YAML
162+
code = code.replace('\\', '\\\\')
163+
code = code.replace('"', '\\"')
164+
code = code.replace('\n', '\\n')
165+
minified_code = code
107166

167+
# Try to find corresponding minified bundled file
108168
for ext in possible_extensions:
109-
minified_file = minified_dir / f"{path_without_ext}.{ext}"
110-
if minified_file.exists():
111-
with open(minified_file, 'r', encoding='utf-8') as f:
112-
code = f.read()
113-
# Escape for YAML
114-
code = code.replace('\\', '\\\\')
115-
code = code.replace('"', '\\"')
116-
code = code.replace('\n', '\\n')
117-
minified_code = code
118-
break
169+
if minified_bundled_code is None and minified_bundled_dir.exists():
170+
minified_bundled_file = minified_bundled_dir / f"{path_without_ext}.{ext}"
171+
if minified_bundled_file.exists():
172+
with open(minified_bundled_file, 'r', encoding='utf-8') as f:
173+
code = f.read()
174+
# Escape for YAML
175+
code = code.replace('\\', '\\\\')
176+
code = code.replace('"', '\\"')
177+
code = code.replace('\n', '\\n')
178+
minified_bundled_code = code
119179

120-
if minified_code and inject_minified_to_markdown(md_file, minified_code):
180+
# Only inject if we found at least one minified version
181+
if (minified_code or minified_bundled_code) and inject_minified_to_markdown(md_file, minified_code, minified_bundled_code):
121182
count += 1
122183
print(f" Updated: {path_without_ext}")
123184

0 commit comments

Comments
 (0)