-
-
Notifications
You must be signed in to change notification settings - Fork 611
/
cache.ts
26 lines (22 loc) · 867 Bytes
/
cache.ts
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
import { defineEventHandler } from 'h3'
import { getContentIndex } from '../content-index'
import { cacheStorage, serverQueryContent } from '../storage'
import type { NavItem } from '@nuxt/content'
import { useRuntimeConfig } from '#imports'
// This route is used to cache all the parsed content
export default defineEventHandler(async (event) => {
const { content } = useRuntimeConfig()
const now = Date.now()
// Fetch all content
const contents = await serverQueryContent(event).find()
// Generate Index
await getContentIndex(event)
const navigation: NavItem[] = await $fetch(`${content.api.baseURL}/navigation`)
await cacheStorage().setItem('content-navigation.json', navigation)
return {
generatedAt: now,
generateTime: Date.now() - now,
contents: content.experimental.cacheContents ? contents : [] as any,
navigation
}
})