ceo optimization
This commit is contained in:
14
lib/api.ts
Normal file
14
lib/api.ts
Normal 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();
|
||||
}
|
||||
17
lib/generateStaticParam.ts
Normal file
17
lib/generateStaticParam.ts
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -13,4 +13,5 @@ export interface Product {
|
||||
description_ru: string;
|
||||
features:features[];
|
||||
image:string;
|
||||
slug?: string;
|
||||
}
|
||||
|
||||
12
lib/slug.ts
Normal file
12
lib/slug.ts
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user