Add support API for header, footer, Home image and small adjust.

This commit is contained in:
schooltechx 2023-04-07 23:56:23 +07:00
parent 692e6f3e24
commit 5af1f48150
10 changed files with 50 additions and 93 deletions

View file

@ -10,10 +10,12 @@
import type { LayoutData } from './$types';
export let data: LayoutData;
console.log(data)
let {logo_url,supervised,divisions,institutes,address,organization} = data
</script>
<Header />
<Header {logo_url} {organization} {supervised} />
<div class="justify-center place-content-center" style="padding-top:50px">
<slot />
</div>
<Footer />
<Footer {logo_url} {organization} {address} {divisions} {institutes} />

View file

@ -1,15 +1,18 @@
//import content from "$lib/data/content/home.html?raw"
//import { getQualifyExams,getCompetitiveExams } from '$lib/data/info';
import type { PageServerLoad } from './$types';
import type {Exam} from '$lib/components/Exam'
import type {Exam} from '$lib/data/CMSDataType'
import dayjs from 'dayjs'
export const load: PageServerLoad = async ({fetch}) => {
let qualify_exams: Exam[] = []
let competitive_exams: Exam[] = []
let content = ""
let image = undefined
let res = await fetch("/api/content?page=home")
if(res.ok){
content = (await res.json()).content
const r = await res.json()
content = r.content
image = r.image
}
res = await fetch("/api/qualifying")
if(res.ok){
@ -25,5 +28,5 @@ export const load: PageServerLoad = async ({fetch}) => {
e.start? dayjs(e.start).format("DD MMM BBBB"):""
})
}
return { content , qualify_exams,competitive_exams };
return { content,image, qualify_exams,competitive_exams };
};

View file

@ -1,16 +1,7 @@
<script lang="ts">
import type { PageData } from './$types';
export let data: PageData;
const qualify_exams = data.qualify_exams;
const competitive_exams = data.competitive_exams;
const patternVue = "/images/pattern.png";
const sel1 = "/images/sel1.png";
const sel2 = "/images/sel2.png";
const sel3 = "/images/sel3.png";
const c1 = "/images/c1.jpg";
const c2 = "/images/c2.jpg";
const c3 = "/images/c3.jpg";
const {qualify_exams,competitive_exams,image} = data
</script>
<section class="reative flex bg-gradient pt-10 pb-44 md:pb-38">
<div class="container mx-auto items-start flex flex-wrap">
@ -44,7 +35,7 @@
</div>
<img
class="absolute top-0 b-auto right-0 sm:w-5/12 sm:mt-32 pr-10 hidden md:flex"
src="{patternVue}"
src="{image}"
alt="..."
/>
</section>

View file

@ -6,10 +6,12 @@ import qualifying_content from "$lib/data/content/qualifying.html?raw"
import competitive_content from "$lib/data/content/competitive.html?raw"
export const GET: RequestHandler = async ({url}: RequestEvent) => {
let content = ""
let image = undefined
const page= url.searchParams.get("page") ?? 'nopage'
switch (page) {
case "home":
content = home_content
image = "/images/pattern.png"
break;
case "qualifying":
content = qualifying_content
@ -26,6 +28,6 @@ export const GET: RequestHandler = async ({url}: RequestEvent) => {
//slience error just send empty content if not found
if(!content)
console.log(`Request content ${page} not found`)
return json({content})
return json({content,image})
}

View file

@ -3,7 +3,7 @@ import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({params,fetch}) => {
const id = params.id+""
const res = await fetch("/api/compettive/"+id)
const res = await fetch("/api/competitive/"+id)
if(res.status==404){
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
}

View file

@ -50,7 +50,7 @@
{/if}
<hr class="border-blueGray-200 my-7" />
<div>
<a href="javascript:history.back()" class="btn btn-outline text-gray-500">
<a href="/competitive" class="btn btn-outline text-gray-500">
<i class="fa-solid fa-arrow-left mr-4"></i>
ย้อนกลับ
</a>

View file

@ -1,6 +1,5 @@
import type {CalendarEvent} from '$lib/data/CMSDataType'
import type {Exam} from '$lib/data/CMSDataType'
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
import dayjs from 'dayjs'
import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({fetch}) => {

View file

@ -50,7 +50,7 @@
{/if}
<hr class="border-blueGray-200 my-7" />
<div>
<a href="javascript:history.back()" class="btn btn-outline text-gray-500">
<a href="/qualifying" class="btn btn-outline text-gray-500">
<i class="fa-solid fa-arrow-left mr-4"></i>
ย้อนกลับ
</a>