File tree 2 files changed +31
-17
lines changed
2 files changed +31
-17
lines changed Original file line number Diff line number Diff line change 2
2
3
3
const { enabled , state } = usePreviewMode ()
4
4
5
- const globalStore = useGlobalStore ()
6
-
7
- const { data , error } = await useFetch (' /api/fetchLayout' )
8
- globalStore .header .primary = data .value .primary
9
- globalStore .header .secondary = data .value .secondary
10
- globalStore .footerPrimary .nodes = data .value .footerPrimary
11
- globalStore .footerSock .nodes = data .value .footerSock
12
- if (data .value ) {
13
- const globalData = removeEmpties (data .value ? .globalSets || [])
14
- // console.log("remove empties: " + JSON.stringify(globalData))
15
- // Shape data from Craft
16
- const craftData = Object .fromEntries (
17
- globalData? .map (item => [item .handle , item])
18
- )
19
- globalStore .globals = craftData
20
- }
21
-
22
5
</script >
23
6
<template >
24
7
<div >
Original file line number Diff line number Diff line change
1
+ export default defineNuxtPlugin ( async ( nuxtApp ) => {
2
+ const globalStore = useGlobalStore ( )
3
+
4
+ const { data, error } = await useFetch ( '/api/fetchLayout' , {
5
+ key : 'layout'
6
+ } )
7
+ if ( error . value ) {
8
+ throw createError ( {
9
+ ...error . value , statusMessage : 'Error while fetching data.' + error . value , fatal : true
10
+ } )
11
+ }
12
+ if ( ! data . value ?. primary || ! data . value ?. secondary || ! data . value ?. footerPrimary || ! data . value ?. footerSock || ! data . value ?. globalSets ) {
13
+ throw createError ( {
14
+ statusCode : 404 ,
15
+ statusMessage : 'Layout Data not found' ,
16
+ fatal : true
17
+ } )
18
+ }
19
+ globalStore . header . primary = data . value . primary
20
+ globalStore . header . secondary = data . value . secondary
21
+ globalStore . footerPrimary . nodes = data . value . footerPrimary
22
+ globalStore . footerSock . nodes = data . value . footerSock
23
+
24
+ const globalData = removeEmpties ( data . value ?. globalSets || [ ] )
25
+ // console.log("remove empties: " + JSON.stringify(globalData))
26
+ // Shape data from Craft
27
+ const craftData = Object . fromEntries (
28
+ globalData ?. map ( item => [ item . handle , item ] )
29
+ )
30
+ globalStore . globals = craftData
31
+ } )
You can’t perform that action at this time.
0 commit comments