feat: admin paneli + blog + testimonials + SEO yöneticisi

Backend altyapısı:
- 4 yeni Appwrite tablosu: blog_posts, testimonials, seo_pages, seo_settings
- Appwrite Storage bucket: kovak-yazilim-media (görsel yüklemeleri)
- Appwrite Auth ile session cookie tabanlı koruma

Admin paneli (/admin):
- Login akışı (email/password) + protected layout
- Dashboard: sayım kartları + hızlı aksiyonlar
- Blog CRUD: markdown content, kapak görseli, draft/published, SEO alanları
- Services CRUD: lucide ikon seçici
- Projects CRUD: teknoloji etiketleri, live URL
- Testimonials CRUD: puanlama
- SEO yöneticisi: global ayarlar + sayfa bazlı override
- Mesaj inbox: status filtreleme + güncelleme
- Medya kütüphanesi: Appwrite Storage upload/delete

Public:
- /blog ve /blog/[slug] sayfaları (markdown render)
- Anasayfaya Testimonials bölümü
- Tüm public sayfalarda generateMetadata + seo_pages override
- Header'a Blog linki

Route yapısı:
- app/(site)/ — public site, Header/Footer ortak
- app/admin/login — auth dışı
- app/admin/(protected)/ — requireUser() korumalı

