Initial commit
This commit is contained in:
92
landing/src/app/pages/(home).server.ts
Normal file
92
landing/src/app/pages/(home).server.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Everything the landing page renders, fetched on the server in one pass.
|
||||
*
|
||||
* The API is designed for a server-rendered frontend — slugs instead of ids,
|
||||
* `Vary: Accept-Language`, per-address submission throttling — so the whole
|
||||
* page is assembled here and hydrated with the result. Calls run in parallel
|
||||
* and none of them can reject: a section whose endpoint failed renders empty
|
||||
* instead of taking the page down with it.
|
||||
*/
|
||||
import type { PageServerLoad } from '@analogjs/router';
|
||||
|
||||
import {
|
||||
localeFromUrl,
|
||||
pireonApi,
|
||||
type Locale,
|
||||
type MaintenanceNotice,
|
||||
type SitePayload,
|
||||
} from '../core/api';
|
||||
import type {
|
||||
PublicCall,
|
||||
PublicClient,
|
||||
PublicIssue,
|
||||
PublicMember,
|
||||
PublicProject,
|
||||
PublicService,
|
||||
PublicTalk,
|
||||
PublicTechnology,
|
||||
PublicTestimonial,
|
||||
} from '../core/api.types';
|
||||
|
||||
export interface LandingData {
|
||||
locale: Locale;
|
||||
site: SitePayload | null;
|
||||
maintenance: MaintenanceNotice | null;
|
||||
services: PublicService[];
|
||||
projects: PublicProject[];
|
||||
clients: PublicClient[];
|
||||
testimonials: PublicTestimonial[];
|
||||
radar: PublicTechnology[];
|
||||
members: PublicMember[];
|
||||
calls: PublicCall[];
|
||||
issues: PublicIssue[];
|
||||
talks: PublicTalk[];
|
||||
}
|
||||
|
||||
export const load = async ({ req }: PageServerLoad): Promise<LandingData> => {
|
||||
// `params` carries route parameters only, and Analog resolves loaders
|
||||
// through an internal request that forwards the query string but not the
|
||||
// headers — so `?lang=` is the one signal available here.
|
||||
const locale = localeFromUrl(req?.url);
|
||||
|
||||
const [
|
||||
site,
|
||||
services,
|
||||
projects,
|
||||
clients,
|
||||
testimonials,
|
||||
radar,
|
||||
members,
|
||||
calls,
|
||||
issues,
|
||||
talks,
|
||||
] = await Promise.all([
|
||||
pireonApi.site(locale),
|
||||
pireonApi.services(locale),
|
||||
pireonApi.projects(locale, { per_page: 6, translated: true }),
|
||||
pireonApi.clients(locale),
|
||||
pireonApi.testimonials(locale),
|
||||
pireonApi.radar(locale),
|
||||
pireonApi.members(locale),
|
||||
pireonApi.calls(locale),
|
||||
pireonApi.goodFirstIssues({ limit: 6 }),
|
||||
pireonApi.talks(locale, { limit: 6 }),
|
||||
]);
|
||||
|
||||
return {
|
||||
locale,
|
||||
site: site.data,
|
||||
// `/site` is the one call worth believing about maintenance: it is the
|
||||
// endpoint the frontend hits on every page anyway.
|
||||
maintenance: site.maintenance,
|
||||
services: services.data ?? [],
|
||||
projects: projects.data ?? [],
|
||||
clients: clients.data ?? [],
|
||||
testimonials: testimonials.data ?? [],
|
||||
radar: radar.data ?? [],
|
||||
members: members.data ?? [],
|
||||
calls: calls.data ?? [],
|
||||
issues: issues.data ?? [],
|
||||
talks: talks.data ?? [],
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user