-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_projects.py
More file actions
298 lines (230 loc) · 9.07 KB
/
sync_projects.py
File metadata and controls
298 lines (230 loc) · 9.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/env python3
"""
Big0Time Project Sync Script
Scans the GitHub projects directory and updates the big0time index.html with:
- Projects sorted by modification date (newest first)
- Grayed out text for projects without landing pages
- Fire icon (🔥) for recently active projects (modified in last 7 days)
- Copies under-construction.html to projects without landing pages
"""
import os
import shutil
import subprocess
from pathlib import Path
from datetime import datetime, timedelta
# Configuration
GITHUB_DIR = Path("/Users/polerixsys/Documents/GitHub")
big0time_DIR = GITHUB_DIR / "big0time"
UNDER_CONSTRUCTION = big0time_DIR / "under-construction.html"
INDEX_HTML = big0time_DIR / "index.html"
RECENT_DAYS = 7 # Projects modified within this many days get fire icon
# Landing page patterns to check (in order of preference)
LANDING_PAGES = [
"index.html",
"index.htm",
"README.html",
"main.html",
"app.html",
]
def get_project_description(project_dir: Path) -> str:
"""Extract project description from README.md or package.json"""
readme = project_dir / "README.md"
if readme.exists():
try:
content = readme.read_text(encoding='utf-8', errors='ignore')
lines = content.strip().split('\n')
# Skip title line (# prefix) and get first non-empty line
for line in lines[1:]:
line = line.strip()
if line and not line.startswith('#'):
# Clean up the description
desc = line.strip().lstrip('- ').lstrip('* ')
if len(desc) > 60:
desc = desc[:57] + "..."
return desc
except Exception:
pass
# Try package.json
pkg_json = project_dir / "package.json"
if pkg_json.exists():
try:
import json
pkg = json.loads(pkg_json.read_text(encoding='utf-8', errors='ignore'))
desc = pkg.get("description", "")
if desc and len(desc) > 60:
desc = desc[:57] + "..."
return desc
except Exception:
pass
return ""
def get_github_url(project_name: str) -> str:
"""Generate GitHub URL from project name"""
return f"https://github.com/polerix/{project_name}"
def get_deployed_url(project_name: str) -> str | None:
"""Generate GitHub Pages URL if deployed, None otherwise"""
# Common patterns for GitHub Pages
base_url = f"https://polerix.github.io/{project_name}"
project_dir = GITHUB_DIR / project_name
# Check if any of the landing pages exist
for landing in LANDING_PAGES:
landing_path = project_dir / landing
if landing_path.exists():
if landing == "index.html" or landing == "index.htm":
return base_url + "/"
return f"{base_url}/{landing}"
return None
def get_project_modification_date(project_dir: Path) -> datetime:
"""Get the most recent modification date (fast version)"""
latest_date = datetime(1970, 1, 1)
# Check .git for commit dates (most reliable and fastest)
git_dir = project_dir / ".git"
if git_dir.exists():
try:
# Get most recent commit date using a faster git command
result = subprocess.run(
["git", "log", "-1", "--format=%ct"],
cwd=project_dir,
capture_output=True,
text=True,
timeout=5
)
if result.returncode == 0 and result.stdout.strip():
timestamp = int(result.stdout.strip())
return datetime.fromtimestamp(timestamp)
except Exception:
pass
# Fallback to directory mtime (much faster than recursive glob)
try:
mtime = datetime.fromtimestamp(project_dir.stat().st_mtime)
return max(latest_date, mtime)
except Exception:
pass
return latest_date
def is_recently_modified(project_dir: Path) -> bool:
"""Check if project was modified in the last RECENT_DAYS days"""
mod_date = get_project_modification_date(project_dir)
return datetime.now() - mod_date < timedelta(days=RECENT_DAYS)
def has_landing_page(project_dir: Path) -> bool:
"""Check if project has a landing page"""
for landing in LANDING_PAGES:
if (project_dir / landing).exists():
return True
return False
def copy_under_construction(project_name: str) -> str:
"""Copy under-construction.html to a project directory"""
project_dir = GITHUB_DIR / project_name
dest = project_dir / "under-construction.html"
if not dest.exists():
shutil.copy2(UNDER_CONSTRUCTION, dest)
print(f" Copied under-construction.html to {project_name}")
return "under-construction.html"
def generate_project_html(project_name: str, project_dir: Path) -> str:
"""Generate HTML for a single project entry"""
has_landing = has_landing_page(project_dir)
is_recent = is_recently_modified(project_dir)
description = get_project_description(project_dir)
# Strip HTML tags from description for clean display
import re
description = re.sub(r'<[^>]+>', '', description)
# Clean up common artifacts
description = description.replace('**', '').replace('\\u', '').strip()
if len(description) > 80:
description = description[:77] + '...'
# Determine the open URL
if has_landing:
open_url = get_deployed_url(project_name)
else:
# Copy under-construction and link to it
copy_under_construction(project_name)
open_url = f"https://polerix.github.io/{project_name}/under-construction.html"
github_url = get_github_url(project_name)
# Generate the HTML (bubble style)
fire_icon = "🔥 " if is_recent else ""
muted_class = " muted" if not has_landing else ""
html = f''' <div class="bubble{muted_class}" data-name="{project_name}">
<div class="inner-glow"></div>
<div class="light-spot"></div>
<div class="name">{fire_icon}{project_name}</div>
<div class="desc">{description}</div>
<div class="actions">
<a href="{open_url}" target="_blank" rel="noopener noreferrer"><button>Open</button></a>
<a href="{github_url}" target="_blank" rel="noopener noreferrer"><button>Repo</button></a>
</div>
</div>'''
return html
def get_all_projects() -> list[tuple[Path, datetime]]:
"""Get all project directories sorted by modification date"""
projects = []
for item in GITHUB_DIR.iterdir():
if not item.is_dir():
continue
# Skip hidden directories and special dirs
if item.name.startswith('.') or item.name.startswith('clawd'):
continue
# Skip big0time itself
if item.name == "big0time":
continue
mod_date = get_project_modification_date(item)
projects.append((item, mod_date))
# Sort by modification date (newest first)
projects.sort(key=lambda x: x[1], reverse=True)
return projects
def update_index_html():
"""Update the index.html with current project list"""
print("Scanning projects...")
projects = get_all_projects()
print(f"Found {len(projects)} projects")
# Generate project HTML entries
project_entries = []
for project_dir, mod_date in projects:
project_name = project_dir.name
print(f" {project_name}: {mod_date.strftime('%Y-%m-%d')}", end="")
has_landing = has_landing_page(project_dir)
is_recent = is_recently_modified(project_dir)
if not has_landing:
print(" [no landing]", end="")
if is_recent:
print(" [recent]", end="")
print()
html = generate_project_html(project_name, project_dir)
project_entries.append(html)
# Read the template
template = INDEX_HTML.read_text(encoding='utf-8')
# Find the menu start and end markers
menu_start = '<!-- MENU START -->'
menu_end = '<!-- MENU END -->'
start_idx = template.find(menu_start)
end_idx = template.find(menu_end)
if start_idx == -1 or end_idx == -1:
print("ERROR: Could not find menu markers in index.html")
return
# Build new template (bubble grid style)
new_template = (
template[:start_idx + len(menu_start)] +
'\n <div class="grid">' +
'\n'.join(project_entries) +
'\n </div>' +
template[end_idx:]
)
# Update the index
INDEX_HTML.write_text(new_template, encoding='utf-8')
print(f"\nUpdated {INDEX_HTML}")
def main():
"""Main entry point"""
print("=" * 50)
print("Big0Time Project Sync")
print("=" * 50)
# Verify paths exist
if not GITHUB_DIR.exists():
print(f"ERROR: GitHub directory not found: {GITHUB_DIR}")
return
if not big0time_DIR.exists():
print(f"ERROR: big0time directory not found: {big0time_DIR}")
return
if not UNDER_CONSTRUCTION.exists():
print(f"ERROR: under-construction.html not found: {UNDER_CONSTRUCTION}")
return
update_index_html()
print("\nSync complete!")
if __name__ == "__main__":
main()