23 route üretiliyor, public static, admin dynamic.
This commit is contained in:
Ege Can Komur
2026-05-20 02:13:09 +03:00
parent 0f20309e4d
commit f833d429fc
52 changed files with 2999 additions and 81 deletions
+405
View File
@@ -0,0 +1,405 @@
"use server";
import { revalidatePath } from "next/cache";
import { ID } from "node-appwrite";
import { InputFile } from "node-appwrite/file";
import {
adminDB,
adminStorage,
DATABASE_ID,
MEDIA_BUCKET_ID,
TABLES,
} from "@/lib/appwrite-server";
import { getCurrentUser } from "@/lib/auth";
async function gate() {
const user = await getCurrentUser();
if (!user) throw new Error("Yetkisiz");
}
function slugify(s: string) {
return s
.toLowerCase()
.replace(/[ğ]/g, "g")
.replace(/[ü]/g, "u")
.replace(/[ş]/g, "s")
.replace(/[ı]/g, "i")
.replace(/[ö]/g, "o")
.replace(/[ç]/g, "c")
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-+|-+$/g, "")
.slice(0, 80);
}
function num(v: FormDataEntryValue | null) {
if (v === null || v === "") return null;
const n = Number(v);
return Number.isFinite(n) ? n : null;
}
function bool(v: FormDataEntryValue | null) {
return v === "on" || v === "true" || v === "1";
}
function str(v: FormDataEntryValue | null) {
if (v === null) return null;
const s = String(v).trim();
return s === "" ? null : s;
}
function strArr(v: FormDataEntryValue | null) {
if (v === null) return null;
return String(v)
.split(",")
.map((x) => x.trim())
.filter(Boolean);
}
// ─── Media upload ────────────────────────────────────────────────
export async function uploadMedia(formData: FormData): Promise<void> {
await gate();
const file = formData.get("file");
if (!(file instanceof File) || file.size === 0) {
throw new Error("Dosya seçilmedi");
}
const bytes = Buffer.from(await file.arrayBuffer());
await adminStorage.createFile({
bucketId: MEDIA_BUCKET_ID,
fileId: ID.unique(),
file: InputFile.fromBuffer(bytes, file.name),
});
revalidatePath("/admin/medya");
}
export async function deleteMediaFile(fileId: string) {
await gate();
await adminStorage.deleteFile({ bucketId: MEDIA_BUCKET_ID, fileId });
revalidatePath("/admin/medya");
}
// ─── Blog ────────────────────────────────────────────────────────
export async function saveBlogPost(formData: FormData) {
await gate();
const id = str(formData.get("id"));
const title = str(formData.get("title"));
if (!title) throw new Error("Başlık zorunlu");
const slug = str(formData.get("slug")) || slugify(title);
const status = (str(formData.get("status")) ?? "draft") as "draft" | "published";
const data = {
slug,
title,
excerpt: str(formData.get("excerpt")),
content: str(formData.get("content")),
cover_image: str(formData.get("cover_image")),
cover_file_id: str(formData.get("cover_file_id")),
author: str(formData.get("author")),
status,
published_at:
status === "published"
? str(formData.get("published_at")) || new Date().toISOString()
: null,
tags: strArr(formData.get("tags")),
seo_title: str(formData.get("seo_title")),
seo_description: str(formData.get("seo_description")),
seo_image: str(formData.get("seo_image")),
};
if (id) {
await adminDB.updateRow({
databaseId: DATABASE_ID,
tableId: TABLES.blogPosts,
rowId: id,
data,
});
} else {
await adminDB.createRow({
databaseId: DATABASE_ID,
tableId: TABLES.blogPosts,
rowId: ID.unique(),
data,
});
}
revalidatePath("/admin/blog");
revalidatePath("/blog");
if (slug) revalidatePath(`/blog/${slug}`);
}
export async function deleteBlogPost(formData: FormData) {
await gate();
const id = String(formData.get("id"));
await adminDB.deleteRow({
databaseId: DATABASE_ID,
tableId: TABLES.blogPosts,
rowId: id,
});
revalidatePath("/admin/blog");
revalidatePath("/blog");
}
// ─── Services ────────────────────────────────────────────────────
export async function saveService(formData: FormData) {
await gate();
const id = str(formData.get("id"));
const title = str(formData.get("title"));
if (!title) throw new Error("Başlık zorunlu");
const description = str(formData.get("description"));
if (!description) throw new Error("Açıklama zorunlu");
const slug = str(formData.get("slug")) || slugify(title);
const data = {
slug,
title,
description,
icon: str(formData.get("icon")),
order: num(formData.get("order")) ?? 0,
featured: bool(formData.get("featured")),
};
if (id) {
await adminDB.updateRow({
databaseId: DATABASE_ID,
tableId: TABLES.services,
rowId: id,
data,
});
} else {
await adminDB.createRow({
databaseId: DATABASE_ID,
tableId: TABLES.services,
rowId: slug,
data,
});
}
revalidatePath("/admin/hizmetler");
revalidatePath("/hizmetler");
revalidatePath("/");
}
export async function deleteService(formData: FormData) {
await gate();
const id = String(formData.get("id"));
await adminDB.deleteRow({
databaseId: DATABASE_ID,
tableId: TABLES.services,
rowId: id,
});
revalidatePath("/admin/hizmetler");
revalidatePath("/hizmetler");
}
// ─── Projects ────────────────────────────────────────────────────
export async function saveProject(formData: FormData) {
await gate();
const id = str(formData.get("id"));
const title = str(formData.get("title"));
if (!title) throw new Error("Başlık zorunlu");
const slug = str(formData.get("slug")) || slugify(title);
const description = str(formData.get("description"));
if (!description) throw new Error("Açıklama zorunlu");
const data = {
slug,
title,
description,
image_url: str(formData.get("image_url")),
live_url: str(formData.get("live_url")),
category: str(formData.get("category")),
technologies: strArr(formData.get("technologies")),
year: num(formData.get("year")),
featured: bool(formData.get("featured")),
};
if (id) {
await adminDB.updateRow({
databaseId: DATABASE_ID,
tableId: TABLES.projects,
rowId: id,
data,
});
} else {
await adminDB.createRow({
databaseId: DATABASE_ID,
tableId: TABLES.projects,
rowId: ID.unique(),
data,
});
}
revalidatePath("/admin/projeler");
revalidatePath("/projeler");
revalidatePath("/");
}
export async function deleteProject(formData: FormData) {
await gate();
const id = String(formData.get("id"));
await adminDB.deleteRow({
databaseId: DATABASE_ID,
tableId: TABLES.projects,
rowId: id,
});
revalidatePath("/admin/projeler");
revalidatePath("/projeler");
}
// ─── Testimonials ────────────────────────────────────────────────
export async function saveTestimonial(formData: FormData) {
await gate();
const id = str(formData.get("id"));
const name = str(formData.get("name"));
if (!name) throw new Error("Ad zorunlu");
const message = str(formData.get("message"));
if (!message) throw new Error("Mesaj zorunlu");
const data = {
name,
role: str(formData.get("role")),
company: str(formData.get("company")),
message,
rating: num(formData.get("rating")) ?? 5,
image_url: str(formData.get("image_url")),
order: num(formData.get("order")) ?? 0,
featured: bool(formData.get("featured")),
};
if (id) {
await adminDB.updateRow({
databaseId: DATABASE_ID,
tableId: TABLES.testimonials,
rowId: id,
data,
});
} else {
await adminDB.createRow({
databaseId: DATABASE_ID,
tableId: TABLES.testimonials,
rowId: ID.unique(),
data,
});
}
revalidatePath("/admin/referanslar");
revalidatePath("/");
}
export async function deleteTestimonial(formData: FormData) {
await gate();
const id = String(formData.get("id"));
await adminDB.deleteRow({
databaseId: DATABASE_ID,
tableId: TABLES.testimonials,
rowId: id,
});
revalidatePath("/admin/referanslar");
}
// ─── SEO Settings (singleton) ────────────────────────────────────
export async function saveSeoSettings(formData: FormData) {
await gate();
const data = {
site_name: str(formData.get("site_name")),
site_description: str(formData.get("site_description")),
default_og_image: str(formData.get("default_og_image")),
twitter_handle: str(formData.get("twitter_handle")),
facebook_url: str(formData.get("facebook_url")),
linkedin_url: str(formData.get("linkedin_url")),
instagram_url: str(formData.get("instagram_url")),
google_site_verification: str(formData.get("google_site_verification")),
gtm_id: str(formData.get("gtm_id")),
};
try {
await adminDB.updateRow({
databaseId: DATABASE_ID,
tableId: TABLES.seoSettings,
rowId: "global",
data,
});
} catch {
await adminDB.createRow({
databaseId: DATABASE_ID,
tableId: TABLES.seoSettings,
rowId: "global",
data,
});
}
revalidatePath("/", "layout");
revalidatePath("/admin/seo");
}
// ─── SEO Page (per path) ─────────────────────────────────────────
export async function saveSeoPage(formData: FormData) {
await gate();
const id = str(formData.get("id"));
const path = str(formData.get("path"));
if (!path) throw new Error("Path zorunlu");
const data = {
path,
title: str(formData.get("title")),
description: str(formData.get("description")),
og_image: str(formData.get("og_image")),
canonical: str(formData.get("canonical")),
noindex: bool(formData.get("noindex")),
};
if (id) {
await adminDB.updateRow({
databaseId: DATABASE_ID,
tableId: TABLES.seoPages,
rowId: id,
data,
});
} else {
await adminDB.createRow({
databaseId: DATABASE_ID,
tableId: TABLES.seoPages,
rowId: ID.unique(),
data,
});
}
revalidatePath(path);
revalidatePath("/admin/seo");
}
export async function deleteSeoPage(formData: FormData) {
await gate();
const id = String(formData.get("id"));
await adminDB.deleteRow({
databaseId: DATABASE_ID,
tableId: TABLES.seoPages,
rowId: id,
});
revalidatePath("/admin/seo");
}
// ─── Contact messages ────────────────────────────────────────────
export async function updateMessageStatus(formData: FormData) {
await gate();
const id = String(formData.get("id"));
const status = String(formData.get("status")) as
| "new"
| "read"
| "replied"
| "archived";
await adminDB.updateRow({
databaseId: DATABASE_ID,
tableId: TABLES.contactMessages,
rowId: id,
data: { status },
});
revalidatePath("/admin/iletisim");
}
export async function deleteMessage(formData: FormData) {
await gate();
const id = String(formData.get("id"));
await adminDB.deleteRow({
databaseId: DATABASE_ID,
tableId: TABLES.contactMessages,
rowId: id,
});
revalidatePath("/admin/iletisim");
}
+20 -4
View File
@@ -1,23 +1,39 @@
import "server-only";
import { Client, TablesDB } from "node-appwrite";
import { Account, Client, Storage, TablesDB } from "node-appwrite";
const endpoint = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!;
const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID!;
const apiKey = process.env.APPWRITE_API_KEY;
export const DATABASE_ID = process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID!;
export const MEDIA_BUCKET_ID =
process.env.NEXT_PUBLIC_APPWRITE_MEDIA_BUCKET_ID ?? "kovak-yazilim-media";
export const TABLES = {
contactMessages: "contact_messages",
services: "services",
projects: "projects",
blogPosts: "blog_posts",
testimonials: "testimonials",
seoPages: "seo_pages",
seoSettings: "seo_settings",
} as const;
function buildClient() {
export function adminClient() {
const c = new Client().setEndpoint(endpoint).setProject(projectId);
if (apiKey) c.setKey(apiKey);
return c;
}
export const serverClient = buildClient();
export const serverTablesDB = new TablesDB(serverClient);
export function sessionClient(sessionSecret: string) {
return new Client()
.setEndpoint(endpoint)
.setProject(projectId)
.setSession(sessionSecret);
}
export const adminDB = new TablesDB(adminClient());
export const adminStorage = new Storage(adminClient());
export const adminAccount = new Account(adminClient());
export { Account, TablesDB, Storage };
+25
View File
@@ -0,0 +1,25 @@
import "server-only";
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import { Account } from "node-appwrite";
import { sessionClient } from "@/lib/appwrite-server";
export const SESSION_COOKIE = "kovak_session";
export async function getCurrentUser() {
const store = await cookies();
const secret = store.get(SESSION_COOKIE)?.value;
if (!secret) return null;
try {
const account = new Account(sessionClient(secret));
return await account.get();
} catch {
return null;
}
}
export async function requireUser() {
const user = await getCurrentUser();
if (!user) redirect("/admin/login");
return user;
}
+91 -15
View File
@@ -1,34 +1,110 @@
import "server-only";
import { Query } from "node-appwrite";
import { serverTablesDB, DATABASE_ID, TABLES } from "@/lib/appwrite-server";
import type { ProjectRow, ServiceRow } from "@/lib/types";
import { adminDB, DATABASE_ID, TABLES } from "@/lib/appwrite-server";
import type {
BlogPostRow,
ContactMessageRow,
ProjectRow,
ServiceRow,
SeoPageRow,
SeoSettingsRow,
TestimonialRow,
} from "@/lib/types";
export async function listServices(opts?: { featured?: boolean }) {
const queries = [Query.orderAsc("order"), Query.limit(50)];
if (opts?.featured) queries.unshift(Query.equal("featured", true));
async function safeList<T>(
tableId: string,
queries: string[],
): Promise<T[]> {
try {
const res = await serverTablesDB.listRows<ServiceRow>({
const res = await adminDB.listRows<T extends import("appwrite").Models.Row ? T : never>({
databaseId: DATABASE_ID,
tableId: TABLES.services,
tableId,
queries,
});
return res.rows;
return res.rows as T[];
} catch {
return [];
}
}
export async function listServices(opts?: { featured?: boolean }) {
const q = [Query.orderAsc("order"), Query.limit(50)];
if (opts?.featured) q.unshift(Query.equal("featured", true));
return safeList<ServiceRow>(TABLES.services, q);
}
export async function listProjects(opts?: { featured?: boolean; limit?: number }) {
const queries = [Query.orderDesc("year"), Query.limit(opts?.limit ?? 50)];
if (opts?.featured) queries.unshift(Query.equal("featured", true));
const q = [Query.orderDesc("year"), Query.limit(opts?.limit ?? 50)];
if (opts?.featured) q.unshift(Query.equal("featured", true));
return safeList<ProjectRow>(TABLES.projects, q);
}
export async function listPublishedPosts(opts?: { limit?: number }) {
return safeList<BlogPostRow>(TABLES.blogPosts, [
Query.equal("status", "published"),
Query.orderDesc("published_at"),
Query.limit(opts?.limit ?? 50),
]);
}
export async function listAllPosts() {
return safeList<BlogPostRow>(TABLES.blogPosts, [
Query.orderDesc("$createdAt"),
Query.limit(200),
]);
}
export async function getPostBySlug(slug: string): Promise<BlogPostRow | null> {
const res = await safeList<BlogPostRow>(TABLES.blogPosts, [
Query.equal("slug", slug),
Query.limit(1),
]);
return res[0] ?? null;
}
export async function listTestimonials(opts?: { featured?: boolean }) {
const q = [Query.orderAsc("order"), Query.limit(50)];
if (opts?.featured) q.unshift(Query.equal("featured", true));
return safeList<TestimonialRow>(TABLES.testimonials, q);
}
export async function listMessages(status?: ContactMessageRow["status"]) {
const q = [Query.orderDesc("$createdAt"), Query.limit(200)];
if (status) q.unshift(Query.equal("status", status));
return safeList<ContactMessageRow>(TABLES.contactMessages, q);
}
export async function getSeoPage(path: string): Promise<SeoPageRow | null> {
const res = await safeList<SeoPageRow>(TABLES.seoPages, [
Query.equal("path", path),
Query.limit(1),
]);
return res[0] ?? null;
}
export async function listSeoPages() {
return safeList<SeoPageRow>(TABLES.seoPages, [
Query.orderAsc("path"),
Query.limit(200),
]);
}
export async function getSeoSettings(): Promise<SeoSettingsRow | null> {
try {
const res = await serverTablesDB.listRows<ProjectRow>({
return await adminDB.getRow<SeoSettingsRow>({
databaseId: DATABASE_ID,
tableId: TABLES.projects,
queries,
tableId: TABLES.seoSettings,
rowId: "global",
});
return res.rows;
} catch {
return [];
return null;
}
}
export async function getRow<T>(tableId: string, rowId: string): Promise<T | null> {
try {
return (await adminDB.getRow({ databaseId: DATABASE_ID, tableId, rowId })) as T;
} catch {
return null;
}
}
+53
View File
@@ -0,0 +1,53 @@
import "server-only";
import type { Metadata } from "next";
import { getSeoPage, getSeoSettings } from "@/lib/data";
import { siteConfig } from "@/lib/site-config";
export async function buildMetadata(path: string, fallback?: Metadata): Promise<Metadata> {
const [settings, override] = await Promise.all([
getSeoSettings(),
getSeoPage(path),
]);
const siteName = settings?.site_name || siteConfig.name;
const siteDesc = settings?.site_description || siteConfig.tagline;
const ogDefault = settings?.default_og_image || "/logo.png";
const title =
override?.title ?? (fallback?.title as string | undefined) ?? siteName;
const description =
override?.description ??
(fallback?.description as string | undefined) ??
siteDesc;
const ogImage = override?.og_image || ogDefault;
return {
title,
description,
metadataBase: new URL(siteConfig.url),
openGraph: {
title,
description,
images: ogImage ? [{ url: ogImage }] : undefined,
type: "website",
locale: "tr_TR",
siteName,
},
twitter: {
card: "summary_large_image",
title,
description,
images: ogImage ? [ogImage] : undefined,
site: settings?.twitter_handle ?? undefined,
},
alternates: override?.canonical
? { canonical: override.canonical }
: undefined,
robots: override?.noindex
? { index: false, follow: false }
: undefined,
verification: settings?.google_site_verification
? { google: settings.google_site_verification }
: undefined,
};
}
+52 -3
View File
@@ -21,10 +21,59 @@ export interface ProjectRow extends Models.Row {
featured?: boolean | null;
}
export interface ContactMessageInput {
export interface BlogPostRow extends Models.Row {
slug: string;
title: string;
excerpt?: string | null;
content?: string | null;
cover_image?: string | null;
cover_file_id?: string | null;
author?: string | null;
status?: "draft" | "published" | null;
published_at?: string | null;
tags?: string[] | null;
seo_title?: string | null;
seo_description?: string | null;
seo_image?: string | null;
}
export interface TestimonialRow extends Models.Row {
name: string;
role?: string | null;
company?: string | null;
message: string;
rating?: number | null;
image_url?: string | null;
order?: number | null;
featured?: boolean | null;
}
export interface SeoPageRow extends Models.Row {
path: string;
title?: string | null;
description?: string | null;
og_image?: string | null;
canonical?: string | null;
noindex?: boolean | null;
}
export interface SeoSettingsRow extends Models.Row {
site_name?: string | null;
site_description?: string | null;
default_og_image?: string | null;
twitter_handle?: string | null;
facebook_url?: string | null;
linkedin_url?: string | null;
instagram_url?: string | null;
google_site_verification?: string | null;
gtm_id?: string | null;
}
export interface ContactMessageRow extends Models.Row {
name: string;
email: string;
phone?: string;
subject?: string;
phone?: string | null;
subject?: string | null;
message: string;
status?: "new" | "read" | "replied" | "archived" | null;
}