1444aa3995
Yeni site_settings tablosu (singleton, rowId='homepage'): - Hero: badge, title, subtitle, 2 CTA (label+href), stats (JSON array) - Section başlıkları: services/projects/testimonials eyebrow + title + description - Alt CTA: title, description, button label+href - Contact: phone (görünen + tel: ham), email, address, hafta içi/sonu saatleri - Social: linkedin/instagram/twitter/facebook URL'leri - Footer tagline Mevcut hardcoded değerler seed edildi. Admin: - /admin/site sayfası eklendi (sidebar'a 'Site Ayarları' linki) - Bölümlü tek form: Hero / Hizmetler / Projeler / Referanslar / Alt CTA / İletişim / Sosyal / Footer - Stats için 'değer | etiket' satır formatı Public bağlantılar: - Hero component artık settings prop alıyor (fallback değerlerle) - Anasayfa: tüm section başlıkları ve alt CTA settings'ten geliyor - Header: telefon settings'ten - Footer: tagline, adres, telefon, email, sosyal linkler settings'ten (sosyal link sadece dolu olanlar gösteriliyor) - Footer'da hizmetler artık /hizmetler/[slug] detay sayfalarına bağlı - İletişim sayfası: adres, telefon, email, saatler settings'ten 30 route üretiliyor.
162 lines
4.0 KiB
TypeScript
162 lines
4.0 KiB
TypeScript
import "server-only";
|
|
import { DATABASE_ID, Q, TABLES, tablesDB } from "@/lib/appwrite-rest";
|
|
import { getSessionSecret } from "@/lib/auth";
|
|
import type {
|
|
BlogPostRow,
|
|
ContactMessageRow,
|
|
ProjectRow,
|
|
ServiceRow,
|
|
SeoPageRow,
|
|
SeoSettingsRow,
|
|
SiteSettingsRow,
|
|
TestimonialRow,
|
|
} from "@/lib/types";
|
|
|
|
async function safeList<T>(tableId: string, queries: string[]): Promise<T[]> {
|
|
try {
|
|
const res = await tablesDB.listRows<T>(DATABASE_ID, tableId, queries);
|
|
return res.rows;
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
async function safeListAuth<T>(tableId: string, queries: string[]): Promise<T[]> {
|
|
try {
|
|
const secret = await getSessionSecret();
|
|
const res = await tablesDB.listRows<T>(
|
|
DATABASE_ID,
|
|
tableId,
|
|
queries,
|
|
secret ?? undefined,
|
|
);
|
|
return res.rows;
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export async function listServices(opts?: { featured?: boolean }) {
|
|
const q = [Q.orderAsc("order"), Q.limit(50)];
|
|
if (opts?.featured) q.unshift(Q.equal("featured", true));
|
|
return safeList<ServiceRow>(TABLES.services, q);
|
|
}
|
|
|
|
export async function listProjects(opts?: {
|
|
featured?: boolean;
|
|
limit?: number;
|
|
serviceSlug?: string;
|
|
}) {
|
|
const q = [Q.orderDesc("year"), Q.limit(opts?.limit ?? 50)];
|
|
if (opts?.featured) q.unshift(Q.equal("featured", true));
|
|
if (opts?.serviceSlug) q.unshift(Q.equal("service_slug", opts.serviceSlug));
|
|
return safeList<ProjectRow>(TABLES.projects, q);
|
|
}
|
|
|
|
export async function getServiceBySlug(slug: string): Promise<ServiceRow | null> {
|
|
const res = await safeList<ServiceRow>(TABLES.services, [
|
|
Q.equal("slug", slug),
|
|
Q.limit(1),
|
|
]);
|
|
return res[0] ?? null;
|
|
}
|
|
|
|
export async function getProjectBySlug(slug: string): Promise<ProjectRow | null> {
|
|
const res = await safeList<ProjectRow>(TABLES.projects, [
|
|
Q.equal("slug", slug),
|
|
Q.limit(1),
|
|
]);
|
|
return res[0] ?? null;
|
|
}
|
|
|
|
export async function listPublishedPosts(opts?: { limit?: number }) {
|
|
return safeList<BlogPostRow>(TABLES.blogPosts, [
|
|
Q.equal("status", "published"),
|
|
Q.orderDesc("published_at"),
|
|
Q.limit(opts?.limit ?? 50),
|
|
]);
|
|
}
|
|
|
|
export async function listAllPosts() {
|
|
return safeListAuth<BlogPostRow>(TABLES.blogPosts, [
|
|
Q.orderDesc("$createdAt"),
|
|
Q.limit(200),
|
|
]);
|
|
}
|
|
|
|
export async function getPostBySlug(slug: string): Promise<BlogPostRow | null> {
|
|
const res = await safeList<BlogPostRow>(TABLES.blogPosts, [
|
|
Q.equal("slug", slug),
|
|
Q.limit(1),
|
|
]);
|
|
return res[0] ?? null;
|
|
}
|
|
|
|
export async function listTestimonials(opts?: { featured?: boolean }) {
|
|
const q = [Q.orderAsc("order"), Q.limit(50)];
|
|
if (opts?.featured) q.unshift(Q.equal("featured", true));
|
|
return safeList<TestimonialRow>(TABLES.testimonials, q);
|
|
}
|
|
|
|
export async function listMessages(status?: ContactMessageRow["status"]) {
|
|
const q = [Q.orderDesc("$createdAt"), Q.limit(200)];
|
|
if (status) q.unshift(Q.equal("status", status));
|
|
return safeListAuth<ContactMessageRow>(TABLES.contactMessages, q);
|
|
}
|
|
|
|
export async function getSeoPage(path: string): Promise<SeoPageRow | null> {
|
|
const res = await safeList<SeoPageRow>(TABLES.seoPages, [
|
|
Q.equal("path", path),
|
|
Q.limit(1),
|
|
]);
|
|
return res[0] ?? null;
|
|
}
|
|
|
|
export async function listSeoPages() {
|
|
return safeListAuth<SeoPageRow>(TABLES.seoPages, [
|
|
Q.orderAsc("path"),
|
|
Q.limit(200),
|
|
]);
|
|
}
|
|
|
|
export async function getSiteSettings(): Promise<SiteSettingsRow | null> {
|
|
try {
|
|
return await tablesDB.getRow<SiteSettingsRow>(
|
|
DATABASE_ID,
|
|
TABLES.siteSettings,
|
|
"homepage",
|
|
);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export async function getSeoSettings(): Promise<SeoSettingsRow | null> {
|
|
try {
|
|
return await tablesDB.getRow<SeoSettingsRow>(
|
|
DATABASE_ID,
|
|
TABLES.seoSettings,
|
|
"global",
|
|
);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export async function getRow<T>(
|
|
tableId: string,
|
|
rowId: string,
|
|
): Promise<T | null> {
|
|
try {
|
|
const secret = await getSessionSecret();
|
|
return await tablesDB.getRow<T>(
|
|
DATABASE_ID,
|
|
tableId,
|
|
rowId,
|
|
secret ?? undefined,
|
|
);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|