JA
ベータ版の翻訳

@core / kit-store

1.0.1 ▾
認証済みMIT
GitHub

Next.js 向けオンラインストアキット:カタログ、カート、Stripe 決済、注文、配送、クーポン、レビュー、アカウント

コード27 ファイルコンテキスト約 1024 トークンスキャン合格

.genpmignore 適用後に組み込まれる正確なツリーです。固定先:

src/app/(store)/_lib/listing.tsx読み取り専用 · 6a45dae
// Listados de categoría y colección: mismo grid con distinto filtro.
import { eq } from 'drizzle-orm';
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { categories, collections, listProducts } from '@/lib/catalog';
import { getDb } from '@/lib/db';
import { buildMetadata } from '@/lib/seo';
import { ProductGrid } from '../_components/product-grid';
import { pageParam } from './store';

type Kind = 'category' | 'collection';
export type ListingProps = { params: Promise<{ slug: string }>; searchParams: Promise<Record<string, string | string[] | undefined>> };

async function load(kind: Kind, slug: string) {
  const table = kind === 'category' ? categories : collections;
  const [row] = await getDb().select({ name: table.name, description: table.description }).from(table).where(eq(table.slug, slug));
  return row ?? null;
}

export function listing(kind: Kind) {
  const base = kind === 'category' ? '/categories' : '/collections';
  return {
    async generateMetadata({ params }: ListingProps): Promise<Metadata> {
      const { slug } = await params;
      const t = await load(kind, slug);
      return t ? ((await buildMetadata({ title: t.name, path: `${base}/${slug}`, ...(t.description && { description: t.description.slice(0, 160) }) })) as Metadata) : {};
    },
    async Page({ params, searchParams }: ListingProps) {
      const { slug } = await params;
      const t = await load(kind, slug);
      if (!t) notFound();
      const page = pageParam(await searchParams);
      const { products, pages } = await listProducts({ [kind]: slug, page, perPage: 24 });
      return <ProductGrid title={t.name} intro={t.description ? <p>{t.description}</p> : undefined} products={products} page={page} pages={pages} basePath={`${base}/${slug}`} />;
    },
  };
}

@core/kit-store を報告

パッケージを報告するには GitHub でログインしてください。

GitHub で続ける