@kenjura/ursa 0.87.1 → 0.89.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +796 -737
- package/bin/ursa.js +7 -1
- package/meta/templates/default-template/index.html +1 -0
- package/package.json +1 -1
- package/src/dev.js +8 -4
- package/src/helper/__test__/hiddenPaths.test.js +106 -0
- package/src/helper/__test__/portUtils.test.js +100 -0
- package/src/helper/__test__/staticAssets.test.js +47 -0
- package/src/helper/automenu.js +43 -3
- package/src/helper/build/autoIndex.js +10 -5
- package/src/helper/contentHash.js +19 -0
- package/src/helper/hiddenPaths.js +62 -0
- package/src/helper/portUtils.js +71 -22
- package/src/helper/staticAssets.js +31 -0
- package/src/jobs/generate.js +1771 -1714
- package/src/serve.js +907 -906
package/src/jobs/generate.js
CHANGED
|
@@ -1,1715 +1,1772 @@
|
|
|
1
|
-
import { recurse } from "../helper/recursive-readdir.js";
|
|
2
|
-
import { copyFile, mkdir, readdir, readFile, stat } from "fs/promises";
|
|
3
|
-
import { getAutomenu } from "../helper/automenu.js";
|
|
4
|
-
import { filterAsync } from "../helper/filterAsync.js";
|
|
5
|
-
import { isDirectory } from "../helper/isDirectory.js";
|
|
6
|
-
import { isFolderHidden, clearConfigCache } from "../helper/folderConfig.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
46
|
-
import {
|
|
47
|
-
import {
|
|
48
|
-
import {
|
|
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
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
progress.
|
|
165
|
-
|
|
166
|
-
progress.logTimed(`Clean build:
|
|
167
|
-
await
|
|
168
|
-
progress.logTimed(`Clean
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
progress.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const
|
|
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
|
-
progress.
|
|
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
|
-
|
|
377
|
-
|
|
378
|
-
progress.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
//
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
for (
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
await
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
//
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
//
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
//
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
);
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
const
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
//
|
|
589
|
-
const
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
//
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
//
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
const
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
//
|
|
706
|
-
if
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
if (
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
//
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
if (
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
if (
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
const
|
|
840
|
-
const
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
:
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
//
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
//
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
const
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
//
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
progress.log(
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
const
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
const
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
if (
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
//
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
);
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
//
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
const
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
if (
|
|
1671
|
-
const
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
//
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1
|
+
import { recurse } from "../helper/recursive-readdir.js";
|
|
2
|
+
import { copyFile, mkdir, readdir, readFile, stat } from "fs/promises";
|
|
3
|
+
import { getAutomenu } from "../helper/automenu.js";
|
|
4
|
+
import { filterAsync } from "../helper/filterAsync.js";
|
|
5
|
+
import { isDirectory } from "../helper/isDirectory.js";
|
|
6
|
+
import { isFolderHidden, clearConfigCache } from "../helper/folderConfig.js";
|
|
7
|
+
import { isHiddenOrSystemPath } from "../helper/hiddenPaths.js";
|
|
8
|
+
import { IMAGE_EXTENSIONS, isMedia } from "../helper/staticAssets.js";
|
|
9
|
+
import {
|
|
10
|
+
extractMetadata,
|
|
11
|
+
extractRawMetadata,
|
|
12
|
+
isMetadataOnly,
|
|
13
|
+
getAutoIndexConfig,
|
|
14
|
+
} from "../helper/metadataExtractor.js";
|
|
15
|
+
import { injectFrontmatterTable } from "../helper/frontmatterTable.js";
|
|
16
|
+
import {
|
|
17
|
+
hashContent,
|
|
18
|
+
loadHashCache,
|
|
19
|
+
saveHashCache,
|
|
20
|
+
needsRegeneration,
|
|
21
|
+
outputsExist,
|
|
22
|
+
updateHash,
|
|
23
|
+
getUrsaDir,
|
|
24
|
+
} from "../helper/contentHash.js";
|
|
25
|
+
import {
|
|
26
|
+
buildValidPaths,
|
|
27
|
+
markInactiveLinks,
|
|
28
|
+
resolveRelativeUrls,
|
|
29
|
+
} from "../helper/linkValidator.js";
|
|
30
|
+
import { getAndIncrementBuildId, loadContentTimestamps, saveContentTimestamps, updateContentTimestamp } from "../helper/ursaConfig.js";
|
|
31
|
+
import { extractSections } from "../helper/sectionExtractor.js";
|
|
32
|
+
import { renderFile, renderFileAsync, terminateParserPool } from "../helper/fileRenderer.js";
|
|
33
|
+
import { buildReactRuntime } from "../helper/mdxRenderer.js";
|
|
34
|
+
import { findStyleCss, findAllStyleCss } from "../helper/findStyleCss.js";
|
|
35
|
+
import { findScriptJs, findAllScriptJs } from "../helper/findScriptJs.js";
|
|
36
|
+
import { bundleMetaTemplateAssets, bundleDocumentCss, bundleDocumentJs, clearMetaBundleCache, generateSeparateCssTags, generateSeparateJsTags } from "../helper/assetBundler.js";
|
|
37
|
+
import { buildFullTextIndex, buildIncrementalIndex, loadIndexCache, saveIndexCache } from "../helper/fullTextIndex.js";
|
|
38
|
+
import { dependencyTracker, loadDependencyTracker, saveDependencyTracker } from "../helper/dependencyTracker.js";
|
|
39
|
+
import { CacheBustHashMap } from "../helper/build/cacheBust.js";
|
|
40
|
+
import { copy as copyDir, emptyDir, outputFile, remove } from "fs-extra";
|
|
41
|
+
import { basename, dirname, extname, join, parse, resolve } from "path";
|
|
42
|
+
import { URL } from "url";
|
|
43
|
+
import o2x from "object-to-xml";
|
|
44
|
+
import { existsSync } from "fs";
|
|
45
|
+
import { createWhitelistFilter } from "../helper/whitelistFilter.js";
|
|
46
|
+
import { processAllImages, transformImageTags, clearImageCache, copyAllImagesFast } from "../helper/imageProcessor.js";
|
|
47
|
+
import { extractImageReferences } from "../helper/imageExtractor.js";
|
|
48
|
+
import { checkFileSize, readFileStreaming, formatFileSize } from "../helper/streamingReader.js";
|
|
49
|
+
import { generateBreadcrumbs } from "../helper/breadcrumbs.js";
|
|
50
|
+
import {
|
|
51
|
+
loadNavCache,
|
|
52
|
+
saveNavCache,
|
|
53
|
+
hashFileList,
|
|
54
|
+
hashFileStats,
|
|
55
|
+
isNavCacheValid,
|
|
56
|
+
createNavCacheEntry,
|
|
57
|
+
restoreMap,
|
|
58
|
+
} from "../helper/build/navCache.js";
|
|
59
|
+
|
|
60
|
+
// Import build helpers from organized modules
|
|
61
|
+
import {
|
|
62
|
+
generateCacheBustTimestamp,
|
|
63
|
+
addTimestampToCssUrls,
|
|
64
|
+
addTimestampToHtmlStaticRefs,
|
|
65
|
+
processBatched,
|
|
66
|
+
ProgressReporter,
|
|
67
|
+
watchModeCache,
|
|
68
|
+
clearWatchCache as clearWatchCacheBase,
|
|
69
|
+
toTitleCase,
|
|
70
|
+
parseExcludeOption,
|
|
71
|
+
createExcludeFilter,
|
|
72
|
+
addTrailingSlash,
|
|
73
|
+
getTemplates,
|
|
74
|
+
getMenu,
|
|
75
|
+
findAllCustomMenus,
|
|
76
|
+
getCustomMenuForFile,
|
|
77
|
+
getTransformedMetadata,
|
|
78
|
+
getFooter,
|
|
79
|
+
getUrsaMetadata,
|
|
80
|
+
generateAutoIndices,
|
|
81
|
+
generateAutoIndexHtmlFromSource,
|
|
82
|
+
copyMetaAssets,
|
|
83
|
+
} from "../helper/build/index.js";
|
|
84
|
+
import { getProfiler } from "../helper/build/profiler.js";
|
|
85
|
+
import { reconcileAll, isInsideTemplatesFolder } from "../helper/documentTemplates.js";
|
|
86
|
+
|
|
87
|
+
// Concurrency limiter for batch processing to avoid memory exhaustion
|
|
88
|
+
const BATCH_SIZE = parseInt(process.env.URSA_BATCH_SIZE || '50', 10);
|
|
89
|
+
|
|
90
|
+
// Cache for CSS path lookups to avoid repeated filesystem walks
|
|
91
|
+
const cssPathCache = new Map();
|
|
92
|
+
|
|
93
|
+
// Cache for script path lookups to avoid repeated filesystem walks
|
|
94
|
+
const scriptPathCache = new Map();
|
|
95
|
+
|
|
96
|
+
// Cache for document-level CSS/JS bundle paths to avoid re-bundling identical sets
|
|
97
|
+
const docBundleCache = new Map();
|
|
98
|
+
|
|
99
|
+
// Wrapper for clearWatchCache that passes cssPathCache and scriptPathCache
|
|
100
|
+
export function clearWatchCache() {
|
|
101
|
+
clearWatchCacheBase(cssPathCache);
|
|
102
|
+
scriptPathCache.clear();
|
|
103
|
+
docBundleCache.clear();
|
|
104
|
+
clearMetaBundleCache();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Clear just the script-related caches (for when script.js changes)
|
|
108
|
+
export function clearScriptCache() {
|
|
109
|
+
scriptPathCache.clear();
|
|
110
|
+
// Clear all JS bundle cache entries
|
|
111
|
+
for (const key of docBundleCache.keys()) {
|
|
112
|
+
if (key.startsWith('js:')) {
|
|
113
|
+
docBundleCache.delete(key);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Clear just the CSS-related caches (for when style.css changes)
|
|
119
|
+
export function clearStyleCache() {
|
|
120
|
+
cssPathCache.clear();
|
|
121
|
+
// Clear all CSS bundle cache entries
|
|
122
|
+
for (const key of docBundleCache.keys()) {
|
|
123
|
+
if (key.startsWith('css:')) {
|
|
124
|
+
docBundleCache.delete(key);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const progress = new ProgressReporter();
|
|
130
|
+
|
|
131
|
+
const DEFAULT_TEMPLATE_NAME =
|
|
132
|
+
process.env.DEFAULT_TEMPLATE_NAME ?? "default-template";
|
|
133
|
+
|
|
134
|
+
export async function generate({
|
|
135
|
+
_source = join(process.cwd(), "."),
|
|
136
|
+
_meta = join(process.cwd(), "meta"),
|
|
137
|
+
_output = join(process.cwd(), "build"),
|
|
138
|
+
_whitelist = null,
|
|
139
|
+
_exclude = null,
|
|
140
|
+
_incremental = false, // Legacy flag, now ignored (always incremental)
|
|
141
|
+
_clean = false, // When true, ignore cache and regenerate all files
|
|
142
|
+
_deferImages = false, // When true, copy images without processing, return promise for background processing
|
|
143
|
+
_deferSearchIndex = false, // When true, return promise for search index building (for faster startup)
|
|
144
|
+
} = {}) {
|
|
145
|
+
// Initialize profiler for this build
|
|
146
|
+
const profiler = getProfiler(true);
|
|
147
|
+
|
|
148
|
+
console.log({ _source, _meta, _output, _whitelist, _exclude, _clean, _deferImages, _deferSearchIndex });
|
|
149
|
+
const source = resolve(_source) + "/";
|
|
150
|
+
const meta = resolve(_meta);
|
|
151
|
+
const output = resolve(_output) + "/";
|
|
152
|
+
console.log({ source, meta, output });
|
|
153
|
+
|
|
154
|
+
// Generate cache-busting timestamp for this build
|
|
155
|
+
const cacheBustTimestamp = generateCacheBustTimestamp();
|
|
156
|
+
const cacheBustHashes = new CacheBustHashMap();
|
|
157
|
+
progress.logTimed(`Cache-bust timestamp: ${cacheBustTimestamp}`);
|
|
158
|
+
|
|
159
|
+
// Initialize dependency tracker for this build
|
|
160
|
+
dependencyTracker.init(source);
|
|
161
|
+
|
|
162
|
+
// Clear output directory and cache when --clean is specified
|
|
163
|
+
if (_clean) {
|
|
164
|
+
progress.startTimer('Clean');
|
|
165
|
+
const ursaDir = getUrsaDir(source);
|
|
166
|
+
progress.logTimed(`Clean build: deleting cache folder ${ursaDir}`);
|
|
167
|
+
await remove(ursaDir);
|
|
168
|
+
progress.logTimed(`Clean build: clearing output directory ${output}`);
|
|
169
|
+
await emptyDir(output);
|
|
170
|
+
progress.logTimed(`Clean complete [${progress.stopTimer('Clean')}]`);
|
|
171
|
+
} else {
|
|
172
|
+
// Warm start: reload persisted dependency registrations so hash-skipped
|
|
173
|
+
// documents keep their edges (current-run registrations take precedence)
|
|
174
|
+
const loaded = await loadDependencyTracker(source);
|
|
175
|
+
if (loaded) {
|
|
176
|
+
const stats = dependencyTracker.getStats();
|
|
177
|
+
progress.logTimed(`Dependency graph loaded: ${stats.totalDocuments} documents, ${stats.uniqueFiles} dependencies`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Phase: Scan source files
|
|
182
|
+
profiler.startPhase('Scan source files');
|
|
183
|
+
progress.startTimer('Scan');
|
|
184
|
+
const allSourceFilenamesUnfiltered = await recurse(source, [() => false]);
|
|
185
|
+
progress.logTimed(`Scanned ${allSourceFilenamesUnfiltered.length} files [${progress.stopTimer('Scan')}]`);
|
|
186
|
+
profiler.endPhase('Scan source files');
|
|
187
|
+
|
|
188
|
+
// Phase: Filter and classify files
|
|
189
|
+
profiler.startPhase('Filter & classify');
|
|
190
|
+
progress.startTimer('Filter');
|
|
191
|
+
|
|
192
|
+
// Apply include filter (existing functionality)
|
|
193
|
+
const includeFilter = process.env.INCLUDE_FILTER
|
|
194
|
+
? (fileName) => fileName.match(process.env.INCLUDE_FILTER)
|
|
195
|
+
: Boolean;
|
|
196
|
+
let allSourceFilenames = allSourceFilenamesUnfiltered.filter(includeFilter);
|
|
197
|
+
|
|
198
|
+
// Apply exclude filter if specified
|
|
199
|
+
if (_exclude) {
|
|
200
|
+
const excludedPaths = await parseExcludeOption(_exclude, source);
|
|
201
|
+
const excludeFilter = createExcludeFilter(excludedPaths, source);
|
|
202
|
+
const beforeCount = allSourceFilenames.length;
|
|
203
|
+
allSourceFilenames = allSourceFilenames.filter(excludeFilter);
|
|
204
|
+
progress.logTimed(`Exclude filter applied: ${beforeCount - allSourceFilenames.length} files excluded`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Apply whitelist filter if specified
|
|
208
|
+
if (_whitelist) {
|
|
209
|
+
const whitelistFilter = await createWhitelistFilter(_whitelist, source);
|
|
210
|
+
allSourceFilenames = allSourceFilenames.filter(whitelistFilter);
|
|
211
|
+
progress.logTimed(`Whitelist applied: ${allSourceFilenames.length} files after filtering`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Clear config cache at start of generation to pick up any changes
|
|
215
|
+
clearConfigCache();
|
|
216
|
+
|
|
217
|
+
// Helper to check if a path is inside a config-hidden folder
|
|
218
|
+
const isInHiddenFolder = (filePath) => {
|
|
219
|
+
const dir = dirname(filePath);
|
|
220
|
+
return isFolderHidden(dir, source);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// read all articles, process them, copy them to build
|
|
224
|
+
const articleExtensions = /\.(md|mdx|txt|yml)$/;
|
|
225
|
+
// Hidden/system folders are judged RELATIVE to the docroot — see
|
|
226
|
+
// helper/hiddenPaths.js for why testing the absolute path silently produces
|
|
227
|
+
// an empty site when the checkout lives under a dot-directory.
|
|
228
|
+
const isHiddenOrSystem = (filename) => isHiddenOrSystemPath(filename, source);
|
|
229
|
+
const allSourceFilenamesThatAreArticles = allSourceFilenames.filter(
|
|
230
|
+
(filename) => filename.match(articleExtensions) && !isHiddenOrSystem(filename) && !isInHiddenFolder(filename)
|
|
231
|
+
);
|
|
232
|
+
const allSourceFilenamesThatAreDirectories = (await filterAsync(
|
|
233
|
+
allSourceFilenames,
|
|
234
|
+
(filename) => isDirectory(filename)
|
|
235
|
+
)).filter((filename) => !isHiddenOrSystem(filename) && !isFolderHidden(filename, source));
|
|
236
|
+
|
|
237
|
+
// Build set of existing HTML files in source directory (these should not be overwritten)
|
|
238
|
+
const htmlExtensions = /\.html$/;
|
|
239
|
+
const existingHtmlFiles = new Set(
|
|
240
|
+
allSourceFilenames
|
|
241
|
+
.filter(f => f.match(htmlExtensions) && !isHiddenOrSystem(f))
|
|
242
|
+
.map(f => f.replace(source, '')) // Store relative paths for easy lookup
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
progress.logTimed(`Classified: ${allSourceFilenamesThatAreArticles.length} articles, ${allSourceFilenamesThatAreDirectories.length} dirs, ${existingHtmlFiles.size} HTML [${progress.stopTimer('Filter')}]`);
|
|
246
|
+
profiler.endPhase('Filter & classify');
|
|
247
|
+
|
|
248
|
+
// Drop persisted dependency registrations for documents that no longer
|
|
249
|
+
// exist (or are excluded), so stale entries don't accumulate across runs
|
|
250
|
+
dependencyTracker.prune(new Set(allSourceFilenamesThatAreArticles));
|
|
251
|
+
|
|
252
|
+
// Phase: Document template reconciliation
|
|
253
|
+
// Must run BEFORE article processing so that any template-driven changes
|
|
254
|
+
// to source .md files are picked up during rendering.
|
|
255
|
+
profiler.startPhase('Template reconciliation');
|
|
256
|
+
progress.startTimer('Templates');
|
|
257
|
+
const templateReconciliation = await reconcileAll(
|
|
258
|
+
allSourceFilenamesThatAreArticles,
|
|
259
|
+
allSourceFilenamesUnfiltered, // templates live in _templates which is filtered out of articles
|
|
260
|
+
source
|
|
261
|
+
);
|
|
262
|
+
if (templateReconciliation.updated > 0 || templateReconciliation.conflicts > 0 || templateReconciliation.initialized > 0) {
|
|
263
|
+
progress.logTimed(
|
|
264
|
+
`📄 Document templates: ${templateReconciliation.initialized} initialized, ` +
|
|
265
|
+
`${templateReconciliation.updated} auto-merged, ` +
|
|
266
|
+
`${templateReconciliation.conflicts} conflicts, ` +
|
|
267
|
+
`${templateReconciliation.unchanged} unchanged, ` +
|
|
268
|
+
`${templateReconciliation.errors} errors`
|
|
269
|
+
);
|
|
270
|
+
if (templateReconciliation.conflicts > 0) {
|
|
271
|
+
console.warn(`\n⚠️ Template conflicts require manual resolution:`);
|
|
272
|
+
for (const msg of templateReconciliation.messages) {
|
|
273
|
+
if (msg.includes('Conflict')) console.warn(` ${msg}`);
|
|
274
|
+
}
|
|
275
|
+
console.warn('');
|
|
276
|
+
}
|
|
277
|
+
if (templateReconciliation.errors > 0) {
|
|
278
|
+
for (const msg of templateReconciliation.messages) {
|
|
279
|
+
if (msg.includes('Error') || msg.includes('not found')) console.warn(` ⚠️ ${msg}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
progress.logTimed(`Document templates processed [${progress.stopTimer('Templates')}]`);
|
|
284
|
+
profiler.endPhase('Template reconciliation');
|
|
285
|
+
|
|
286
|
+
// Phase: Build navigation and metadata
|
|
287
|
+
profiler.startPhase('Build navigation');
|
|
288
|
+
progress.startTimer('Navigation');
|
|
289
|
+
|
|
290
|
+
// Check if we can use cached navigation
|
|
291
|
+
let validPaths, templates, menu, menuData, customMenus, footer, buildId;
|
|
292
|
+
let navCacheUsed = false;
|
|
293
|
+
|
|
294
|
+
if (!_clean) {
|
|
295
|
+
const fileListHash = hashFileList(allSourceFilenames);
|
|
296
|
+
const fileStatsHash = await hashFileStats(allSourceFilenames);
|
|
297
|
+
const navCache = await loadNavCache(source);
|
|
298
|
+
|
|
299
|
+
if (isNavCacheValid(navCache, fileListHash, fileStatsHash)) {
|
|
300
|
+
// Use cached navigation data
|
|
301
|
+
navCacheUsed = true;
|
|
302
|
+
validPaths = restoreMap(navCache.validPaths);
|
|
303
|
+
menuData = navCache.menuData;
|
|
304
|
+
menu = navCache.menuHtml;
|
|
305
|
+
customMenus = restoreMap(navCache.customMenus);
|
|
306
|
+
|
|
307
|
+
// Templates and footer still need to be loaded (they depend on meta directory)
|
|
308
|
+
templates = await getTemplates(meta);
|
|
309
|
+
buildId = getAndIncrementBuildId(resolve(_source));
|
|
310
|
+
footer = await getFooter(source, _source, buildId);
|
|
311
|
+
|
|
312
|
+
progress.logTimed(`Navigation loaded from cache: ${validPaths.size} paths, ${customMenus.size} custom menus [${progress.stopTimer('Navigation')}]`);
|
|
313
|
+
} else {
|
|
314
|
+
// Cache miss - build navigation from scratch
|
|
315
|
+
validPaths = buildValidPaths(allSourceFilenamesThatAreArticles, source, allSourceFilenamesThatAreDirectories);
|
|
316
|
+
templates = await getTemplates(meta);
|
|
317
|
+
|
|
318
|
+
const menuResult = await getMenu(allSourceFilenames, source, validPaths);
|
|
319
|
+
menu = menuResult.html;
|
|
320
|
+
menuData = menuResult.menuData;
|
|
321
|
+
|
|
322
|
+
customMenus = findAllCustomMenus(allSourceFilenames, source);
|
|
323
|
+
buildId = getAndIncrementBuildId(resolve(_source));
|
|
324
|
+
footer = await getFooter(source, _source, buildId);
|
|
325
|
+
|
|
326
|
+
// Save to cache for next run
|
|
327
|
+
const cacheEntry = createNavCacheEntry(
|
|
328
|
+
fileListHash,
|
|
329
|
+
fileStatsHash,
|
|
330
|
+
menuData,
|
|
331
|
+
menu,
|
|
332
|
+
Array.from(validPaths.entries()),
|
|
333
|
+
Array.from(customMenus.entries())
|
|
334
|
+
);
|
|
335
|
+
await saveNavCache(source, cacheEntry);
|
|
336
|
+
|
|
337
|
+
progress.logTimed(`Navigation built: ${validPaths.size} paths, ${customMenus.size} custom menus [${progress.stopTimer('Navigation')}]`);
|
|
338
|
+
}
|
|
339
|
+
} else {
|
|
340
|
+
// Clean build - ignore cache
|
|
341
|
+
validPaths = buildValidPaths(allSourceFilenamesThatAreArticles, source, allSourceFilenamesThatAreDirectories);
|
|
342
|
+
templates = await getTemplates(meta);
|
|
343
|
+
|
|
344
|
+
const menuResult = await getMenu(allSourceFilenames, source, validPaths);
|
|
345
|
+
menu = menuResult.html;
|
|
346
|
+
menuData = menuResult.menuData;
|
|
347
|
+
|
|
348
|
+
customMenus = findAllCustomMenus(allSourceFilenames, source);
|
|
349
|
+
buildId = getAndIncrementBuildId(resolve(_source));
|
|
350
|
+
footer = await getFooter(source, _source, buildId);
|
|
351
|
+
|
|
352
|
+
progress.logTimed(`Navigation built (clean): ${validPaths.size} paths, ${customMenus.size} custom menus [${progress.stopTimer('Navigation')}]`);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
profiler.endPhase('Build navigation');
|
|
356
|
+
|
|
357
|
+
// Build the _ursa_metadata embedded in every generated JSON file (ursa + doc repo versions)
|
|
358
|
+
const ursaMetadata = await getUrsaMetadata(_source);
|
|
359
|
+
|
|
360
|
+
// Phase: Load cache
|
|
361
|
+
profiler.startPhase('Load cache');
|
|
362
|
+
progress.startTimer('Cache');
|
|
363
|
+
|
|
364
|
+
// Load content hash cache from .ursa folder in source directory
|
|
365
|
+
let hashCache = new Map();
|
|
366
|
+
if (!_clean) {
|
|
367
|
+
hashCache = await loadHashCache(source);
|
|
368
|
+
progress.logTimed(`Loaded ${hashCache.size} cached hashes [${progress.stopTimer('Cache')}]`);
|
|
369
|
+
} else {
|
|
370
|
+
progress.logTimed(`Clean build: ignoring cached hashes`);
|
|
371
|
+
progress.stopTimer('Cache');
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Load content timestamps from .ursa.json (survives --clean)
|
|
375
|
+
// These track when content actually changed, not filesystem mtime
|
|
376
|
+
const contentTimestamps = loadContentTimestamps(source);
|
|
377
|
+
const buildTimestamp = Date.now();
|
|
378
|
+
progress.logTimed(`Loaded ${contentTimestamps.size} content timestamps`);
|
|
379
|
+
profiler.endPhase('Load cache');
|
|
380
|
+
|
|
381
|
+
// Phase: Copy meta/public files
|
|
382
|
+
profiler.startPhase('Copy meta files');
|
|
383
|
+
progress.startTimer('Meta');
|
|
384
|
+
|
|
385
|
+
// create public folder
|
|
386
|
+
const pub = join(output, "public");
|
|
387
|
+
await mkdir(pub, { recursive: true });
|
|
388
|
+
|
|
389
|
+
// Copy meta assets with new template folder structure
|
|
390
|
+
const { copiedFiles, orphanedFiles } = await copyMetaAssets(meta, pub);
|
|
391
|
+
|
|
392
|
+
// Warn about orphaned files in meta that aren't part of any template
|
|
393
|
+
if (orphanedFiles.length > 0) {
|
|
394
|
+
console.warn(`\n⚠️ Warning: Found ${orphanedFiles.length} orphaned file(s) in meta directory:`);
|
|
395
|
+
console.warn(` These files are not in meta/templates/ or meta/shared/ and won't be included:`);
|
|
396
|
+
for (const file of orphanedFiles.slice(0, 10)) {
|
|
397
|
+
console.warn(` - ${file}`);
|
|
398
|
+
}
|
|
399
|
+
if (orphanedFiles.length > 10) {
|
|
400
|
+
console.warn(` ... and ${orphanedFiles.length - 10} more`);
|
|
401
|
+
}
|
|
402
|
+
console.warn(` Move them to meta/templates/{templateName}/ or meta/shared/ to include them.\n`);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Bundle meta template assets (CSS + JS) into single files per template
|
|
406
|
+
// This must happen after copying meta to public but before cache-busting
|
|
407
|
+
templates = await bundleMetaTemplateAssets(templates, meta, pub, { minify: true, sourcemap: false });
|
|
408
|
+
progress.logTimed(`Meta template assets bundled`);
|
|
409
|
+
|
|
410
|
+
// Build React runtime for MDX hydration (React 19 has no UMD, so we bundle locally)
|
|
411
|
+
await buildReactRuntime(pub);
|
|
412
|
+
|
|
413
|
+
// Process all CSS files in the entire output directory tree for cache-busting
|
|
414
|
+
const allOutputFiles = await recurse(output, [() => false]);
|
|
415
|
+
for (const cssFile of allOutputFiles.filter(f => f.endsWith('.css'))) {
|
|
416
|
+
const cssContent = await readFile(cssFile, 'utf8');
|
|
417
|
+
const processedCss = addTimestampToCssUrls(cssContent, cacheBustTimestamp);
|
|
418
|
+
await outputFile(cssFile, processedCss);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Process JS files in output for cache-busting fetch URLs
|
|
422
|
+
for (const jsFile of allOutputFiles.filter(f => f.endsWith('.js'))) {
|
|
423
|
+
let jsContent = await readFile(jsFile, 'utf8');
|
|
424
|
+
jsContent = jsContent.replace(
|
|
425
|
+
/fetch\(['"]([^'"\)]+\.(json))['"](?!\s*\+)/g,
|
|
426
|
+
`fetch('$1?v=${cacheBustTimestamp}'`
|
|
427
|
+
);
|
|
428
|
+
await outputFile(jsFile, jsContent);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
progress.logTimed(`Meta files copied and processed [${progress.stopTimer('Meta')}]`);
|
|
432
|
+
profiler.endPhase('Copy meta files');
|
|
433
|
+
|
|
434
|
+
// Track errors for error report
|
|
435
|
+
const errors = [];
|
|
436
|
+
|
|
437
|
+
// Search index: built incrementally during article processing (lighter memory footprint)
|
|
438
|
+
const searchIndex = [];
|
|
439
|
+
// Full-text index: collect documents for word-to-document mapping
|
|
440
|
+
const fullTextDocs = [];
|
|
441
|
+
// Recent activity: collect {title, url, mtime} for all articles, keep top 10 by mtime
|
|
442
|
+
const recentActivity = [];
|
|
443
|
+
// Track paths of documents that were regenerated (for incremental index updates)
|
|
444
|
+
const changedPaths = new Set();
|
|
445
|
+
// Directory index cache: only stores minimal data needed for directory indices
|
|
446
|
+
// Uses WeakRef-style approach - store only what's needed, clear as we go
|
|
447
|
+
const dirIndexCache = new Map();
|
|
448
|
+
|
|
449
|
+
// Track CSS files that have been copied to avoid duplicates
|
|
450
|
+
const copiedCssFiles = new Set();
|
|
451
|
+
|
|
452
|
+
// Identify all image files from the filtered source list
|
|
453
|
+
const imageExtensions = IMAGE_EXTENSIONS;
|
|
454
|
+
let allSourceFilenamesThatAreImages = allSourceFilenames.filter(
|
|
455
|
+
(filename) => filename.match(imageExtensions) && !isHiddenOrSystem(filename)
|
|
456
|
+
);
|
|
457
|
+
|
|
458
|
+
// When using a whitelist, also include images referenced by whitelisted documents
|
|
459
|
+
// This ensures that images used in whitelisted articles are processed even if not explicitly whitelisted
|
|
460
|
+
if (_whitelist) {
|
|
461
|
+
progress.logTimed('Scanning whitelisted articles for image references...');
|
|
462
|
+
const referencedImages = new Set();
|
|
463
|
+
|
|
464
|
+
for (const articlePath of allSourceFilenamesThatAreArticles) {
|
|
465
|
+
try {
|
|
466
|
+
const content = await readFile(articlePath, 'utf8');
|
|
467
|
+
const imageRefs = extractImageReferences(content, articlePath, source);
|
|
468
|
+
imageRefs.forEach(img => referencedImages.add(img));
|
|
469
|
+
} catch (e) {
|
|
470
|
+
// Ignore read errors - file might not exist or be unreadable
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Get all images from the unfiltered source list that are referenced
|
|
475
|
+
const allImagesUnfiltered = allSourceFilenamesUnfiltered.filter(
|
|
476
|
+
(filename) => filename.match(imageExtensions) && !isHiddenOrSystem(filename)
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
// Add referenced images that aren't already in the list
|
|
480
|
+
const additionalImages = allImagesUnfiltered.filter(
|
|
481
|
+
img => referencedImages.has(img) && !allSourceFilenamesThatAreImages.includes(img)
|
|
482
|
+
);
|
|
483
|
+
|
|
484
|
+
if (additionalImages.length > 0) {
|
|
485
|
+
progress.logTimed(`Found ${additionalImages.length} additional images referenced by whitelisted documents`);
|
|
486
|
+
allSourceFilenamesThatAreImages = [...allSourceFilenamesThatAreImages, ...additionalImages];
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// Phase: Process images
|
|
491
|
+
profiler.startPhase('Process images');
|
|
492
|
+
progress.startTimer('Images');
|
|
493
|
+
|
|
494
|
+
// Handle images based on deferred mode
|
|
495
|
+
let imageMap = new Map();
|
|
496
|
+
let deferredImageProcessingPromise = null;
|
|
497
|
+
|
|
498
|
+
if (_deferImages) {
|
|
499
|
+
// Fast mode: just copy images without processing, defer preview generation
|
|
500
|
+
progress.logTimed(`Copying ${allSourceFilenamesThatAreImages.length} images (preview generation deferred)...`);
|
|
501
|
+
await copyAllImagesFast(
|
|
502
|
+
allSourceFilenamesThatAreImages,
|
|
503
|
+
source,
|
|
504
|
+
output,
|
|
505
|
+
(current, total, path) => {
|
|
506
|
+
progress.status('Images (copy)', `${current}/${total} ${path}`);
|
|
507
|
+
}
|
|
508
|
+
);
|
|
509
|
+
progress.done('Images (copy)', `${allSourceFilenamesThatAreImages.length} copied (previews deferred)`);
|
|
510
|
+
profiler.endPhase('Process images');
|
|
511
|
+
|
|
512
|
+
// Create promise for background image processing (will be returned to caller)
|
|
513
|
+
deferredImageProcessingPromise = (async () => {
|
|
514
|
+
progress.logTimed(`\n🖼️ Starting deferred image preview generation...`);
|
|
515
|
+
const startTime = Date.now();
|
|
516
|
+
const processedImageMap = await processAllImages(
|
|
517
|
+
allSourceFilenamesThatAreImages,
|
|
518
|
+
source,
|
|
519
|
+
output,
|
|
520
|
+
(current, total, path) => {
|
|
521
|
+
progress.status('Images (previews)', `${current}/${total} ${path}`);
|
|
522
|
+
}
|
|
523
|
+
);
|
|
524
|
+
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
525
|
+
progress.done('Images (previews)', `${allSourceFilenamesThatAreImages.length} done (${processedImageMap.size} with previews) in ${elapsed}s`);
|
|
526
|
+
|
|
527
|
+
// Update the watch cache with the processed image map
|
|
528
|
+
watchModeCache.imageMap = processedImageMap;
|
|
529
|
+
|
|
530
|
+
return processedImageMap;
|
|
531
|
+
})();
|
|
532
|
+
} else {
|
|
533
|
+
// Normal mode: process all images FIRST to build the preview image map
|
|
534
|
+
// This is done before articles so we can transform img tags in the HTML
|
|
535
|
+
progress.logTimed(`Processing ${allSourceFilenamesThatAreImages.length} images for preview generation...`);
|
|
536
|
+
imageMap = await processAllImages(
|
|
537
|
+
allSourceFilenamesThatAreImages,
|
|
538
|
+
source,
|
|
539
|
+
output,
|
|
540
|
+
(current, total, path) => {
|
|
541
|
+
progress.status('Images', `${current}/${total} ${path}`);
|
|
542
|
+
}
|
|
543
|
+
);
|
|
544
|
+
progress.done('Images', `${allSourceFilenamesThatAreImages.length} done (${imageMap.size} with previews) [${progress.stopTimer('Images')}]`);
|
|
545
|
+
profiler.endPhase('Process images');
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// Phase: Process articles
|
|
549
|
+
profiler.startPhase('Process articles');
|
|
550
|
+
progress.startTimer('Articles');
|
|
551
|
+
|
|
552
|
+
// Track files that were regenerated (for incremental mode stats)
|
|
553
|
+
let regeneratedCount = 0;
|
|
554
|
+
let skippedCount = 0;
|
|
555
|
+
let processedCount = 0;
|
|
556
|
+
const totalArticles = allSourceFilenamesThatAreArticles.length;
|
|
557
|
+
|
|
558
|
+
progress.logTimed(`Processing ${totalArticles} articles in batches of ${BATCH_SIZE}...`);
|
|
559
|
+
|
|
560
|
+
// Single pass: process all articles with batched concurrency to limit memory usage
|
|
561
|
+
await processBatched(allSourceFilenamesThatAreArticles, async (file) => {
|
|
562
|
+
try {
|
|
563
|
+
processedCount++;
|
|
564
|
+
const shortFile = file.replace(source, '');
|
|
565
|
+
progress.status('Articles', `${processedCount}/${totalArticles} ${shortFile}`);
|
|
566
|
+
|
|
567
|
+
// Use streaming for large files to reduce memory pressure
|
|
568
|
+
const { size: fileSize, useStreaming } = await checkFileSize(file);
|
|
569
|
+
let rawBody;
|
|
570
|
+
if (useStreaming) {
|
|
571
|
+
rawBody = await readFileStreaming(file, 'utf8');
|
|
572
|
+
progress.log(`📄 Streaming large file ${shortFile} (${formatFileSize(fileSize)})`);
|
|
573
|
+
} else {
|
|
574
|
+
rawBody = await readFile(file, "utf8");
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
const type = parse(file).ext;
|
|
578
|
+
const ext = extname(file);
|
|
579
|
+
const base = basename(file, ext);
|
|
580
|
+
const dir = addTrailingSlash(dirname(file)).replace(source, "");
|
|
581
|
+
|
|
582
|
+
// Calculate output paths for this file
|
|
583
|
+
const outputFilename = file
|
|
584
|
+
.replace(source, output)
|
|
585
|
+
.replace(parse(file).ext, ".html");
|
|
586
|
+
const url = '/' + outputFilename.replace(output, '');
|
|
587
|
+
|
|
588
|
+
// Generate URL path relative to output (for search index)
|
|
589
|
+
const relativePath = file.replace(source, '').replace(/\.(md|mdx|txt|yml)$/, '.html');
|
|
590
|
+
const searchUrl = relativePath.startsWith('/') ? relativePath : '/' + relativePath;
|
|
591
|
+
|
|
592
|
+
// Generate title from filename (in title case)
|
|
593
|
+
// For index/home files, use parent folder name instead
|
|
594
|
+
const titleBase = (base === 'index' || base === 'home') ? basename(dirname(file)) : base;
|
|
595
|
+
const title = toTitleCase(titleBase || base);
|
|
596
|
+
|
|
597
|
+
// Always add to search index (lightweight: title + path only, content added lazily)
|
|
598
|
+
searchIndex.push({
|
|
599
|
+
title: title,
|
|
600
|
+
path: relativePath,
|
|
601
|
+
url: searchUrl,
|
|
602
|
+
content: '' // Content excerpts built lazily to save memory
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
// Add document to full-text index (uses raw markdown content)
|
|
606
|
+
fullTextDocs.push({
|
|
607
|
+
path: relativePath,
|
|
608
|
+
title: title,
|
|
609
|
+
content: rawBody
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
// Collect timestamp for recent activity tracking
|
|
613
|
+
// Use stored content timestamp if available, otherwise fall back to file mtime
|
|
614
|
+
// Content timestamps track when content actually changed, not filesystem mtime
|
|
615
|
+
const storedTimestamp = contentTimestamps.get(relativePath);
|
|
616
|
+
let activityTimestamp = storedTimestamp;
|
|
617
|
+
if (!activityTimestamp) {
|
|
618
|
+
// No stored timestamp - use file mtime as initial value
|
|
619
|
+
try {
|
|
620
|
+
const fileStat = await stat(file);
|
|
621
|
+
activityTimestamp = fileStat.mtimeMs;
|
|
622
|
+
} catch (e) {
|
|
623
|
+
activityTimestamp = 0;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
recentActivity.push({
|
|
627
|
+
title: title,
|
|
628
|
+
url: searchUrl,
|
|
629
|
+
mtime: activityTimestamp
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
// Check if a corresponding .html file already exists in source directory
|
|
633
|
+
const outputHtmlRelative = relativePath.startsWith('/') ? relativePath.slice(1) : relativePath;
|
|
634
|
+
if (existingHtmlFiles.has(outputHtmlRelative)) {
|
|
635
|
+
progress.log(`⚠️ Warning: Skipping ${shortFile} - would overwrite existing ${outputHtmlRelative} in source`);
|
|
636
|
+
skippedCount++;
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// Skip metadata-only index files - they exist only to provide folder metadata
|
|
641
|
+
// The auto-index system will generate the actual index.html for these folders
|
|
642
|
+
if (base === 'index' && (type === '.md' || type === '.mdx') && isMetadataOnly(rawBody)) {
|
|
643
|
+
progress.log(`ℹ️ Skipping metadata-only ${shortFile} - auto-index will generate listing`);
|
|
644
|
+
skippedCount++;
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// Metadata is needed both for the cache decision below and for rendering.
|
|
649
|
+
const fileMeta = extractMetadata(rawBody);
|
|
650
|
+
|
|
651
|
+
// A document with `generate-auto-index: true` renders a listing of the
|
|
652
|
+
// source tree, so its output depends on which folders and files exist —
|
|
653
|
+
// not just on its own text. A content hash cannot see that: adding,
|
|
654
|
+
// renaming, or deleting a folder anywhere in the tree leaves the hash
|
|
655
|
+
// untouched and the listing stale forever. Only a handful of documents
|
|
656
|
+
// opt in, so always rebuild them.
|
|
657
|
+
const hasAutoIndex = getAutoIndexConfig(fileMeta).enabled;
|
|
658
|
+
|
|
659
|
+
// Check if file needs regeneration.
|
|
660
|
+
// An unchanged hash is not enough: the hash cache lives in the source tree
|
|
661
|
+
// and is shared across output dirs, so also require that every output this
|
|
662
|
+
// document emits is actually present before skipping it.
|
|
663
|
+
const needsRegen =
|
|
664
|
+
_clean ||
|
|
665
|
+
hasAutoIndex ||
|
|
666
|
+
needsRegeneration(file, rawBody, hashCache) ||
|
|
667
|
+
!outputsExist([
|
|
668
|
+
outputFilename,
|
|
669
|
+
outputFilename.replace(".html", ".json"),
|
|
670
|
+
outputFilename.replace(".html", ".xml"),
|
|
671
|
+
]);
|
|
672
|
+
|
|
673
|
+
if (!needsRegen) {
|
|
674
|
+
skippedCount++;
|
|
675
|
+
// For directory indices, store minimal data (not full bodyHtml)
|
|
676
|
+
// But include metadata for directory JSON files
|
|
677
|
+
dirIndexCache.set(file, {
|
|
678
|
+
name: base,
|
|
679
|
+
url,
|
|
680
|
+
metadata: fileMeta,
|
|
681
|
+
});
|
|
682
|
+
return; // Skip regenerating this file
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
regeneratedCount++;
|
|
686
|
+
// Track this path for incremental search index updates
|
|
687
|
+
changedPaths.add(relativePath);
|
|
688
|
+
|
|
689
|
+
const rawMeta = extractRawMetadata(rawBody);
|
|
690
|
+
|
|
691
|
+
// Lazy metadata transform - only compute if template actually uses it
|
|
692
|
+
// This defers the potentially expensive custom transform function load
|
|
693
|
+
let transformedMetadata = null;
|
|
694
|
+
const getTransformedMeta = async () => {
|
|
695
|
+
if (transformedMetadata === null) {
|
|
696
|
+
transformedMetadata = await getTransformedMetadata(dirname(file), fileMeta);
|
|
697
|
+
}
|
|
698
|
+
return transformedMetadata;
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
// Calculate the document's URL path (e.g., "/character/index.html")
|
|
702
|
+
const docUrlPath = '/' + dir + base + '.html';
|
|
703
|
+
|
|
704
|
+
// Use async rendering with worker threads for parallel markdown parsing
|
|
705
|
+
// Wikitext (.txt) files will fall back to main thread
|
|
706
|
+
// For MDX files, enable hydration if frontmatter has `hydrate: true`
|
|
707
|
+
const shouldHydrate = type === '.mdx' && fileMeta?.hydrate === true;
|
|
708
|
+
|
|
709
|
+
let renderResult = await renderFileAsync({
|
|
710
|
+
fileContents: rawBody,
|
|
711
|
+
type,
|
|
712
|
+
dirname: dir,
|
|
713
|
+
basename: base,
|
|
714
|
+
filePath: file,
|
|
715
|
+
sourceRoot: source,
|
|
716
|
+
useWorker: true,
|
|
717
|
+
hydrate: shouldHydrate,
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
// Handle the result - can be string or { html, hydrationScript }
|
|
721
|
+
let body;
|
|
722
|
+
let hydrationScript = '';
|
|
723
|
+
if (typeof renderResult === 'object' && renderResult.html) {
|
|
724
|
+
body = renderResult.html;
|
|
725
|
+
hydrationScript = renderResult.hydrationScript || '';
|
|
726
|
+
} else {
|
|
727
|
+
body = renderResult;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Inject default H1 if body doesn't start with one
|
|
731
|
+
if (!body || !body.trimStart().startsWith('<h1')) {
|
|
732
|
+
const h1Title = fileMeta?.title || title;
|
|
733
|
+
body = `<h1>${h1Title}</h1>\n` + (body || '');
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// Inject breadcrumbs before the H1
|
|
737
|
+
const breadcrumbs = generateBreadcrumbs(dir, base, fileMeta);
|
|
738
|
+
if (breadcrumbs) {
|
|
739
|
+
body = breadcrumbs + body;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// Inject frontmatter table after first H1 (for markdown files with metadata)
|
|
743
|
+
if ((type === '.md' || type === '.mdx') && fileMeta) {
|
|
744
|
+
body = injectFrontmatterTable(body, fileMeta);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// Handle auto-index generation for index files with generate-auto-index: true
|
|
748
|
+
if (base === 'index' && fileMeta) {
|
|
749
|
+
const autoIndexConfig = getAutoIndexConfig(fileMeta);
|
|
750
|
+
if (autoIndexConfig.enabled) {
|
|
751
|
+
// Generate auto-index HTML for this directory from source
|
|
752
|
+
// Using source avoids race conditions with concurrent file generation
|
|
753
|
+
const sourceDir = dirname(file);
|
|
754
|
+
const autoIndexHtml = await generateAutoIndexHtmlFromSource(sourceDir, autoIndexConfig.depth);
|
|
755
|
+
|
|
756
|
+
if (autoIndexHtml) {
|
|
757
|
+
if (autoIndexConfig.position === 'bottom') {
|
|
758
|
+
body = body + '\n' + autoIndexHtml;
|
|
759
|
+
} else {
|
|
760
|
+
body = autoIndexHtml + '\n' + body;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// Find all style.css files up the tree and bundle them into a single CSS file per folder path
|
|
767
|
+
// (Generate mode: one CSS bundle per unique folder, minimizing requests per page load)
|
|
768
|
+
let styleLink = "";
|
|
769
|
+
try {
|
|
770
|
+
const dirKey = (dir === "/" || dir === "") ? _source : resolve(_source, dir);
|
|
771
|
+
const folderRelative = (dir === "/" || dir === "") ? "" : dir;
|
|
772
|
+
|
|
773
|
+
// Check bundle cache first (dirs with same CSS ancestry share the same bundle)
|
|
774
|
+
let cachedBundleUrl = docBundleCache.get(`css:${dirKey}`);
|
|
775
|
+
if (cachedBundleUrl !== undefined) {
|
|
776
|
+
if (cachedBundleUrl) {
|
|
777
|
+
styleLink = `<link rel="stylesheet" href="${cachedBundleUrl}" />`;
|
|
778
|
+
}
|
|
779
|
+
} else {
|
|
780
|
+
let cssPaths = cssPathCache.get(dirKey);
|
|
781
|
+
if (cssPaths === undefined) {
|
|
782
|
+
cssPaths = await findAllStyleCss(dirKey, _source);
|
|
783
|
+
cssPathCache.set(dirKey, cssPaths);
|
|
784
|
+
}
|
|
785
|
+
if (cssPaths.length > 0) {
|
|
786
|
+
// Copy all source CSS files to output (still needed for serve mode fallback)
|
|
787
|
+
for (const cssPath of cssPaths) {
|
|
788
|
+
if (!copiedCssFiles.has(cssPath)) {
|
|
789
|
+
const cssOutputPath = cssPath.replace(source, output);
|
|
790
|
+
const cssContent = await readFile(cssPath, 'utf8');
|
|
791
|
+
await outputFile(cssOutputPath, cssContent);
|
|
792
|
+
copiedCssFiles.add(cssPath);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
// Bundle into a single file
|
|
796
|
+
const bundleUrl = await bundleDocumentCss(cssPaths, output, source, folderRelative, { minify: true });
|
|
797
|
+
docBundleCache.set(`css:${dirKey}`, bundleUrl);
|
|
798
|
+
styleLink = `<link rel="stylesheet" href="${bundleUrl}" />`;
|
|
799
|
+
} else {
|
|
800
|
+
docBundleCache.set(`css:${dirKey}`, null);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
} catch (e) {
|
|
804
|
+
// ignore
|
|
805
|
+
console.error(e);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// Find all script.js files from docroot to current dir and bundle them
|
|
809
|
+
// (Generate mode: one JS bundle per unique folder, external not inlined)
|
|
810
|
+
let customScript = "";
|
|
811
|
+
try {
|
|
812
|
+
const dirKey = (dir === "/" || dir === "") ? _source : resolve(_source, dir);
|
|
813
|
+
const folderRelative = (dir === "/" || dir === "") ? "" : dir;
|
|
814
|
+
|
|
815
|
+
let cachedBundleUrl = docBundleCache.get(`js:${dirKey}`);
|
|
816
|
+
if (cachedBundleUrl !== undefined) {
|
|
817
|
+
if (cachedBundleUrl) {
|
|
818
|
+
customScript = `<script src="${cachedBundleUrl}"></script>`;
|
|
819
|
+
}
|
|
820
|
+
} else {
|
|
821
|
+
let scriptPaths = scriptPathCache.get(dirKey);
|
|
822
|
+
if (scriptPaths === undefined) {
|
|
823
|
+
scriptPaths = await findAllScriptJs(dirKey, _source);
|
|
824
|
+
scriptPathCache.set(dirKey, scriptPaths);
|
|
825
|
+
}
|
|
826
|
+
if (scriptPaths.length > 0) {
|
|
827
|
+
const bundleUrl = await bundleDocumentJs(scriptPaths, output, source, folderRelative, { minify: true });
|
|
828
|
+
docBundleCache.set(`js:${dirKey}`, bundleUrl);
|
|
829
|
+
customScript = `<script src="${bundleUrl}"></script>`;
|
|
830
|
+
} else {
|
|
831
|
+
docBundleCache.set(`js:${dirKey}`, null);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
} catch (e) {
|
|
835
|
+
// ignore
|
|
836
|
+
console.error(e);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
const requestedTemplateName = fileMeta && fileMeta.template;
|
|
840
|
+
const templateName = requestedTemplateName || DEFAULT_TEMPLATE_NAME;
|
|
841
|
+
const template = templates[templateName];
|
|
842
|
+
|
|
843
|
+
if (!template) {
|
|
844
|
+
throw new Error(`Template not found. Requested: "${templateName}". Available templates: ${Object.keys(templates).join(', ') || 'none'}`);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// Register this document's dependencies for invalidation tracking
|
|
848
|
+
{
|
|
849
|
+
const dirKey = (dir === "/" || dir === "") ? _source : resolve(_source, dir);
|
|
850
|
+
const cssDeps = cssPathCache.get(dirKey) || [];
|
|
851
|
+
const jsDeps = scriptPathCache.get(dirKey) || [];
|
|
852
|
+
dependencyTracker.registerDocument(file, {
|
|
853
|
+
templateName,
|
|
854
|
+
cssPaths: cssDeps,
|
|
855
|
+
scriptPaths: jsDeps,
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// Check if this file has a custom menu
|
|
860
|
+
const customMenuInfo = getCustomMenuForFile(file, source, customMenus);
|
|
861
|
+
|
|
862
|
+
// Lazy evaluation of transformed metadata - only compute if template uses it
|
|
863
|
+
// This defers expensive custom transform function loading until actually needed
|
|
864
|
+
const templateUsesTransformedMeta = template.includes('${transformedMetadata}');
|
|
865
|
+
const lazyTransformedMeta = templateUsesTransformedMeta
|
|
866
|
+
? await getTransformedMeta()
|
|
867
|
+
: '';
|
|
868
|
+
|
|
869
|
+
// Build final HTML with all replacements in a single regex pass
|
|
870
|
+
// This avoids creating 8 intermediate strings
|
|
871
|
+
// Append hydration script to customScript if present (for MDX with hydrate: true)
|
|
872
|
+
const finalCustomScript = hydrationScript
|
|
873
|
+
? customScript + '\n' + hydrationScript
|
|
874
|
+
: customScript;
|
|
875
|
+
|
|
876
|
+
const replacements = {
|
|
877
|
+
"${title}": fileMeta?.title || title,
|
|
878
|
+
"${menu}": menu,
|
|
879
|
+
"${meta}": JSON.stringify(fileMeta),
|
|
880
|
+
"${transformedMetadata}": lazyTransformedMeta,
|
|
881
|
+
"${body}": body,
|
|
882
|
+
"${styleLink}": styleLink,
|
|
883
|
+
"${customScript}": finalCustomScript,
|
|
884
|
+
"${searchIndex}": "[]", // Placeholder - search index written separately as JSON file
|
|
885
|
+
"${footer}": footer
|
|
886
|
+
};
|
|
887
|
+
// Single-pass replacement using regex alternation
|
|
888
|
+
const pattern = /\$\{(title|menu|meta|transformedMetadata|body|styleLink|customScript|searchIndex|footer)\}/g;
|
|
889
|
+
let finalHtml = template.replace(pattern, (match) => replacements[match] ?? match);
|
|
890
|
+
|
|
891
|
+
// Add menu data attributes to body
|
|
892
|
+
if (customMenuInfo) {
|
|
893
|
+
const menuPosition = customMenuInfo.menuPosition || 'top';
|
|
894
|
+
finalHtml = finalHtml.replace(
|
|
895
|
+
/<body([^>]*)>/,
|
|
896
|
+
`<body$1 data-custom-menu="${customMenuInfo.menuJsonPath}" data-menu-position="${menuPosition}">`
|
|
897
|
+
);
|
|
898
|
+
} else {
|
|
899
|
+
// No custom menu — default to top menu
|
|
900
|
+
finalHtml = finalHtml.replace(
|
|
901
|
+
/<body([^>]*)>/,
|
|
902
|
+
`<body$1 data-menu-position="top">`
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
// Resolve relative URLs in raw HTML elements (img src, etc.)
|
|
907
|
+
finalHtml = resolveRelativeUrls(finalHtml, docUrlPath);
|
|
908
|
+
|
|
909
|
+
// Resolve links and mark broken internal links as inactive
|
|
910
|
+
finalHtml = markInactiveLinks(finalHtml, validPaths, docUrlPath, false);
|
|
911
|
+
|
|
912
|
+
// Transform image tags to use preview images with data-fullsrc for originals
|
|
913
|
+
// Skip in deferred mode - images will use original paths until preview generation completes
|
|
914
|
+
if (!_deferImages) {
|
|
915
|
+
finalHtml = transformImageTags(finalHtml, imageMap, docUrlPath);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// Add cache-busting timestamps to static file references
|
|
919
|
+
finalHtml = addTimestampToHtmlStaticRefs(finalHtml, cacheBustTimestamp);
|
|
920
|
+
|
|
921
|
+
await outputFile(outputFilename, finalHtml);
|
|
922
|
+
|
|
923
|
+
// Clear finalHtml reference to allow GC
|
|
924
|
+
finalHtml = null;
|
|
925
|
+
|
|
926
|
+
// JSON output
|
|
927
|
+
const jsonOutputFilename = outputFilename.replace(".html", ".json");
|
|
928
|
+
|
|
929
|
+
// Extract sections for markdown files
|
|
930
|
+
const sections = (type === '.md' || type === '.mdx') ? extractSections(rawBody) : [];
|
|
931
|
+
|
|
932
|
+
// Use lazy metadata for JSON output - may have been computed above for HTML
|
|
933
|
+
const jsonTransformedMeta = await getTransformedMeta();
|
|
934
|
+
|
|
935
|
+
const jsonObject = {
|
|
936
|
+
name: base,
|
|
937
|
+
url,
|
|
938
|
+
contents: rawBody,
|
|
939
|
+
bodyHtml: body,
|
|
940
|
+
metadata: fileMeta,
|
|
941
|
+
sections,
|
|
942
|
+
transformedMetadata: jsonTransformedMeta,
|
|
943
|
+
_ursa_metadata: ursaMetadata,
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
// Store minimal data for directory indices, including metadata
|
|
947
|
+
dirIndexCache.set(file, {
|
|
948
|
+
name: base,
|
|
949
|
+
url,
|
|
950
|
+
metadata: fileMeta,
|
|
951
|
+
});
|
|
952
|
+
|
|
953
|
+
const json = JSON.stringify(jsonObject);
|
|
954
|
+
await outputFile(jsonOutputFilename, json);
|
|
955
|
+
|
|
956
|
+
// XML output
|
|
957
|
+
const xmlOutputFilename = outputFilename.replace(".html", ".xml");
|
|
958
|
+
const xml = `<article>${o2x(jsonObject)}</article>`;
|
|
959
|
+
await outputFile(xmlOutputFilename, xml);
|
|
960
|
+
|
|
961
|
+
// Update the content hash for this file
|
|
962
|
+
updateHash(file, rawBody, hashCache);
|
|
963
|
+
|
|
964
|
+
// Update content timestamp since this file was regenerated (content changed)
|
|
965
|
+
contentTimestamps.set(relativePath, buildTimestamp);
|
|
966
|
+
// Also update the recentActivity entry we pushed earlier with the new timestamp
|
|
967
|
+
const activityEntry = recentActivity.find(e => e.url === searchUrl);
|
|
968
|
+
if (activityEntry) {
|
|
969
|
+
activityEntry.mtime = buildTimestamp;
|
|
970
|
+
}
|
|
971
|
+
} catch (e) {
|
|
972
|
+
progress.log(`Error processing ${file}: ${e.message}`);
|
|
973
|
+
errors.push({ file, phase: 'article-generation', error: e });
|
|
974
|
+
}
|
|
975
|
+
});
|
|
976
|
+
|
|
977
|
+
// Complete the articles status line
|
|
978
|
+
progress.done('Articles', `${totalArticles} done (${regeneratedCount} regenerated, ${skippedCount} unchanged) [${progress.stopTimer('Articles')}]`);
|
|
979
|
+
profiler.endPhase('Process articles');
|
|
980
|
+
|
|
981
|
+
// Phase: Write search index
|
|
982
|
+
// Can be deferred in serve mode for faster startup
|
|
983
|
+
let deferredSearchIndexPromise = null;
|
|
984
|
+
|
|
985
|
+
const buildSearchIndex = async () => {
|
|
986
|
+
const indexStartTime = Date.now();
|
|
987
|
+
progress.logTimed('Building search index...');
|
|
988
|
+
|
|
989
|
+
// Write search index as a separate JSON file (not embedded in each page)
|
|
990
|
+
const searchIndexPath = join(output, 'public', 'search-index.json');
|
|
991
|
+
progress.log(`Writing search index with ${searchIndex.length} entries`);
|
|
992
|
+
await outputFile(searchIndexPath, JSON.stringify(searchIndex));
|
|
993
|
+
|
|
994
|
+
// Build full-text index - use incremental mode when possible
|
|
995
|
+
let fullTextIndex;
|
|
996
|
+
if (!_clean && changedPaths.size > 0 && changedPaths.size < fullTextDocs.length) {
|
|
997
|
+
// Incremental update: only re-index changed documents
|
|
998
|
+
progress.log(`Incremental full-text index: ${changedPaths.size} changed, ${fullTextDocs.length - changedPaths.size} cached`);
|
|
999
|
+
fullTextIndex = buildIncrementalIndex(fullTextDocs, changedPaths, source);
|
|
1000
|
+
} else {
|
|
1001
|
+
// Full rebuild: clean build or all documents changed
|
|
1002
|
+
progress.log(`Building full-text index from ${fullTextDocs.length} documents...`);
|
|
1003
|
+
fullTextIndex = buildFullTextIndex(fullTextDocs);
|
|
1004
|
+
// Save to cache for future incremental updates
|
|
1005
|
+
saveIndexCache(source, fullTextIndex);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
const fullTextIndexPath = join(output, 'public', 'fulltext-index.json');
|
|
1009
|
+
const fullTextIndexJson = JSON.stringify(fullTextIndex);
|
|
1010
|
+
const wordCount = Object.keys(fullTextIndex).length;
|
|
1011
|
+
progress.log(`Writing full-text index (${wordCount} unique words, ${(fullTextIndexJson.length / 1024).toFixed(1)} KB)`);
|
|
1012
|
+
await outputFile(fullTextIndexPath, fullTextIndexJson);
|
|
1013
|
+
|
|
1014
|
+
const elapsed = ((Date.now() - indexStartTime) / 1000).toFixed(1);
|
|
1015
|
+
return { entries: searchIndex.length, words: wordCount, elapsed };
|
|
1016
|
+
};
|
|
1017
|
+
|
|
1018
|
+
if (_deferSearchIndex) {
|
|
1019
|
+
// Deferred mode: start building in background, return promise
|
|
1020
|
+
profiler.startPhase('Write search index (deferred)');
|
|
1021
|
+
progress.startTimer('Search index');
|
|
1022
|
+
progress.log('Search index building deferred for faster startup...');
|
|
1023
|
+
deferredSearchIndexPromise = buildSearchIndex().then(result => {
|
|
1024
|
+
progress.done('Search index (background)', `${result.entries} entries, ${result.words} words in ${result.elapsed}s`);
|
|
1025
|
+
return result;
|
|
1026
|
+
});
|
|
1027
|
+
progress.done('Search index', 'deferred [0ms]');
|
|
1028
|
+
profiler.endPhase('Write search index (deferred)');
|
|
1029
|
+
} else {
|
|
1030
|
+
// Normal mode: build search index now
|
|
1031
|
+
profiler.startPhase('Write search index');
|
|
1032
|
+
progress.startTimer('Search index');
|
|
1033
|
+
const result = await buildSearchIndex();
|
|
1034
|
+
progress.done('Search index', `${result.entries} entries, ${result.words} words [${progress.stopTimer('Search index')}]`);
|
|
1035
|
+
profiler.endPhase('Write search index');
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// Phase: Write recent activity data
|
|
1039
|
+
profiler.startPhase('Write recent activity');
|
|
1040
|
+
progress.startTimer('Recent activity');
|
|
1041
|
+
// Sort by mtime descending, keep top 10
|
|
1042
|
+
recentActivity.sort((a, b) => b.mtime - a.mtime);
|
|
1043
|
+
const top10 = recentActivity.slice(0, 10);
|
|
1044
|
+
const recentActivityPath = join(output, 'public', 'recent-activity.json');
|
|
1045
|
+
await outputFile(recentActivityPath, JSON.stringify(top10));
|
|
1046
|
+
progress.done('Recent activity', `${top10.length} entries [${progress.stopTimer('Recent activity')}]`);
|
|
1047
|
+
profiler.endPhase('Write recent activity');
|
|
1048
|
+
|
|
1049
|
+
// Phase: Write menu data
|
|
1050
|
+
profiler.startPhase('Write menu data');
|
|
1051
|
+
progress.startTimer('Menu data');
|
|
1052
|
+
// Write menu data as a separate JSON file (not embedded in each page)
|
|
1053
|
+
// This dramatically reduces HTML file sizes for large sites
|
|
1054
|
+
const menuDataPath = join(output, 'public', 'menu-data.json');
|
|
1055
|
+
const menuDataJson = JSON.stringify(menuData);
|
|
1056
|
+
progress.log(`Writing menu data (${(menuDataJson.length / 1024).toFixed(1)} KB)`);
|
|
1057
|
+
await outputFile(menuDataPath, menuDataJson);
|
|
1058
|
+
|
|
1059
|
+
// Write custom menu JSON files
|
|
1060
|
+
for (const [menuDir, menuInfo] of customMenus) {
|
|
1061
|
+
const customMenuPath = join(output, menuInfo.menuJsonPath);
|
|
1062
|
+
// Include menuPosition in the JSON so client knows how to render
|
|
1063
|
+
const customMenuJson = JSON.stringify({
|
|
1064
|
+
menuData: menuInfo.menuData,
|
|
1065
|
+
menuPosition: menuInfo.menuPosition || 'top',
|
|
1066
|
+
});
|
|
1067
|
+
progress.log(`Writing custom menu: ${menuInfo.menuJsonPath}`);
|
|
1068
|
+
await outputFile(customMenuPath, customMenuJson);
|
|
1069
|
+
}
|
|
1070
|
+
progress.done('Menu data', `${customMenus.size + 1} files [${progress.stopTimer('Menu data')}]`);
|
|
1071
|
+
profiler.endPhase('Write menu data');
|
|
1072
|
+
|
|
1073
|
+
// Phase: Process directory indices
|
|
1074
|
+
profiler.startPhase('Process directories');
|
|
1075
|
+
progress.startTimer('Directories');
|
|
1076
|
+
|
|
1077
|
+
// Output paths that a source document already owns. The generated directory
|
|
1078
|
+
// listing below writes to <dir>.html, which collides with two things: an
|
|
1079
|
+
// article named after its own folder (settings/dying-light.md renders to
|
|
1080
|
+
// settings/dying-light.html) and a hand-written .html copied from the source
|
|
1081
|
+
// tree. Those documents win — the listing must never overwrite them.
|
|
1082
|
+
const documentOwnedOutputs = new Set(
|
|
1083
|
+
allSourceFilenamesThatAreArticles.map((filename) =>
|
|
1084
|
+
filename.replace(source, output).replace(/\.(md|mdx|txt|yml)$/, ".html")
|
|
1085
|
+
)
|
|
1086
|
+
);
|
|
1087
|
+
for (const relativeHtmlPath of existingHtmlFiles) {
|
|
1088
|
+
documentOwnedOutputs.add(join(output, relativeHtmlPath));
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// Process directory indices with batched concurrency
|
|
1092
|
+
const totalDirs = allSourceFilenamesThatAreDirectories.length;
|
|
1093
|
+
let processedDirs = 0;
|
|
1094
|
+
progress.log(`Processing ${totalDirs} directories...`);
|
|
1095
|
+
await processBatched(allSourceFilenamesThatAreDirectories, async (dirPath) => {
|
|
1096
|
+
try {
|
|
1097
|
+
processedDirs++;
|
|
1098
|
+
const shortDir = dirPath.replace(source, '');
|
|
1099
|
+
progress.status('Directories', `${processedDirs}/${totalDirs} ${shortDir}`);
|
|
1100
|
+
|
|
1101
|
+
const pathsInThisDirectory = allSourceFilenames.filter((filename) =>
|
|
1102
|
+
filename.match(new RegExp(`${dirPath}.+`))
|
|
1103
|
+
);
|
|
1104
|
+
|
|
1105
|
+
// Use minimal directory index cache instead of full jsonCache
|
|
1106
|
+
const jsonObjects = pathsInThisDirectory
|
|
1107
|
+
.map((path) => {
|
|
1108
|
+
const object = dirIndexCache.get(path);
|
|
1109
|
+
return typeof object === "object" ? object : null;
|
|
1110
|
+
})
|
|
1111
|
+
.filter((a) => a);
|
|
1112
|
+
|
|
1113
|
+
const json = JSON.stringify(jsonObjects);
|
|
1114
|
+
|
|
1115
|
+
const outputFilename = dirPath.replace(source, output) + ".json";
|
|
1116
|
+
await outputFile(outputFilename, json);
|
|
1117
|
+
|
|
1118
|
+
// html
|
|
1119
|
+
// Rewritten every build: the listing reflects the directory's contents,
|
|
1120
|
+
// so skipping it whenever the file already exists (the old behaviour)
|
|
1121
|
+
// froze it at whatever the tree looked like the first time it was
|
|
1122
|
+
// written, and new or removed documents never showed up again.
|
|
1123
|
+
const htmlOutputFilename = dirPath.replace(source, output) + ".html";
|
|
1124
|
+
if (!documentOwnedOutputs.has(htmlOutputFilename)) {
|
|
1125
|
+
const template = templates["default-template"];
|
|
1126
|
+
const indexHtml = `<ul>${pathsInThisDirectory
|
|
1127
|
+
.map((path) => {
|
|
1128
|
+
const partialPath = path
|
|
1129
|
+
.replace(source, "")
|
|
1130
|
+
.replace(parse(path).ext, ".html");
|
|
1131
|
+
const name = basename(path, parse(path).ext);
|
|
1132
|
+
return `<li><a href="${partialPath}">${name}</a></li>`;
|
|
1133
|
+
})
|
|
1134
|
+
.join("")}</ul>`;
|
|
1135
|
+
let finalHtml = template;
|
|
1136
|
+
const replacements = {
|
|
1137
|
+
"${menu}": menu,
|
|
1138
|
+
"${body}": indexHtml,
|
|
1139
|
+
"${searchIndex}": "[]", // Search index now in separate file
|
|
1140
|
+
"${title}": "Index",
|
|
1141
|
+
"${meta}": "{}",
|
|
1142
|
+
"${transformedMetadata}": "",
|
|
1143
|
+
"${styleLink}": "",
|
|
1144
|
+
"${footer}": footer
|
|
1145
|
+
};
|
|
1146
|
+
for (const [key, value] of Object.entries(replacements)) {
|
|
1147
|
+
finalHtml = finalHtml.replace(key, value);
|
|
1148
|
+
}
|
|
1149
|
+
// Add cache-busting timestamps to static file references
|
|
1150
|
+
finalHtml = addTimestampToHtmlStaticRefs(finalHtml, cacheBustTimestamp);
|
|
1151
|
+
await outputFile(htmlOutputFilename, finalHtml);
|
|
1152
|
+
}
|
|
1153
|
+
} catch (e) {
|
|
1154
|
+
progress.log(`Error processing directory ${dirPath}: ${e.message}`);
|
|
1155
|
+
errors.push({ file: dirPath, phase: 'directory-index', error: e });
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
|
|
1159
|
+
progress.done('Directories', `${totalDirs} done [${progress.stopTimer('Directories')}]`);
|
|
1160
|
+
profiler.endPhase('Process directories');
|
|
1161
|
+
|
|
1162
|
+
// Clear directory index cache to free memory before processing static files
|
|
1163
|
+
dirIndexCache.clear();
|
|
1164
|
+
|
|
1165
|
+
// Phase: Process static files
|
|
1166
|
+
profiler.startPhase('Process static files');
|
|
1167
|
+
progress.startTimer('Static files');
|
|
1168
|
+
// Copy static HTML files (images were already processed above with preview generation)
|
|
1169
|
+
// Note: Images are processed before articles to enable preview transformation in HTML
|
|
1170
|
+
|
|
1171
|
+
// Also copy existing HTML files from source to output (they're treated as static)
|
|
1172
|
+
const allSourceFilenamesThatAreHtml = allSourceFilenames.filter(
|
|
1173
|
+
(filename) => filename.match(/\.html$/) && !isHiddenOrSystem(filename)
|
|
1174
|
+
);
|
|
1175
|
+
|
|
1176
|
+
// Fonts, audio, video, PDFs: copied through untouched. Images are handled
|
|
1177
|
+
// separately above because they also get previews; everything else that is
|
|
1178
|
+
// neither an article nor a stylesheet belongs here. Leaving this out is what
|
|
1179
|
+
// let `ursa serve` and `ursa generate` disagree — serve reads these straight
|
|
1180
|
+
// off disk, so the missing copy step only ever showed up in a built site.
|
|
1181
|
+
const allSourceFilenamesThatAreMedia = allSourceFilenames.filter(
|
|
1182
|
+
(filename) => isMedia(filename) && !isHiddenOrSystem(filename)
|
|
1183
|
+
);
|
|
1184
|
+
|
|
1185
|
+
const allStaticFiles = [...allSourceFilenamesThatAreHtml, ...allSourceFilenamesThatAreMedia];
|
|
1186
|
+
const totalStatic = allStaticFiles.length;
|
|
1187
|
+
let processedStatic = 0;
|
|
1188
|
+
let copiedStatic = 0;
|
|
1189
|
+
progress.log(
|
|
1190
|
+
`Processing ${totalStatic} static files ` +
|
|
1191
|
+
`(${allSourceFilenamesThatAreHtml.length} HTML, ${allSourceFilenamesThatAreMedia.length} media)...`
|
|
1192
|
+
);
|
|
1193
|
+
await processBatched(allStaticFiles, async (file) => {
|
|
1194
|
+
try {
|
|
1195
|
+
processedStatic++;
|
|
1196
|
+
const shortFile = file.replace(source, '');
|
|
1197
|
+
progress.status('Static files', `${processedStatic}/${totalStatic} ${shortFile}`);
|
|
1198
|
+
|
|
1199
|
+
// Check if file has changed using file stat as a quick check
|
|
1200
|
+
const fileStat = await stat(file);
|
|
1201
|
+
const statKey = `${file}:stat`;
|
|
1202
|
+
const newStatHash = `${fileStat.size}:${fileStat.mtimeMs}`;
|
|
1203
|
+
const outputFilename = file.replace(source, output);
|
|
1204
|
+
// As with articles: an unchanged stat only means the source is untouched,
|
|
1205
|
+
// so the output must exist before this copy can be skipped.
|
|
1206
|
+
if (hashCache.get(statKey) === newStatHash && outputsExist([outputFilename])) {
|
|
1207
|
+
return; // Skip unchanged static file
|
|
1208
|
+
}
|
|
1209
|
+
hashCache.set(statKey, newStatHash);
|
|
1210
|
+
copiedStatic++;
|
|
1211
|
+
|
|
1212
|
+
await mkdir(dirname(outputFilename), { recursive: true });
|
|
1213
|
+
|
|
1214
|
+
if (file.endsWith('.css')) {
|
|
1215
|
+
// Process CSS for cache busting
|
|
1216
|
+
const cssContent = await readFile(file, 'utf8');
|
|
1217
|
+
const processedCss = addTimestampToCssUrls(cssContent, cacheBustTimestamp);
|
|
1218
|
+
await outputFile(outputFilename, processedCss);
|
|
1219
|
+
} else if (file.endsWith('.html')) {
|
|
1220
|
+
// Process HTML files for link resolution
|
|
1221
|
+
let htmlContent = await readFile(file, 'utf8');
|
|
1222
|
+
// Calculate the document's URL path for relative link resolution
|
|
1223
|
+
const docUrlPath = '/' + file.replace(source, '').replace(/^\//, '');
|
|
1224
|
+
// Resolve relative URLs in raw HTML elements (img src, etc.)
|
|
1225
|
+
htmlContent = resolveRelativeUrls(htmlContent, docUrlPath);
|
|
1226
|
+
// Resolve internal links to have proper .html extensions
|
|
1227
|
+
htmlContent = markInactiveLinks(htmlContent, validPaths, docUrlPath, false);
|
|
1228
|
+
// Transform image tags to use preview images with data-fullsrc for originals
|
|
1229
|
+
// Skip in deferred mode - images will use original paths until preview generation completes
|
|
1230
|
+
if (!_deferImages) {
|
|
1231
|
+
htmlContent = transformImageTags(htmlContent, imageMap, docUrlPath);
|
|
1232
|
+
}
|
|
1233
|
+
// Add cache-busting timestamps
|
|
1234
|
+
htmlContent = addTimestampToHtmlStaticRefs(htmlContent, cacheBustTimestamp);
|
|
1235
|
+
await outputFile(outputFilename, htmlContent);
|
|
1236
|
+
} else {
|
|
1237
|
+
await copyFile(file, outputFilename);
|
|
1238
|
+
}
|
|
1239
|
+
} catch (e) {
|
|
1240
|
+
progress.log(`Error processing static file ${file}: ${e.message}`);
|
|
1241
|
+
errors.push({ file, phase: 'static-file', error: e });
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
|
|
1245
|
+
progress.done('Static files', `${totalStatic} done (${copiedStatic} copied) [${progress.stopTimer('Static files')}]`);
|
|
1246
|
+
profiler.endPhase('Process static files');
|
|
1247
|
+
|
|
1248
|
+
// Phase: Auto-index generation
|
|
1249
|
+
profiler.startPhase('Auto-index generation');
|
|
1250
|
+
progress.startTimer('Auto-index');
|
|
1251
|
+
// Automatic index generation for folders without index.html
|
|
1252
|
+
progress.log(`Checking for missing index files...`);
|
|
1253
|
+
await generateAutoIndices(output, allSourceFilenamesThatAreDirectories, source, templates, menu, footer, allSourceFilenamesThatAreArticles, copiedCssFiles, existingHtmlFiles, cacheBustTimestamp, progress, customMenus);
|
|
1254
|
+
progress.done('Auto-index', `checked ${allSourceFilenamesThatAreDirectories.length} directories [${progress.stopTimer('Auto-index')}]`);
|
|
1255
|
+
profiler.endPhase('Auto-index generation');
|
|
1256
|
+
|
|
1257
|
+
// Phase: Finalization
|
|
1258
|
+
profiler.startPhase('Finalization');
|
|
1259
|
+
progress.startTimer('Finalization');
|
|
1260
|
+
// Save the hash cache to .ursa folder in source directory
|
|
1261
|
+
if (hashCache.size > 0) {
|
|
1262
|
+
await saveHashCache(source, hashCache);
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
// Save content timestamps to .ursa.json (tracks when content actually changed)
|
|
1266
|
+
if (contentTimestamps.size > 0) {
|
|
1267
|
+
saveContentTimestamps(source, contentTimestamps);
|
|
1268
|
+
progress.log(`Saved ${contentTimestamps.size} content timestamps`);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
// Persist the dependency tracker so hash-skipped documents keep their
|
|
1272
|
+
// edges on the next warm start (invalidation plans stay accurate)
|
|
1273
|
+
await saveDependencyTracker(source);
|
|
1274
|
+
|
|
1275
|
+
// Populate watch mode cache for fast single-file regeneration
|
|
1276
|
+
watchModeCache.templates = templates;
|
|
1277
|
+
watchModeCache.menu = menu;
|
|
1278
|
+
watchModeCache.footer = footer;
|
|
1279
|
+
watchModeCache.validPaths = validPaths;
|
|
1280
|
+
watchModeCache.source = source;
|
|
1281
|
+
watchModeCache.meta = meta;
|
|
1282
|
+
watchModeCache.output = output;
|
|
1283
|
+
watchModeCache.hashCache = hashCache;
|
|
1284
|
+
watchModeCache.cacheBustTimestamp = cacheBustTimestamp;
|
|
1285
|
+
watchModeCache.cacheBustHashes = cacheBustHashes;
|
|
1286
|
+
watchModeCache.allArticlePaths = [...allSourceFilenamesThatAreArticles];
|
|
1287
|
+
watchModeCache.imageMap = imageMap;
|
|
1288
|
+
watchModeCache.customMenus = customMenus;
|
|
1289
|
+
watchModeCache.ursaMetadata = ursaMetadata;
|
|
1290
|
+
watchModeCache.lastFullBuild = Date.now();
|
|
1291
|
+
watchModeCache.isInitialized = true;
|
|
1292
|
+
const depStats = dependencyTracker.getStats();
|
|
1293
|
+
progress.log(`Watch cache initialized (${depStats.totalDocuments} documents, ${depStats.uniqueFiles} dependencies tracked)`);
|
|
1294
|
+
|
|
1295
|
+
// Write error report if there were any errors
|
|
1296
|
+
if (errors.length > 0) {
|
|
1297
|
+
const errorReportPath = join(output, '_errors.log');
|
|
1298
|
+
const failedFiles = errors.map(e => e.file);
|
|
1299
|
+
|
|
1300
|
+
let report = `URSA GENERATION ERROR REPORT\n`;
|
|
1301
|
+
report += `Generated: ${new Date().toISOString()}\n`;
|
|
1302
|
+
report += `Total errors: ${errors.length}\n\n`;
|
|
1303
|
+
report += `${'='.repeat(60)}\n`;
|
|
1304
|
+
report += `FAILED FILES:\n`;
|
|
1305
|
+
report += `${'='.repeat(60)}\n\n`;
|
|
1306
|
+
failedFiles.forEach(f => {
|
|
1307
|
+
report += ` - ${f}\n`;
|
|
1308
|
+
});
|
|
1309
|
+
report += `\n${'='.repeat(60)}\n`;
|
|
1310
|
+
report += `ERROR DETAILS:\n`;
|
|
1311
|
+
report += `${'='.repeat(60)}\n\n`;
|
|
1312
|
+
|
|
1313
|
+
errors.forEach(({ file, phase, error }) => {
|
|
1314
|
+
report += `${'─'.repeat(60)}\n`;
|
|
1315
|
+
report += `File: ${file}\n`;
|
|
1316
|
+
report += `Phase: ${phase}\n`;
|
|
1317
|
+
report += `Error: ${error.message}\n`;
|
|
1318
|
+
if (error.stack) {
|
|
1319
|
+
report += `Stack:\n${error.stack}\n`;
|
|
1320
|
+
}
|
|
1321
|
+
report += `\n`;
|
|
1322
|
+
});
|
|
1323
|
+
|
|
1324
|
+
await outputFile(errorReportPath, report);
|
|
1325
|
+
progress.log(`\n⚠️ ${errors.length} error(s) occurred during generation.`);
|
|
1326
|
+
progress.log(` Error report written to: ${errorReportPath}\n`);
|
|
1327
|
+
} else {
|
|
1328
|
+
progress.log(`\n✅ Generation complete with no errors.\n`);
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
progress.done('Finalization', `complete [${progress.stopTimer('Finalization')}]`);
|
|
1332
|
+
profiler.endPhase('Finalization');
|
|
1333
|
+
|
|
1334
|
+
// Print profiler report
|
|
1335
|
+
progress.log(profiler.report());
|
|
1336
|
+
|
|
1337
|
+
// Terminate worker pool so threads don't keep the process alive
|
|
1338
|
+
await terminateParserPool();
|
|
1339
|
+
|
|
1340
|
+
// Return deferred processing promises if in deferred mode
|
|
1341
|
+
// Caller can await these to know when background processing is complete
|
|
1342
|
+
return {
|
|
1343
|
+
deferredImageProcessing: deferredImageProcessingPromise,
|
|
1344
|
+
deferredSearchIndex: deferredSearchIndexPromise
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* Regenerate multiple documents affected by a dependency change (e.g., style.css, script.js, template).
|
|
1350
|
+
* Uses the watchModeCache and dependency tracker to efficiently re-render affected documents
|
|
1351
|
+
* with updated cache-bust timestamps.
|
|
1352
|
+
*
|
|
1353
|
+
* @param {string[]} documentPaths - Absolute paths to documents to regenerate
|
|
1354
|
+
* @param {Object} options
|
|
1355
|
+
* @param {string} options._source - Source directory
|
|
1356
|
+
* @param {string} options._meta - Meta directory
|
|
1357
|
+
* @param {string} options._output - Output directory
|
|
1358
|
+
* @param {string} [options.reason] - Reason for regeneration (for logging)
|
|
1359
|
+
* @param {string[]} [options.priorityPaths] - Document paths to regenerate first (e.g. client-viewed docs)
|
|
1360
|
+
* @param {function} [options.onPriorityComplete] - Callback after priority paths are done (receives { regenerated, failed })
|
|
1361
|
+
* @returns {Promise<{success: boolean, message: string, regenerated: number, failed: number}>}
|
|
1362
|
+
*/
|
|
1363
|
+
export async function regenerateAffectedDocuments(documentPaths, {
|
|
1364
|
+
_source,
|
|
1365
|
+
_meta,
|
|
1366
|
+
_output,
|
|
1367
|
+
reason = "dependency change",
|
|
1368
|
+
priorityPaths = [],
|
|
1369
|
+
onPriorityComplete = null,
|
|
1370
|
+
} = {}) {
|
|
1371
|
+
const startTime = Date.now();
|
|
1372
|
+
|
|
1373
|
+
if (!watchModeCache.isInitialized) {
|
|
1374
|
+
return { success: false, message: "Cache not initialized - need full build first", regenerated: 0, failed: 0 };
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
if (documentPaths.length === 0) {
|
|
1378
|
+
return { success: true, message: "No documents to regenerate", regenerated: 0, failed: 0 };
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// Generate a fresh cache-bust timestamp for this invalidation pass
|
|
1382
|
+
const newTimestamp = generateCacheBustTimestamp();
|
|
1383
|
+
watchModeCache.cacheBustTimestamp = newTimestamp;
|
|
1384
|
+
|
|
1385
|
+
let regenerated = 0;
|
|
1386
|
+
let failed = 0;
|
|
1387
|
+
|
|
1388
|
+
// Separate priority paths from the rest
|
|
1389
|
+
const prioritySet = new Set(priorityPaths.map(p => resolve(p)));
|
|
1390
|
+
const priorityDocs = documentPaths.filter(p => prioritySet.has(resolve(p)));
|
|
1391
|
+
const remainingDocs = documentPaths.filter(p => !prioritySet.has(resolve(p)));
|
|
1392
|
+
|
|
1393
|
+
if (priorityDocs.length > 0) {
|
|
1394
|
+
console.log(`🔄 Regenerating ${priorityDocs.length} priority documents first, then ${remainingDocs.length} remaining (${reason})`);
|
|
1395
|
+
} else {
|
|
1396
|
+
console.log(`🔄 Regenerating ${documentPaths.length} documents (${reason})`);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
// Process priority documents first
|
|
1400
|
+
for (const docPath of priorityDocs) {
|
|
1401
|
+
try {
|
|
1402
|
+
const result = await regenerateSingleFile(docPath, { _source, _meta, _output });
|
|
1403
|
+
if (result.success) {
|
|
1404
|
+
regenerated++;
|
|
1405
|
+
} else {
|
|
1406
|
+
console.warn(` ⚠️ ${docPath}: ${result.message}`);
|
|
1407
|
+
failed++;
|
|
1408
|
+
}
|
|
1409
|
+
} catch (e) {
|
|
1410
|
+
console.error(` ❌ ${docPath}: ${e.message}`);
|
|
1411
|
+
failed++;
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
// Notify caller that priority docs are done (so server can reload those clients immediately)
|
|
1416
|
+
if (priorityDocs.length > 0 && onPriorityComplete) {
|
|
1417
|
+
try {
|
|
1418
|
+
onPriorityComplete({ regenerated, failed, priorityDocs });
|
|
1419
|
+
} catch (e) {
|
|
1420
|
+
console.error(` ⚠️ onPriorityComplete callback error: ${e.message}`);
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
// Process remaining documents
|
|
1425
|
+
for (const docPath of remainingDocs) {
|
|
1426
|
+
try {
|
|
1427
|
+
const result = await regenerateSingleFile(docPath, { _source, _meta, _output });
|
|
1428
|
+
if (result.success) {
|
|
1429
|
+
regenerated++;
|
|
1430
|
+
} else {
|
|
1431
|
+
console.warn(` ⚠️ ${docPath}: ${result.message}`);
|
|
1432
|
+
failed++;
|
|
1433
|
+
}
|
|
1434
|
+
} catch (e) {
|
|
1435
|
+
console.error(` ❌ ${docPath}: ${e.message}`);
|
|
1436
|
+
failed++;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
// Persist updated dependency registrations (e.g. a doc switched templates)
|
|
1441
|
+
if (regenerated > 0) {
|
|
1442
|
+
await saveDependencyTracker(resolve(_source) + "/");
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
const elapsed = Date.now() - startTime;
|
|
1446
|
+
const msg = `Regenerated ${regenerated}/${documentPaths.length} documents in ${elapsed}ms (${reason})${failed > 0 ? `, ${failed} failed` : ""}`;
|
|
1447
|
+
console.log(`✅ ${msg}`);
|
|
1448
|
+
return { success: failed === 0, message: msg, regenerated, failed };
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
/**
|
|
1452
|
+
* Regenerate a single file without scanning the entire source directory.
|
|
1453
|
+
* This is much faster for watch mode - only regenerate what changed.
|
|
1454
|
+
*
|
|
1455
|
+
* @param {string} changedFile - Absolute path to the file that changed
|
|
1456
|
+
* @param {Object} options - Same options as generate()
|
|
1457
|
+
* @returns {Promise<{success: boolean, message: string}>}
|
|
1458
|
+
*/
|
|
1459
|
+
export async function regenerateSingleFile(changedFile, {
|
|
1460
|
+
_source,
|
|
1461
|
+
_meta,
|
|
1462
|
+
_output,
|
|
1463
|
+
} = {}) {
|
|
1464
|
+
const startTime = Date.now();
|
|
1465
|
+
const source = resolve(_source) + "/";
|
|
1466
|
+
const meta = resolve(_meta);
|
|
1467
|
+
const output = resolve(_output) + "/";
|
|
1468
|
+
|
|
1469
|
+
// Check if this is an article file we can regenerate
|
|
1470
|
+
const articleExtensions = /\.(md|mdx|txt|yml)$/;
|
|
1471
|
+
if (!changedFile.match(articleExtensions)) {
|
|
1472
|
+
return { success: false, message: `Not an article file: ${changedFile}` };
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
// Check if cache is initialized
|
|
1476
|
+
if (!watchModeCache.isInitialized) {
|
|
1477
|
+
return { success: false, message: 'Cache not initialized - need full build first' };
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
// Verify paths match cached paths
|
|
1481
|
+
if (watchModeCache.source !== source || watchModeCache.output !== output) {
|
|
1482
|
+
return { success: false, message: 'Paths changed - need full rebuild' };
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
try {
|
|
1486
|
+
const { templates, menu, footer, validPaths, hashCache, cacheBustTimestamp, imageMap, customMenus, ursaMetadata } = watchModeCache;
|
|
1487
|
+
|
|
1488
|
+
const rawBody = await readFile(changedFile, "utf8");
|
|
1489
|
+
const type = parse(changedFile).ext;
|
|
1490
|
+
const ext = extname(changedFile);
|
|
1491
|
+
const base = basename(changedFile, ext);
|
|
1492
|
+
const dir = addTrailingSlash(dirname(changedFile)).replace(source, "");
|
|
1493
|
+
|
|
1494
|
+
// Calculate output paths
|
|
1495
|
+
const outputFilename = changedFile
|
|
1496
|
+
.replace(source, output)
|
|
1497
|
+
.replace(parse(changedFile).ext, ".html");
|
|
1498
|
+
const url = '/' + outputFilename.replace(output, '');
|
|
1499
|
+
|
|
1500
|
+
// Title from filename (for index/home, use parent folder name)
|
|
1501
|
+
const titleBase = (base === 'index' || base === 'home') ? basename(dirname(changedFile)) : base;
|
|
1502
|
+
const title = toTitleCase(titleBase || base);
|
|
1503
|
+
|
|
1504
|
+
// Extract metadata
|
|
1505
|
+
const fileMeta = extractMetadata(rawBody);
|
|
1506
|
+
const transformedMetadata = await getTransformedMetadata(
|
|
1507
|
+
dirname(changedFile),
|
|
1508
|
+
fileMeta
|
|
1509
|
+
);
|
|
1510
|
+
|
|
1511
|
+
// Calculate the document's URL path
|
|
1512
|
+
const docUrlPath = '/' + dir + base + '.html';
|
|
1513
|
+
|
|
1514
|
+
// Check if hydration should be enabled for MDX files
|
|
1515
|
+
const shouldHydrate = type === '.mdx' && fileMeta?.hydrate === true;
|
|
1516
|
+
|
|
1517
|
+
// Render body (use async for .mdx, sync for .md/.txt)
|
|
1518
|
+
let body;
|
|
1519
|
+
let hydrationScript = '';
|
|
1520
|
+
if (type === '.mdx') {
|
|
1521
|
+
const renderResult = await renderFileAsync({
|
|
1522
|
+
fileContents: rawBody,
|
|
1523
|
+
type,
|
|
1524
|
+
dirname: dir,
|
|
1525
|
+
basename: base,
|
|
1526
|
+
filePath: changedFile,
|
|
1527
|
+
sourceRoot: source,
|
|
1528
|
+
useWorker: false,
|
|
1529
|
+
hydrate: shouldHydrate,
|
|
1530
|
+
});
|
|
1531
|
+
|
|
1532
|
+
// Handle the result - can be string or { html, hydrationScript }
|
|
1533
|
+
if (typeof renderResult === 'object' && renderResult.html) {
|
|
1534
|
+
body = renderResult.html;
|
|
1535
|
+
hydrationScript = renderResult.hydrationScript || '';
|
|
1536
|
+
} else {
|
|
1537
|
+
body = renderResult;
|
|
1538
|
+
}
|
|
1539
|
+
} else {
|
|
1540
|
+
body = renderFile({
|
|
1541
|
+
fileContents: rawBody,
|
|
1542
|
+
type,
|
|
1543
|
+
dirname: dir,
|
|
1544
|
+
basename: base,
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
// Inject default H1 if body doesn't start with one
|
|
1549
|
+
if (!body || !body.trimStart().startsWith('<h1')) {
|
|
1550
|
+
const h1Title = fileMeta?.title || title;
|
|
1551
|
+
body = `<h1>${h1Title}</h1>\n` + (body || '');
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// Inject breadcrumbs before the H1
|
|
1555
|
+
const breadcrumbs = generateBreadcrumbs(dir, base, fileMeta);
|
|
1556
|
+
if (breadcrumbs) {
|
|
1557
|
+
body = breadcrumbs + body;
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
// Inject frontmatter table for markdown/mdx files
|
|
1561
|
+
if ((type === '.md' || type === '.mdx') && fileMeta) {
|
|
1562
|
+
body = injectFrontmatterTable(body, fileMeta);
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
// Handle auto-index generation for index files with generate-auto-index: true
|
|
1566
|
+
if (base === 'index' && fileMeta) {
|
|
1567
|
+
const autoIndexConfig = getAutoIndexConfig(fileMeta);
|
|
1568
|
+
if (autoIndexConfig.enabled) {
|
|
1569
|
+
// Generate auto-index HTML for this directory from source
|
|
1570
|
+
const sourceDir = dirname(changedFile);
|
|
1571
|
+
const autoIndexHtml = await generateAutoIndexHtmlFromSource(sourceDir, autoIndexConfig.depth);
|
|
1572
|
+
|
|
1573
|
+
if (autoIndexHtml) {
|
|
1574
|
+
if (autoIndexConfig.position === 'bottom') {
|
|
1575
|
+
body = body + '\n' + autoIndexHtml;
|
|
1576
|
+
} else {
|
|
1577
|
+
body = autoIndexHtml + '\n' + body;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// Find all CSS files up the tree and create separate link tags
|
|
1584
|
+
// (regenerateSingleFile is used in serve mode, so separate tags per level for invalidation)
|
|
1585
|
+
let styleLink = "";
|
|
1586
|
+
let cssPaths = [];
|
|
1587
|
+
try {
|
|
1588
|
+
const dirKey = (dir === "/" || dir === "") ? _source : resolve(_source, dir);
|
|
1589
|
+
cssPaths = await findAllStyleCss(dirKey, _source);
|
|
1590
|
+
if (cssPaths.length > 0) {
|
|
1591
|
+
// Copy all CSS files to output (always copy in single-file mode to ensure up to date)
|
|
1592
|
+
for (const cssPath of cssPaths) {
|
|
1593
|
+
const cssOutputPath = cssPath.replace(source, output);
|
|
1594
|
+
const cssContent = await readFile(cssPath, 'utf8');
|
|
1595
|
+
await outputFile(cssOutputPath, cssContent);
|
|
1596
|
+
}
|
|
1597
|
+
styleLink = generateSeparateCssTags(cssPaths, source);
|
|
1598
|
+
}
|
|
1599
|
+
} catch (e) {
|
|
1600
|
+
// ignore
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
// Get template
|
|
1604
|
+
const requestedTemplateName = fileMeta && fileMeta.template;
|
|
1605
|
+
const template =
|
|
1606
|
+
templates[requestedTemplateName] || templates[DEFAULT_TEMPLATE_NAME];
|
|
1607
|
+
|
|
1608
|
+
if (!template) {
|
|
1609
|
+
return { success: false, message: `Template not found: ${requestedTemplateName || DEFAULT_TEMPLATE_NAME}` };
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
// Find all script.js files from docroot to current dir and serve as separate external tags
|
|
1613
|
+
// (Serve mode: separate tags per level for individual invalidation)
|
|
1614
|
+
let customScript = "";
|
|
1615
|
+
let scriptPaths = [];
|
|
1616
|
+
try {
|
|
1617
|
+
const dirKey = (dir === "/" || dir === "") ? _source : resolve(_source, dir);
|
|
1618
|
+
scriptPaths = await findAllScriptJs(dirKey, _source);
|
|
1619
|
+
if (scriptPaths.length > 0) {
|
|
1620
|
+
// Copy all script files to output so they can be served
|
|
1621
|
+
for (const scriptPath of scriptPaths) {
|
|
1622
|
+
const scriptOutputPath = scriptPath.replace(source, output);
|
|
1623
|
+
const scriptContent = await readFile(scriptPath, 'utf8');
|
|
1624
|
+
await outputFile(scriptOutputPath, scriptContent);
|
|
1625
|
+
}
|
|
1626
|
+
customScript = generateSeparateJsTags(scriptPaths, source);
|
|
1627
|
+
}
|
|
1628
|
+
} catch (e) {
|
|
1629
|
+
// ignore
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
// Register this document's dependencies (template, inherited CSS/JS) so
|
|
1633
|
+
// invalidation plans stay accurate after frontmatter/template changes.
|
|
1634
|
+
// Persisted to .ursa/dependency-graph.json by regenerateAffectedDocuments.
|
|
1635
|
+
const usedTemplateName = (requestedTemplateName && templates[requestedTemplateName])
|
|
1636
|
+
? requestedTemplateName
|
|
1637
|
+
: DEFAULT_TEMPLATE_NAME;
|
|
1638
|
+
dependencyTracker.registerDocument(changedFile, {
|
|
1639
|
+
templateName: usedTemplateName,
|
|
1640
|
+
cssPaths,
|
|
1641
|
+
scriptPaths,
|
|
1642
|
+
});
|
|
1643
|
+
|
|
1644
|
+
// Check if this file has a custom menu
|
|
1645
|
+
const customMenuInfo = customMenus ? getCustomMenuForFile(changedFile, source, customMenus) : null;
|
|
1646
|
+
|
|
1647
|
+
// Append hydration script to customScript if present (for MDX with hydrate: true)
|
|
1648
|
+
const finalCustomScript = hydrationScript
|
|
1649
|
+
? customScript + '\n' + hydrationScript
|
|
1650
|
+
: customScript;
|
|
1651
|
+
|
|
1652
|
+
// Build final HTML
|
|
1653
|
+
let finalHtml = template;
|
|
1654
|
+
const replacements = {
|
|
1655
|
+
"${title}": fileMeta?.title || title,
|
|
1656
|
+
"${menu}": menu,
|
|
1657
|
+
"${meta}": JSON.stringify(fileMeta),
|
|
1658
|
+
"${transformedMetadata}": transformedMetadata,
|
|
1659
|
+
"${body}": body,
|
|
1660
|
+
"${styleLink}": styleLink,
|
|
1661
|
+
"${customScript}": finalCustomScript,
|
|
1662
|
+
"${searchIndex}": "[]",
|
|
1663
|
+
"${footer}": footer
|
|
1664
|
+
};
|
|
1665
|
+
for (const [key, value] of Object.entries(replacements)) {
|
|
1666
|
+
finalHtml = finalHtml.replace(key, value);
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
// If this page has a custom menu, add data attributes to body
|
|
1670
|
+
if (customMenuInfo) {
|
|
1671
|
+
const menuPosition = customMenuInfo.menuPosition || 'top';
|
|
1672
|
+
finalHtml = finalHtml.replace(
|
|
1673
|
+
/<body([^>]*)>/,
|
|
1674
|
+
`<body$1 data-custom-menu="${customMenuInfo.menuJsonPath}" data-menu-position="${menuPosition}">`
|
|
1675
|
+
);
|
|
1676
|
+
} else {
|
|
1677
|
+
// No custom menu — default to top menu
|
|
1678
|
+
finalHtml = finalHtml.replace(
|
|
1679
|
+
/<body([^>]*)>/,
|
|
1680
|
+
`<body$1 data-menu-position="top">`
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
// Resolve relative URLs in raw HTML elements (img src, etc.)
|
|
1685
|
+
finalHtml = resolveRelativeUrls(finalHtml, docUrlPath);
|
|
1686
|
+
|
|
1687
|
+
// Mark broken links
|
|
1688
|
+
finalHtml = markInactiveLinks(finalHtml, validPaths, docUrlPath, false);
|
|
1689
|
+
|
|
1690
|
+
// Transform image tags to use preview images with data-fullsrc for originals
|
|
1691
|
+
if (imageMap) {
|
|
1692
|
+
finalHtml = transformImageTags(finalHtml, imageMap, docUrlPath);
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
// Add cache-busting timestamps to static file references
|
|
1696
|
+
finalHtml = addTimestampToHtmlStaticRefs(finalHtml, cacheBustTimestamp);
|
|
1697
|
+
|
|
1698
|
+
await outputFile(outputFilename, finalHtml);
|
|
1699
|
+
|
|
1700
|
+
// JSON output
|
|
1701
|
+
const jsonOutputFilename = outputFilename.replace(".html", ".json");
|
|
1702
|
+
const sections = (type === '.md' || type === '.mdx') ? extractSections(rawBody) : [];
|
|
1703
|
+
const jsonObject = {
|
|
1704
|
+
name: base,
|
|
1705
|
+
url,
|
|
1706
|
+
contents: rawBody,
|
|
1707
|
+
bodyHtml: body,
|
|
1708
|
+
metadata: fileMeta,
|
|
1709
|
+
sections,
|
|
1710
|
+
transformedMetadata,
|
|
1711
|
+
_ursa_metadata: ursaMetadata,
|
|
1712
|
+
};
|
|
1713
|
+
const json = JSON.stringify(jsonObject);
|
|
1714
|
+
await outputFile(jsonOutputFilename, json);
|
|
1715
|
+
|
|
1716
|
+
// XML output
|
|
1717
|
+
const xmlOutputFilename = outputFilename.replace(".html", ".xml");
|
|
1718
|
+
const xml = `<article>${o2x(jsonObject)}</article>`;
|
|
1719
|
+
await outputFile(xmlOutputFilename, xml);
|
|
1720
|
+
|
|
1721
|
+
// Folder-named index promotion (mirrors autoIndex behavior on full builds):
|
|
1722
|
+
// If the file is named like its parent folder (e.g. aletheia/aletheia.md) and
|
|
1723
|
+
// no explicit index.{md,mdx,txt,yml,html} exists alongside it, also write the
|
|
1724
|
+
// same outputs to <dir>/index.html|json|xml so the canonical URL stays fresh.
|
|
1725
|
+
const sourceDirOfFile = dirname(changedFile);
|
|
1726
|
+
const parentFolderName = basename(sourceDirOfFile);
|
|
1727
|
+
if (base && parentFolderName && base === parentFolderName) {
|
|
1728
|
+
const hasExplicitIndex = ['index.md', 'index.mdx', 'index.txt', 'index.yml', 'index.html']
|
|
1729
|
+
.some(name => existsSync(join(sourceDirOfFile, name)));
|
|
1730
|
+
if (!hasExplicitIndex) {
|
|
1731
|
+
const outDirOfFile = dirname(outputFilename);
|
|
1732
|
+
await outputFile(join(outDirOfFile, 'index.html'), finalHtml);
|
|
1733
|
+
await outputFile(join(outDirOfFile, 'index.json'), json);
|
|
1734
|
+
await outputFile(join(outDirOfFile, 'index.xml'), xml);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
// Update hash cache
|
|
1739
|
+
updateHash(changedFile, rawBody, hashCache);
|
|
1740
|
+
|
|
1741
|
+
// Update recent-activity.json with this file's new content timestamp
|
|
1742
|
+
try {
|
|
1743
|
+
const now = Date.now();
|
|
1744
|
+
const recentActivityPath = join(output, 'public', 'recent-activity.json');
|
|
1745
|
+
let recentActivity = [];
|
|
1746
|
+
try {
|
|
1747
|
+
const existing = await readFile(recentActivityPath, 'utf8');
|
|
1748
|
+
recentActivity = JSON.parse(existing);
|
|
1749
|
+
} catch (e) { /* no existing file, start fresh */ }
|
|
1750
|
+
// Remove old entry for this URL if present
|
|
1751
|
+
recentActivity = recentActivity.filter(r => r.url !== url);
|
|
1752
|
+
// Add updated entry with current timestamp (content changed now)
|
|
1753
|
+
recentActivity.push({ title, url, mtime: now });
|
|
1754
|
+
// Sort by mtime descending, keep top 10
|
|
1755
|
+
recentActivity.sort((a, b) => b.mtime - a.mtime);
|
|
1756
|
+
recentActivity = recentActivity.slice(0, 10);
|
|
1757
|
+
await outputFile(recentActivityPath, JSON.stringify(recentActivity));
|
|
1758
|
+
|
|
1759
|
+
// Also update content timestamp in .ursa.json for persistence
|
|
1760
|
+
const relativePath = '/' + changedFile.replace(source, '').replace(/\.(md|mdx|txt|yml)$/, '.html');
|
|
1761
|
+
updateContentTimestamp(source, relativePath, now);
|
|
1762
|
+
} catch (e) {
|
|
1763
|
+
// ignore recent activity update errors
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
const elapsed = Date.now() - startTime;
|
|
1767
|
+
const shortFile = changedFile.replace(source, '');
|
|
1768
|
+
return { success: true, message: `Regenerated ${shortFile} in ${elapsed}ms` };
|
|
1769
|
+
} catch (e) {
|
|
1770
|
+
return { success: false, message: `Error: ${e.message}` };
|
|
1771
|
+
}
|
|
1715
1772
|
}
|