ceo optimization

This commit is contained in:
nabijonovdavronbek619@gmail.com
2026-01-09 17:38:01 +05:00
parent a700fdddc6
commit c2c39d44a0
11 changed files with 117 additions and 50 deletions

14
lib/api.ts Normal file
View File

@@ -0,0 +1,14 @@
import { Product } from "@/lib/products";
export async function getAllProducts(): Promise<Product[]> {
const res = await fetch("https://admin.promtechno.uz/api/products/", {
cache: "force-cache", // build time uchun
});
if (!res.ok) {
console.log("Failed to fetch products");
return [];
}
return res.json();
}

View File

@@ -0,0 +1,17 @@
import axios from "axios";
import { generateSlug } from "./slug";
export async function generateStaticParams() {
try {
await axios.get("https://admin.promtechno.uz/api/products/").then((res) => {
console.log("all data: ", res?.data);
const allData = res?.data || [];
return allData.map((product: any) => ({
slug: generateSlug(product.name_uz),
}));
});
} catch (error) {
console.error("Error in generateStaticParams:", error);
return []; // Xato bo'lsa bo'sh array qaytarish
}
}

View File

@@ -9,18 +9,11 @@ interface ProductStore {
}
export const useProductStore = create<ProductStore>()(
devtools(
persist(
(set) => ({
productName: "",
setProductName: (name: string) => set({ productName: name }),
resetProductName: () => set({ productName: "" }),
}),
{
name: "product-storage",
}
)
)
devtools((set) => ({
productName: "",
setProductName: (name: string) => set({ productName: name }),
resetProductName: () => set({ productName: "" }),
}))
);
interface ProductDetail {

View File

@@ -13,4 +13,5 @@ export interface Product {
description_ru: string;
features:features[];
image:string;
slug?: string;
}

12
lib/slug.ts Normal file
View File

@@ -0,0 +1,12 @@
export function generateSlug(productName: string): string {
return productName
.toLowerCase()
.replace(/\s+/g, "-") // Bo'shliqlarni tire bilan almashtirish
.replace(/[()]/g, "") // Qavslarni olib tashlash
.replace(/[–—]/g, "-") // Maxsus tire'larni oddiy tire bilan
.replace(/%/g, "foiz") // % ni foiz deb yozish
.replace(/,/g, "-") // Vergullarni tire bilan
.replace(/\.+/g, "-") // Nuqtalarni tire bilan
.replace(/-+/g, "-") // Bir nechta tire'ni bitta tire bilan
.replace(/^-|-$/g, ""); // Boshi va oxiridagi tire'larni olib tashlash
}