Files
Montech_Landing/apps/landing/composables/useSiteContent.ts
T
MahdiandCursor b0088c35d1 Replace the landing with the artifact design and rebuild the admin in Ant Design.
Adds consultation leads, section editors, and the one-time content reset for this release.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 20:36:06 +03:30

54 lines
1.6 KiB
TypeScript

import {
resolveSection,
type PublicSettings,
type PublicSitePayload,
type SectionKey,
type SiteSections,
} from "@montech/shared";
const SITE_KEY = "public-site";
export const DEFAULT_SETTINGS: PublicSettings = {
brandName: "منتک",
tagline: "هوش‌افزار منظر",
email: "info@montech.ir",
phone: "۰۹۱۲ ۳۴۵ ۶۷۸۹",
address: "تهران، ایران",
timezone: "Asia/Tehran",
socials: [],
logoUrl: null,
};
/**
* Loads the public site payload once per request (called from the default layout).
* A failed API call degrades to the built-in default content instead of breaking the page.
*/
export function loadSiteContent() {
return useAsyncData(SITE_KEY, () => apiFetch<PublicSitePayload>("/api/public/site").catch(() => null));
}
export function useSiteContent() {
const { data } = useNuxtData<PublicSitePayload | null>(SITE_KEY);
const settings = computed<PublicSettings>(() => {
const s = data.value?.settings;
if (!s) return DEFAULT_SETTINGS;
return {
...DEFAULT_SETTINGS,
...Object.fromEntries(Object.entries(s).filter(([, v]) => v !== "" && v !== null && v !== undefined)),
socials: Array.isArray(s.socials) ? s.socials.filter((x) => x && x.url) : [],
logoUrl: s.logoUrl || null,
};
});
function section<K extends SectionKey>(key: K) {
return computed<SiteSections[K]>(() => resolveSection(key, data.value?.sections?.[key]));
}
function pageSeo(key: string) {
return computed(() => data.value?.pages?.find((p) => p.key === key)?.seo ?? null);
}
return { data, settings, section, pageSeo };
}