🚧 Migrate to new SvelteKit routing system
A bit annoying but for the best I guess?
This commit is contained in:
91
src/routes/about/+page.server.ts
Normal file
91
src/routes/about/+page.server.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
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 () => {
|
||||
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_firstphoto {
|
||||
id
|
||||
title
|
||||
}
|
||||
intro_portraits {
|
||||
id
|
||||
title
|
||||
}
|
||||
intro_text
|
||||
intro_firstlocation {
|
||||
slug
|
||||
country {
|
||||
flag { id }
|
||||
slug
|
||||
}
|
||||
}
|
||||
|
||||
purpose_text
|
||||
|
||||
process_title
|
||||
process_subtitle
|
||||
process_steps {
|
||||
title
|
||||
text
|
||||
image {
|
||||
id
|
||||
title
|
||||
width, height
|
||||
}
|
||||
}
|
||||
process_intention
|
||||
|
||||
contact_title
|
||||
contact_blocks
|
||||
}
|
||||
}
|
||||
`)
|
||||
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
|
||||
|
||||
return {
|
||||
about,
|
||||
photos,
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
throw error(500, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user