2023-04-04 12:39:11 +07:00
|
|
|
import type { PageServerLoad } from './$types'
|
2023-04-07 22:59:53 +07:00
|
|
|
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
|
|
|
|
import dayjs from 'dayjs'
|
2023-04-07 13:49:34 +07:00
|
|
|
export const load: PageServerLoad = async ({fetch}) => {
|
|
|
|
|
let content = ""
|
|
|
|
|
let exams:Exam[] = []
|
|
|
|
|
let res = await fetch("/api/content?page=competitive")
|
|
|
|
|
if(res.ok){
|
|
|
|
|
content = (await res.json()).content
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res = await fetch("/api/competitive")
|
|
|
|
|
if(res.ok){
|
|
|
|
|
exams = await res.json()
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 17:59:43 +07:00
|
|
|
const events:CalendarEvent[]=[]
|
2023-04-07 22:59:53 +07:00
|
|
|
exams.forEach((e)=>{
|
|
|
|
|
if(!e.start){
|
|
|
|
|
e.date=""
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
e.date= dayjs(e.start).format("DD MMM BBBB")
|
|
|
|
|
|
|
|
|
|
const {id,title,start,category_id} = e
|
|
|
|
|
|
2023-04-07 23:05:32 +07:00
|
|
|
let backgroundColor ="rgb(153 153 255 / 34%)"
|
2023-04-07 22:59:53 +07:00
|
|
|
if(category_id)
|
|
|
|
|
backgroundColor ="#99FFEE"
|
|
|
|
|
|
2023-04-05 17:59:43 +07:00
|
|
|
const url = "/competitive/"+id
|
|
|
|
|
events.push({id,title,start,url,backgroundColor})
|
|
|
|
|
})
|
2023-04-05 19:35:08 +07:00
|
|
|
return {content,exams,events}
|
2023-04-06 10:46:37 +07:00
|
|
|
}
|