forked from Open-Coding-Society/pages
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
376 lines (333 loc) · 13.1 KB
/
Makefile
File metadata and controls
376 lines (333 loc) · 13.1 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
HOST ?= localhost
PORT ?= 4500
LOG_FILE = /tmp/jekyll$(PORT).log
SHELL = /bin/bash -c
.SHELLFLAGS = -e
NOTEBOOK_FILES := $(shell find _notebooks -name '*.ipynb')
DESTINATION_DIRECTORY = _posts
MARKDOWN_FILES := $(patsubst _notebooks/%.ipynb,$(DESTINATION_DIRECTORY)/%_IPYNB_2_.md,$(NOTEBOOK_FILES))
default: serve-current
@touch /tmp/.notebook_watch_marker
@make watch-notebooks &
@make watch-files
# File watcher - monitors log for file changes and triggers conversion
watch-files:
@echo "Watching for file changes (auto-convert on save)..."
@(tail -f $(LOG_FILE) | while read line; do \
if echo "$$line" | grep -q "Regenerating:"; then \
echo "$$line"; \
echo $$(date +%s) > /tmp/.jekyll_regenerating; \
elif echo "$$line" | grep -q "\.\.\.done in"; then \
rm -f /tmp/.jekyll_regenerating; \
echo " ✓ $$line"; \
elif echo "$$line" | grep -q "_notebooks/.*\.ipynb"; then \
echo "$$line"; \
notebook=$$(echo "$$line" | grep -o '_notebooks/[^[:space:]]*\.ipynb'); \
make convert-single NOTEBOOK_FILE="$$notebook" & \
elif echo "$$line" | grep -q "_docx/.*\.docx"; then \
echo "$$line"; \
docx=$$(echo "$$line" | grep -o '_docx/[^[:space:]]*\.docx'); \
make convert-docx-single DOCX_FILE="$$docx" & \
fi; \
done) 2>/dev/null & \
sleep 2; \
while true; do \
if [ -f /tmp/.jekyll_regenerating ]; then \
START=$$(cat /tmp/.jekyll_regenerating); \
NOW=$$(date +%s); \
ELAPSED=$$((NOW - START)); \
if [ $$((ELAPSED % 10)) -eq 0 ] && [ $$ELAPSED -gt 0 ]; then \
echo " Still regenerating... ($$ELAPSED seconds elapsed)"; \
fi; \
fi; \
sleep 1; \
done
use-minima:
@echo "Switching to Minima theme..."
@cp _themes/minima/_config.yml _config.yml
@cp _themes/minima/Gemfile Gemfile
@cp _themes/minima/opencs.html _layouts/opencs.html
@cp _themes/minima/page.html _layouts/page.html
@cp _themes/minima/post.html _layouts/post.html
@python3 scripts/update_color_map.py minima || echo "⚠ Color map update failed, continuing..."
@echo "✓ Minima theme activated"
use-cayman:
@echo "Switching to Cayman theme..."
@cp _themes/cayman/_config.yml _config.yml
@cp _themes/cayman/Gemfile Gemfile
@cp _themes/cayman/opencs.html _layouts/opencs.html
@cp _themes/cayman/page.html _layouts/page.html
@cp _themes/cayman/post.html _layouts/post.html
@python3 scripts/update_color_map.py cayman || echo "⚠ Color map update failed, continuing..."
@echo "✓ Cayman theme activated"
use-hydejack:
@echo "Switching to Hydejack theme..."
@cp _themes/hydejack/_config.yml _config.yml
@cp _themes/hydejack/Gemfile Gemfile
@cp _themes/hydejack/opencs.html _layouts/opencs.html
@cp _themes/hydejack/page.html _layouts/page.html
@cp _themes/hydejack/post.html _layouts/post.html
@python3 scripts/update_color_map.py hydejack || echo "⚠ Color map update failed, continuing..."
@echo "✓ Hydejack theme activated"
use-so-simple:
@cp _themes/so-simple/_config.yml _config.yml
@cp _themes/so-simple/Gemfile Gemfile
@cp _themes/so-simple/opencs.html _layouts/opencs.html
@cp _themes/so-simple/page.html _layouts/page.html
@cp _themes/so-simple/post.html _layouts/post.html
@cp _themes/so-simple/navigation.yml _data/navigation.yml
use-yat:
@cp _themes/yat/_config.yml _config.yml
@cp _themes/yat/Gemfile Gemfile
@cp _themes/yat/opencs.html _layouts/opencs.html
@cp _themes/yat/page.html _layouts/page.html
@cp _themes/yat/post.html _layouts/post.html
serve-hydejack: use-hydejack clean
@make serve-current
build-tactile: use-tactile build-current
# Serve with selected theme
serve-minima: use-minima clean
@make serve-current
serve-text: use-text clean
@make serve-current
serve-cayman: use-cayman clean
@make serve-current
serve-so-simple: use-so-simple clean
@make serve-current
serve-yat: use-yat clean
@make serve-current
# General serve target (uses whatever is in _config.yml/Gemfile)
serve-current: stop convert split-courses
@echo "Starting server with current config/Gemfile..."
@bundle install > $(LOG_FILE) 2>&1 && bundle exec jekyll serve -H $(HOST) -P $(PORT) >> $(LOG_FILE) 2>&1 & \
PID=$$!; \
echo "Server PID: $$PID"
@make wait-for-server
# Build with selected theme
build-minima: use-minima build-current
build-text: use-text build-current
build-cayman: use-cayman build-current
build-so-simple: use-so-simple build-current
build-yat: use-yat build-current
build-current: clean convert split-courses
@bundle install
@bundle exec jekyll clean
@bundle exec jekyll build
# General serve/build for whatever is current
serve: serve-current
build: build-current
# Multi-course file splitting
split-courses:
@echo " ------ Splitting multi-course files... -------"
@python3 scripts/split_multi_course_files.py
clean-courses:
@echo "🧹 Cleaning course-specific files..."
@python3 scripts/split_multi_course_files.py clean
# Notebook and DOCX conversion
convert: $(MARKDOWN_FILES) convert-docx
$(DESTINATION_DIRECTORY)/%_IPYNB_2_.md: _notebooks/%.ipynb
@mkdir -p $(@D)
@python3 -c "from scripts.convert_notebooks import convert_notebooks; convert_notebooks()"
# Single notebook conversion (faster for development)
convert-single:
@if [ -z "$(NOTEBOOK_FILE)" ]; then \
echo "Error: NOTEBOOK_FILE variable not set"; \
exit 1; \
fi
@echo "Converting: $(NOTEBOOK_FILE)"
@python3 scripts/convert_notebooks.py "$(NOTEBOOK_FILE)"
# DOCX conversion
convert-docx:
@if [ -d "_docx" ] && [ "$(shell ls -A _docx 2>/dev/null)" ]; then \
python3 scripts/convert_docx.py; \
else \
echo "No DOCX files found in _docx directory"; \
fi
# DOCX conversion for specific config change
convert-docx-config:
@if [ -d "_docx" ] && [ "$(shell ls -A _docx 2>/dev/null)" ]; then \
if [ -n "$(CONFIG_FILE)" ]; then \
echo "🔧 Config file changed: $(CONFIG_FILE)"; \
python3 scripts/convert_docx.py --config-changed "$(CONFIG_FILE)"; \
else \
python3 scripts/convert_docx.py; \
fi; \
else \
echo "No DOCX files found in _docx directory"; \
fi
# Clean only DOCX-converted files (safe)
clean-docx:
@echo "Cleaning DOCX-converted files..."
@find _posts -type f -name '*_DOCX_.md' -exec rm {} + 2>/dev/null || true
@echo "Cleaning extracted DOCX images..."
@rm -rf images/docx/*.png images/docx/*.jpg images/docx/*.jpeg images/docx/*.gif 2>/dev/null || true
@echo "Cleaning DOCX index page..."
@rm -f docx-index.md 2>/dev/null || true
@echo "DOCX cleanup complete"
# Color mapping
update-colors:
@echo "Updating local color map..."
@python3 scripts/update_color_map.py
@echo "Color map updated successfully"
@echo "Generated files:"
@echo " - _sass/root-color-map.scss"
@echo " - local-color-usage-report.md"
@echo " - colors.json"
# Update colors and preview
update-colors-preview: update-colors
@echo "Starting server to preview color changes..."
@make serve-current
clean: stop
@echo "Cleaning converted IPYNB files..."
@find _posts -type f -name '*_IPYNB_2_.md' -exec rm {} +
@echo "Cleaning Github Issue files..."
@find _posts -type f -name '*_GithubIssue_.md' -exec rm {} +
@echo "Cleaning converted DOCX files..."
@find _posts -type f -name '*_DOCX_.md' -exec rm {} + 2>/dev/null || true
@echo "Cleaning course-specific files..."
@make clean-courses
@echo "Cleaning extracted DOCX images..."
@rm -rf images/docx/*.png images/docx/*.jpg images/docx/*.jpeg images/docx/*.gif 2>/dev/null || true
@echo "Cleaning DOCX index page..."
@rm -f docx-index.md 2>/dev/null || true
@echo "Removing empty directories in _posts..."
@while [ $$(find _posts -type d -empty | wc -l) -gt 0 ]; do \
find _posts -type d -empty -exec rmdir {} +; \
done
@echo "Removing _site directory..."
@rm -rf _site
stop:
@echo "Stopping server..."
@@lsof -ti :$(PORT) | xargs kill >/dev/null 2>&1 || true
@echo "Stopping logging process..."
@@ps aux | awk -v log_file=$(LOG_FILE) '$$0 ~ "tail -f " log_file { print $$2 }' | xargs kill >/dev/null 2>&1 || true
@echo "Stopping notebook watcher..."
@@ps aux | grep "watch-notebooks" | grep -v grep | awk '{print $$2}' | xargs kill >/dev/null 2>&1 || true
@@ps aux | grep "find _notebooks" | grep -v grep | awk '{print $$2}' | xargs kill >/dev/null 2>&1 || true
@rm -f $(LOG_FILE) /tmp/.notebook_watch_marker /tmp/.jekyll_regenerating
reload:
@make stop
@make
refresh:
@make stop
@make clean
@make
# Development mode: clean start with incremental builds and single-file conversion
# Skips full notebook conversion for ~20 second startup, converts individual files on save
dev: stop clean start-server-fast
@make watch-notebooks &
@make watch-files
# Watch notebooks directory for changes (since Jekyll excludes _notebooks)
watch-notebooks:
@echo "Watching _notebooks for changes..."
@while true; do \
find _notebooks -name '*.ipynb' -newer /tmp/.notebook_watch_marker 2>/dev/null | while read notebook; do \
echo "Notebook changed: $$notebook"; \
make convert-single NOTEBOOK_FILE="$$notebook"; \
done; \
touch /tmp/.notebook_watch_marker; \
sleep 2; \
done
# Start server without conversion (for dev mode)
start-server-fast:
@echo "Starting development server (fast mode)..."
@echo " - Skipping full notebook conversion"
@echo " - Incremental builds enabled"
@touch /tmp/.notebook_watch_marker
@bundle install > $(LOG_FILE) 2>&1 && bundle exec jekyll serve -H $(HOST) -P $(PORT) --incremental >> $(LOG_FILE) 2>&1 & \
PID=$$!; \
echo "Server PID: $$PID"
@make wait-for-server
# Common server wait logic
wait-for-server:
@until [ -f $(LOG_FILE) ]; do sleep 1; done
@for ((COUNTER = 0; ; COUNTER++)); do \
if grep -q "Server address:" $(LOG_FILE); then \
echo "Server started in $$COUNTER seconds"; \
grep "Server address:" $(LOG_FILE); \
break; \
fi; \
if [ $$COUNTER -eq 300 ]; then \
echo "Server timed out after $$COUNTER seconds."; \
echo "Review errors from $(LOG_FILE)."; \
cat $(LOG_FILE); \
exit 1; \
fi; \
if [ $$COUNTER -gt 5 ] && grep -E -qi "\bfatal\b|\bexception\b" $(LOG_FILE); then \
echo "Fatal error detected during startup!"; \
cat $(LOG_FILE); \
exit 1; \
fi; \
if [ $$((COUNTER % 10)) -eq 0 ] && [ $$COUNTER -gt 0 ]; then \
echo "Still starting... ($$COUNTER seconds elapsed)"; \
fi; \
sleep 1; \
done
# Single DOCX file conversion (for dev mode)
convert-docx-single:
@if [ -z "$(DOCX_FILE)" ]; then \
echo "Error: DOCX_FILE variable not set"; \
exit 1; \
fi
@echo "Converting: $(DOCX_FILE)"
@python3 scripts/convert_docx.py --single "$(DOCX_FILE)" 2>/dev/null || python3 scripts/convert_docx.py
docx-only: convert-docx
@echo "DOCX conversion complete - ready for preview"
preview-docx: clean-docx convert-docx
@echo "Converting DOCX and starting preview server..."
@make serve-current
help:
@echo "Available Makefile commands:"
@echo ""
@echo "Theme Serve Commands:"
@echo " make serve-minima - Switch to Minima and serve"
@echo " make serve-text - Switch to TeXt and serve"
@echo " make serve-cayman - Switch to Cayman and serve"
@echo " make serve-so-simple - Switch to So Simple and serve"
@echo " make serve-yat - Switch to Yat and serve"
@echo " make serve-hydejack - Switch to HydeJack and serve"
@echo ""
@echo "Theme Build Commands:"
@echo " make build-minima - Switch to Minima and build"
@echo " make build-text - Switch to TeXt and build"
@echo " make build-cayman - Switch to Cayman and build"
@echo " make build-so-simple - Switch to So Simple and build"
@echo " make build-yat - Switch to Yat and build"
@echo ""
@echo "Color Mapping Commands:"
@echo " make update-colors - Update local color map"
@echo " make update-colors-preview - Update colors and start server"
@echo ""
@echo "Server Commands:"
@echo " make - Full conversion, serve, and watch for file changes (auto-convert on save)"
@echo " make dev - Fast dev mode: clean start, no conversion, file watching, only convert files on save (quick)"
@echo " make serve - Convert and serve (no auto-convert watching)"
@echo " make build - Convert and build _site/ for deployment (no server)"
@echo " make stop - Stop server and logging"
@echo " make reload - Stop and restart server"
@echo " make refresh - Stop, clean, and restart server"
@echo ""
@echo "Conversion Commands:"
@echo " make convert - Convert notebooks and DOCX files"
@echo " make convert-docx - Convert DOCX files only"
@echo " make split-courses - Split multi-course files automatically"
@echo " make docx-only - Convert DOCX and prepare for preview"
@echo " make preview-docx - Clean, convert DOCX, and serve"
@echo ""
@echo "Cleanup Commands:"
@echo " make clean - Remove all generated files"
@echo " make clean-docx - Remove DOCX-generated files only"
@echo " make clean-courses - Remove course-specific split files only"
@echo ""
@echo "Diagnostic Commands:"
@echo " make convert-check - Check notebooks for conversion warnings"
@echo " make convert-fix - Fix identified notebook conversion issues"
# Notebook diagnostic and fix targets
convert-check:
@echo "Running conversion diagnostics..."
@echo "Checking for notebook conversion warnings or errors..."
@python3 scripts/check_conversion_warnings.py
convert-fix:
@echo "Running conversion fixes..."
@echo "️Fixing notebooks with known warnings or errors..."
@python3 scripts/check_conversion_warnings.py --fix