-
-
Notifications
You must be signed in to change notification settings - Fork 605
/
utils.ts
56 lines (46 loc) · 1.76 KB
/
utils.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { withBase } from 'ufo'
import { useRuntimeConfig, useRequestEvent, useCookie, useRoute } from '#app'
import { unwrap, flatUnwrap } from '../markdown-parser/utils/node'
export const withContentBase = (url: string) => withBase(url, '/api/' + useRuntimeConfig().public.content.base)
export const useUnwrap = () => ({
unwrap,
flatUnwrap
})
export const useContentDisabled = () => {
// Console warnings
// eslint-disable-next-line no-console
console.warn('useContent is only accessible when you are using `documentDriven` mode.')
// eslint-disable-next-line no-console
console.warn('Learn more by visiting: https://content.nuxtjs.org/guide/writing/document-driven')
// Break app
throw new Error('useContent is only accessible when you are using `documentDriven` mode.')
}
export const navigationDisabled = () => {
// Console warnings
// eslint-disable-next-line no-console
console.warn('Navigation is only accessible when you enable it in module options.')
// eslint-disable-next-line no-console
console.warn('Learn more by visiting: https://content.nuxtjs.org/api/configuration#navigation')
// Break app
throw new Error('Navigation is only accessible when you enable it in module options.')
}
export const addPrerenderPath = (path: string) => {
const event = useRequestEvent()
event.res.setHeader(
'x-nitro-prerender',
[
event.res.getHeader('x-nitro-prerender'),
path
].filter(Boolean).join(',')
)
}
export const shouldUseClientDB = () => {
const { clientDB } = useRuntimeConfig().content
if (!process.client) { return false }
if (clientDB?.isSPA) { return true }
// Disable clientDB when preview mode is disabled
if (useRoute().query?.preview || useCookie('previewToken').value) {
return true
}
return false
}