104 lines
2.8 KiB
TypeScript
104 lines
2.8 KiB
TypeScript
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)
|
|
}
|
|
} |