-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcollections.ts
More file actions
42 lines (38 loc) · 1.25 KB
/
collections.ts
File metadata and controls
42 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type { CollectionKey } from 'astro:content'
import { getCollection } from 'astro:content'
import { content } from '../../content'
import { getDefaultTabForApi } from '../packageUtils'
export type EnrichedContentEntry = {
filePath: string
base?: string
data: {
tab: string
[key: string]: any
}
[key: string]: any
}
/**
* Fetches and enriches all content collections for a specific version
* Enriches entries with default tab information if not specified
*
* @param version - The documentation version (e.g., 'v6')
* @returns Promise resolving to array of collection entries with enriched metadata
*/
export async function getEnrichedCollections(version: string): Promise<EnrichedContentEntry[]> {
const contentEntries = content.filter((entry) => entry.version === version)
const collections = await Promise.all(
contentEntries.map((entry) => getCollection(entry.name as CollectionKey))
)
return collections.flatMap((collectionEntries, index) => {
const base = contentEntries[index].base
return collectionEntries.map(({ data, filePath = '', ...rest }) => ({
filePath,
base,
...rest,
data: {
...data,
tab: data.tab || data.source || getDefaultTabForApi(filePath),
},
}))
})
}