🚧 Switch to monorepo with Turbo

This commit is contained in:
2023-01-10 12:53:42 +01:00
parent dd8715bb34
commit 25bb949a13
205 changed files with 14975 additions and 347 deletions

View File

@@ -0,0 +1,104 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
import { getRandomItems } from '$utils/functions'
export const load: PageServerLoad = async ({ setHeaders }) => {
try {
// Get data and total of published photos
const res = await fetchAPI(`query {
photos: photo (
filter: {
favorite: { _eq: true },
status: { _eq: "published" },
},
limit: -1,
) {
id
}
about {
description
intro_title
intro_heading
intro_text
intro_firstphoto { id, title }
intro_firstphoto_caption
intro_firstlocation {
slug
name
country {
flag { id, title }
slug
}
}
creation_title
creation_heading
creation_text
creation_portrait { id, title }
creation_portrait_caption
present_image { id, title }
present_title
present_heading
present_text
present_conclusion
image_showcase { id, title }
process_title
process_subtitle
process_steps {
title
text
media_type
image {
id
title
width, height
}
video_mp4 { id }
video_webm { id }
}
contact_title
contact_blocks
seo_title
seo_description
seo_image { id }
}
}`)
const { data: { about, photos: photosIds }} = res
// Get random photos
const randomPhotosIds = [...getRandomItems(photosIds, 42)].map(({ id }) => id)
// Query these random photos from IDs
const photosRes = await fetchAPI(`query {
photo (filter: { id: { _in: "${randomPhotosIds}" }}) {
id
title
slug
image {
id
title
}
}
}`)
if (photosRes) {
const { data: { photo: photos }} = photosRes
setHeaders({ 'Cache-Control': 'public, max-age=1, stale-while-revalidate=604799' })
return {
about,
photos,
}
}
} catch (err) {
throw error(500, err.message)
}
}