aboutsummaryrefslogtreecommitdiff
path: root/loading
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-04-22 14:32:03 +0530
committerBobby <[email protected]>2026-04-22 14:32:03 +0530
commitbbe9d34700995ba1644d726743dbb61144052bd1 (patch)
treebee0455edb7023d08b348022672ec2c294f2579c /loading
parent87f4e51a2804d0788c8cd1fcde56923d19d0e06c (diff)
downloadhollowdark-bbe9d34700995ba1644d726743dbb61144052bd1.tar.xz
hollowdark-bbe9d34700995ba1644d726743dbb61144052bd1.zip
Load the content manifest and cache every chunk to IndexedDB on initial loadHEADmain
Diffstat (limited to 'loading')
-rw-r--r--loading/content.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/loading/content.ts b/loading/content.ts
new file mode 100644
index 0000000..d3181fa
--- /dev/null
+++ b/loading/content.ts
@@ -0,0 +1,46 @@
+import { fetchManifest } from '@hollowdark/content-system/loader/loader'
+import { populateFromManifest } from '@hollowdark/content-system/registry/registry'
+import { setContentRegistry } from '@hollowdark/content-system/registry/singleton'
+import { loadingProgress } from '@hollowdark/loading/progress'
+
+/**
+ * Run the real initial-load pipeline. Fetches the content manifest,
+ * walks every chunk into the shared registry, and reports progress to
+ * the loading store so the initial-load screen's bar moves in real
+ * time. Falls back to whatever is cached when offline.
+ *
+ * `baseUrl` is the app's base path — empty string in local dev, the
+ * hosting sub-path under GitHub Pages.
+ */
+export async function runInitialLoad(baseUrl: string): Promise<void> {
+ loadingProgress.set({
+ percentage: 0,
+ currentMessage: 'Preparing your reading space',
+ phase: 'loading'
+ })
+
+ const manifest = await fetchManifest(baseUrl)
+ const chunkCount = Object.keys(manifest.chunks).length
+
+ if (chunkCount === 0) {
+ setContentRegistry(
+ await populateFromManifest(manifest, baseUrl, () => {})
+ )
+ loadingProgress.set({
+ percentage: 1,
+ currentMessage: 'Preparing your reading space',
+ phase: 'complete'
+ })
+ return
+ }
+
+ const registry = await populateFromManifest(manifest, baseUrl, (loaded, total) => {
+ loadingProgress.set({
+ percentage: loaded / total,
+ currentMessage: 'Preparing your reading space',
+ phase: loaded === total ? 'complete' : 'loading'
+ })
+ })
+
+ setContentRegistry(registry)
+}