ZH
测试版翻译

@core / catalog

1.0.0 ▾
已验证MIT
GitHub

商品目录:带选项的变体、以分计价、分类、合集、翻译和安全的库存预留

代码8 个文件上下文约 576 个 token扫描通过

应用 .genpmignore 后将被注入的确切目录树。固定于

src/lib/catalog/sources.ts只读 · 79d3468
// Fuentes de sitemap y buscador con los productos activos.
import { and, asc, eq, gt } from 'drizzle-orm';
import { defineSearchSource, defineSitemapSource } from '../contracts/index.ts';
import { getDb } from '../db/index.ts';
import { toPlainText } from '../rich-text/index.ts';
import { type Product, products } from './schema.ts';

async function* active(): AsyncGenerator<Product> {
  let after = '';
  for (;;) {
    const rows = await getDb().select().from(products).where(and(eq(products.status, 'active'), gt(products.id, after))).orderBy(asc(products.id)).limit(500);
    yield* rows;
    if (rows.length < 500) return;
    after = rows.at(-1)!.id;
  }
}

const defaultPath = (slug: string) => `/products/${slug}`;

export const productSitemapSource = (path = defaultPath) =>
  defineSitemapSource({
    name: 'products',
    async *urls() {
      for await (const p of active()) yield { loc: path(p.slug), lastmod: p.updatedAt };
    },
  });

export const productSearchSource = (path = defaultPath) =>
  defineSearchSource({
    type: 'product',
    async *documents() {
      for await (const p of active())
        yield {
          id: p.id,
          type: 'product',
          url: path(p.slug),
          title: p.name,
          body: [p.brand, p.tags.join(' '), Object.values(p.attributes).join(' '), p.description ? toPlainText(p.description) : ''].filter(Boolean).join('\n'),
          updatedAt: p.updatedAt,
        };
    },
  });

举报 @core/catalog

使用 GitHub 登录后才能举报包。