-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload-content-collections.ts
More file actions
31 lines (25 loc) · 1.26 KB
/
load-content-collections.ts
File metadata and controls
31 lines (25 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import path, { resolve } from "node:path"
import { pathToFileURL } from "node:url"
import type { Page } from "content-collections"
import type { Section } from "content-collections"
import type { Version } from "./version-resolvers"
/**
* Load content-collections outputs
* Always read from generated-docs
* If no tags/releases exist → fallback to main branch (production) or current (development)
* During development, if generated-docs missing → tell user to run generate:docs
*/
export async function loadContentCollections(version: Version) {
const projectRoot = process.cwd()
const genBase = resolve(projectRoot, "generated-docs", version, ".content-collections", "generated")
const pagesPath = pathToFileURL(path.join(genBase, "allPages.js")).href
const sectionsPath = pathToFileURL(path.join(genBase, "allSections.js")).href
const pagesMod = await import(/* @vite-ignore */ pagesPath)
const sectionsMod = await import(/* @vite-ignore */ sectionsPath)
const allPages = pagesMod.default as Page[]
const allSections = sectionsMod.default as Section[]
if (!Array.isArray(allPages) || !Array.isArray(allSections)) {
throw new Error(`Generated modules must default-export arrays (allPages/allSections) for version ${version}.`)
}
return { allPages, allSections }
}