@uniweb/build 0.1.26 → 0.1.28
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/package.json +4 -3
- package/src/prerender.js +356 -257
- package/src/runtime-schema.js +135 -0
- package/src/site/asset-processor.js +32 -0
- package/src/site/assets.js +82 -0
- package/src/site/collection-processor.js +382 -0
- package/src/site/content-collector.js +60 -6
- package/src/site/data-fetcher.js +496 -0
- package/src/site/index.js +14 -0
- package/src/site/plugin.js +50 -0
package/src/site/plugin.js
CHANGED
|
@@ -36,6 +36,7 @@ import { readFile, readdir } from 'node:fs/promises'
|
|
|
36
36
|
import { collectSiteContent } from './content-collector.js'
|
|
37
37
|
import { processAssets, rewriteSiteContentPaths } from './asset-processor.js'
|
|
38
38
|
import { processAdvancedAssets } from './advanced-processors.js'
|
|
39
|
+
import { processCollections, writeCollectionFiles } from './collection-processor.js'
|
|
39
40
|
import { generateSearchIndex, isSearchEnabled, getSearchIndexFilename } from '../search/index.js'
|
|
40
41
|
import { mergeTranslations } from '../i18n/merge.js'
|
|
41
42
|
|
|
@@ -343,6 +344,14 @@ export function siteContentPlugin(options = {}) {
|
|
|
343
344
|
siteContent = await collectSiteContent(resolvedSitePath)
|
|
344
345
|
console.log(`[site-content] Collected ${siteContent.pages?.length || 0} pages`)
|
|
345
346
|
|
|
347
|
+
// Process content collections if defined in site.yml
|
|
348
|
+
// This generates JSON files in public/data/ BEFORE the Vite build
|
|
349
|
+
if (siteContent.config?.collections) {
|
|
350
|
+
console.log('[site-content] Processing content collections...')
|
|
351
|
+
const collections = await processCollections(resolvedSitePath, siteContent.config.collections)
|
|
352
|
+
await writeCollectionFiles(resolvedSitePath, collections)
|
|
353
|
+
}
|
|
354
|
+
|
|
346
355
|
// Update localesDir from site config
|
|
347
356
|
if (siteContent.config?.i18n?.localesDir) {
|
|
348
357
|
localesDir = siteContent.config.i18n.localesDir
|
|
@@ -383,6 +392,25 @@ export function siteContentPlugin(options = {}) {
|
|
|
383
392
|
}, 100)
|
|
384
393
|
}
|
|
385
394
|
|
|
395
|
+
// Debounce collection rebuilds separately (writes to file system)
|
|
396
|
+
let collectionRebuildTimeout = null
|
|
397
|
+
const scheduleCollectionRebuild = () => {
|
|
398
|
+
if (collectionRebuildTimeout) clearTimeout(collectionRebuildTimeout)
|
|
399
|
+
collectionRebuildTimeout = setTimeout(async () => {
|
|
400
|
+
console.log('[site-content] Collection content changed, regenerating JSON...')
|
|
401
|
+
try {
|
|
402
|
+
if (siteContent?.config?.collections) {
|
|
403
|
+
const collections = await processCollections(resolvedSitePath, siteContent.config.collections)
|
|
404
|
+
await writeCollectionFiles(resolvedSitePath, collections)
|
|
405
|
+
}
|
|
406
|
+
// Send full reload to client
|
|
407
|
+
server.ws.send({ type: 'full-reload' })
|
|
408
|
+
} catch (err) {
|
|
409
|
+
console.error('[site-content] Collection rebuild failed:', err.message)
|
|
410
|
+
}
|
|
411
|
+
}, 100)
|
|
412
|
+
}
|
|
413
|
+
|
|
386
414
|
// Track all watchers for cleanup
|
|
387
415
|
const watchers = []
|
|
388
416
|
|
|
@@ -408,6 +436,28 @@ export function siteContentPlugin(options = {}) {
|
|
|
408
436
|
// theme.yml may not exist, that's ok
|
|
409
437
|
}
|
|
410
438
|
|
|
439
|
+
// Watch content/ folder for collection changes
|
|
440
|
+
if (siteContent?.config?.collections) {
|
|
441
|
+
const contentPaths = new Set()
|
|
442
|
+
for (const config of Object.values(siteContent.config.collections)) {
|
|
443
|
+
const collectionPath = typeof config === 'string' ? config : config.path
|
|
444
|
+
if (collectionPath) {
|
|
445
|
+
contentPaths.add(resolve(resolvedSitePath, collectionPath))
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
for (const contentPath of contentPaths) {
|
|
450
|
+
if (existsSync(contentPath)) {
|
|
451
|
+
try {
|
|
452
|
+
watchers.push(watch(contentPath, { recursive: true }, scheduleCollectionRebuild))
|
|
453
|
+
console.log(`[site-content] Watching ${contentPath} for collection changes`)
|
|
454
|
+
} catch (err) {
|
|
455
|
+
console.warn('[site-content] Could not watch content directory:', err.message)
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
411
461
|
// Store watchers for cleanup
|
|
412
462
|
watcher = { close: () => watchers.forEach(w => w.close()) }
|
|
413
463
|
}
|