M1:搜索筛选、品牌页、sitemap/robots、JSON-LD

This commit is contained in:
zhongluofeng authored and trae-solo-agent committed 2026-10-30 16:11:00 +08:00
1 parent 8430e5304d
commit 0c30c79696
11 files changed
+354 -25

No files matched your search

+3
View File
@@ -1,2 +1,5 @@
# 使用项目内 store,避免本机全局 store 目录(D:\.pnpm-store)的写权限问题
store-dir=.pnpm-store
# 本项目在沙箱环境执行命令时,符号链接会被重定向到虚拟路径并失效,
# 因此改用 hoisted 扁平结构,避免 junction 依赖。
node-linker=hoisted
+2 -2
View File
@@ -6,8 +6,8 @@ import tailwindcss from '@tailwindcss/vite';
// https://astro.build/config
export default defineConfig({
// TODO: 上线时改成正式域名,影响 sitemap / canonical / OG
site: 'http://localhost:4321',
// 正式站点地址,影响 canonical / sitemap / OG
site: 'https://specs.atie.fun',
output: 'server',
adapter: node({ mode: 'standalone' }),
integrations: [react()],
+4 -4
View File
@@ -37,7 +37,7 @@ importers:
version: 6.2.14
lucide-react:
specifier: ^1.64.0
version: 1.64.0(@types/react@19.3.0)(react@19.3.1)
version: 1.65.0(@types/react@19.3.0)(react@19.3.1)
motion:
specifier: ^14.8.0
version: 14.8.0(react-dom@19.3.1(react@19.3.1))(react@19.3.1)
@@ -1356,8 +1356,8 @@ packages:
resolution: {integrity: sha512-U4N8FgzmWxc8k1VH8Kr6lQg18U7Fjvby6wXHVRX/ZZ7IwWbRMgrRbP0Wrb5q5NVinryp4SQampHKdvtecItxUg==}
engines: {node: 20 || >=22}
lucide-react@1.64.0:
resolution: {integrity: sha512-v626F/bcLNvFom6vzztHILtG9tUgXXbgA5AGkd82YkV401+Ko/NHyrWafbPwGofa+6p/EgDJcvEkIwsMH9098w==}
lucide-react@1.65.0:
resolution: {integrity: sha512-roSdtzudEY39i2hn5LLjA8toYfhF2z4S10WSqZF4ubXpHlOmNTvaxMxZLdJfQDi6pEifQWX+cRmYihKSsvAxfA==}
peerDependencies:
'@types/react': '*'
react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0
@@ -3031,7 +3031,7 @@ snapshots:
lru-cache@11.5.3: {}
lucide-react@1.64.0(@types/react@19.3.0)(react@19.3.1):
lucide-react@1.65.0(@types/react@19.3.0)(react@19.3.1):
dependencies:
react: 19.3.1
optionalDependencies:
+6
View File
@@ -0,0 +1,6 @@
User-agent: *
Allow: /
Disallow: /admin
Disallow: /api
Sitemap: https://specs.atie.fun/sitemap.xml
+1
View File
@@ -29,6 +29,7 @@ const {
<nav class="flex items-center gap-1 text-sm text-muted-foreground">
<a href="/devices" class="rounded-md px-2.5 py-1.5 transition-colors hover:bg-accent hover:text-foreground">手机</a>
<a href="/chips" class="rounded-md px-2.5 py-1.5 transition-colors hover:bg-accent hover:text-foreground">芯片</a>
<a href="/brands" class="rounded-md px-2.5 py-1.5 transition-colors hover:bg-accent hover:text-foreground">品牌</a>
<a href="/poc" class="rounded-md px-2.5 py-1.5 transition-colors hover:bg-accent hover:text-foreground">组件自检</a>
</nav>
</div>
+51 -6
View File
@@ -53,16 +53,61 @@ function rowToChip(row: Row): Chip {
/* ------------------------------- devices ------------------------------- */
export function listDevices(options: { category?: DeviceCategory } = {}): Device[] {
export type DeviceSort = 'latest' | 'name' | 'brand';
export interface DeviceQuery {
category?: DeviceCategory;
brand?: string;
q?: string;
sort?: DeviceSort;
}
/** 列表查询:分类 / 品牌 / 关键词 / 排序,全部走参数化 SQL */
export function listDevices(query: DeviceQuery = {}): Device[] {
const db = getDb();
const rows = options.category
const where: string[] = [];
const params: string[] = [];
if (query.category) {
where.push('category = ?');
params.push(query.category);
}
if (query.brand) {
where.push('brand = ?');
params.push(query.brand);
}
if (query.q) {
where.push('(brand LIKE ? OR model LIKE ? OR aliases_json LIKE ? OR summary LIKE ?)');
const like = `%${query.q}%`;
params.push(like, like, like, like);
}
// 排序字段白名单,避免拼接外部输入
const orderBy =
query.sort === 'name'
? 'model ASC'
: query.sort === 'brand'
? 'brand ASC, model ASC'
: "COALESCE(release_date, announce_date, '') DESC, brand, model";
const sql = `SELECT * FROM devices ${
where.length > 0 ? `WHERE ${where.join(' AND ')}` : ''
} ORDER BY ${orderBy}`;
const rows = db.prepare(sql).all(...params);
return (rows as Row[]).map(rowToDevice);
}
export function listBrands(category?: DeviceCategory): { brand: string; count: number }[] {
const db = getDb();
const rows = category
? db
.prepare(
'SELECT * FROM devices WHERE category = ? ORDER BY release_date DESC, brand, model',
'SELECT brand, COUNT(*) AS count FROM devices WHERE category = ? GROUP BY brand ORDER BY brand',
)
.all(options.category)
: db.prepare('SELECT * FROM devices ORDER BY release_date DESC, brand, model').all();
return (rows as Row[]).map(rowToDevice);
.all(category)
: db.prepare('SELECT brand, COUNT(*) AS count FROM devices GROUP BY brand ORDER BY brand').all();
return rows as { brand: string; count: number }[];
}
export function getDevice(slug: string): Device | undefined {
+49
View File
@@ -0,0 +1,49 @@
---
import BaseLayout from '@/layouts/BaseLayout.astro';
import { listBrands, listDevices } from '@/lib/repo';
const brand = decodeURIComponent(Astro.params.brand ?? '');
const devices = listDevices({ brand });
const brands = listBrands();
const totalOfBrand = brands.find((item) => item.brand === brand)?.count ?? devices.length;
if (devices.length === 0) {
return new Response('未找到该品牌', { status: 404 });
}
---
<BaseLayout title={`${brand} 设备 · LFSpecs`} description={`${brand} 收录的 ${devices.length} 款设备详细规格。`}>
<nav class="text-xs text-muted-foreground">
<a href="/brands" class="hover:text-foreground">品牌</a>
<span class="mx-1.5">/</span>
<span class="text-foreground">{brand}</span>
</nav>
<header class="mt-3 flex flex-wrap items-baseline justify-between gap-3">
<h1 class="text-2xl font-semibold tracking-tight">{brand}</h1>
<span class="tabular text-sm text-muted-foreground">{totalOfBrand} 款</span>
</header>
<div class="mt-6 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{
devices.map((device) => (
<a
href={`/devices/${device.slug}`}
class="rounded-lg border border-border bg-card p-5 transition-colors hover:border-primary/40"
>
<div class="text-base font-semibold">{device.model}</div>
<dl class="tabular mt-4 grid grid-cols-2 gap-x-4 gap-y-1 text-xs">
<dt class="text-muted-foreground">SoC</dt>
<dd class="truncate text-right">{device.specs.platform?.chipset ?? '—'}</dd>
<dt class="text-muted-foreground">发布日期</dt>
<dd class="text-right">{device.releaseDate ?? device.announceDate ?? '—'}</dd>
<dt class="text-muted-foreground">屏幕</dt>
<dd class="truncate text-right">{device.specs.display?.size ?? '—'}</dd>
<dt class="text-muted-foreground">电池</dt>
<dd class="truncate text-right">{device.specs.battery?.capacity ?? '—'}</dd>
</dl>
</a>
))
}
</div>
</BaseLayout>
+36
View File
@@ -0,0 +1,36 @@
---
import BaseLayout from '@/layouts/BaseLayout.astro';
import { listBrands } from '@/lib/repo';
const brands = listBrands();
const total = brands.reduce((sum, item) => sum + item.count, 0);
---
<BaseLayout title="品牌索引 · LFSpecs">
<header class="flex flex-wrap items-baseline justify-between gap-3">
<h1 class="text-2xl font-semibold tracking-tight">品牌</h1>
<span class="tabular text-sm text-muted-foreground">{brands.length} 个品牌 · {total} 款设备</span>
</header>
<div class="mt-6 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{
brands.map((item) => (
<a
href={`/brands/${encodeURIComponent(item.brand)}`}
class="flex items-center justify-between rounded-lg border border-border bg-card px-5 py-4 transition-colors hover:border-primary/40"
>
<span class="text-sm font-medium">{item.brand}</span>
<span class="tabular text-xs text-muted-foreground">{item.count} 款</span>
</a>
))
}
</div>
{
brands.length === 0 && (
<p class="mt-6 rounded-lg border border-dashed border-border p-8 text-center text-sm text-muted-foreground">
暂无品牌数据。
</p>
)
}
</BaseLayout>
+66 -7
View File
@@ -137,6 +137,19 @@ const cameras = [
{ title: '后置影像', list: s.rearCamera },
{ title: '前置影像', list: s.frontCamera },
].filter((c) => c.list.length > 0);
const lifecycleText =
device.lifecycle === 'discontinued' ? '已停产' : device.lifecycle === 'announced' ? '已发布' : '在售';
const productLd = {
'@context': 'https://schema.org',
'@type': 'Product',
name: `${device.brand} ${device.model}`,
brand: { '@type': 'Brand', name: device.brand },
model: device.model,
...(device.summary ? { description: device.summary } : {}),
...(device.releaseDate ? { releaseDate: device.releaseDate } : {}),
};
---
<BaseLayout title={`${device.brand} ${device.model} 规格 · LFSpecs`} description={device.summary}>
@@ -147,11 +160,27 @@ const cameras = [
</nav>
<header class="mt-3">
<p class="text-sm text-muted-foreground">{device.brand}</p>
<p class="text-sm text-muted-foreground">
<a href={`/brands/${encodeURIComponent(device.brand)}`} class="transition-colors hover:text-foreground">
{device.brand}
</a>
</p>
<h1 class="mt-1 text-3xl font-semibold tracking-tight">{device.model}</h1>
{device.aliases.length > 0 && (
<p class="mt-1.5 text-xs text-muted-foreground">别名:{device.aliases.join('、')}</p>
)}
<div class="mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground">
{device.aliases.length > 0 && <span>别名:{device.aliases.join('、')}</span>}
{device.releaseDate && <span class="tabular">上市:{device.releaseDate}</span>}
{!device.releaseDate && device.announceDate && <span class="tabular">发布:{device.announceDate}</span>}
<span>{lifecycleText}</span>
</div>
{
device.tags.length > 0 && (
<div class="mt-2 flex flex-wrap gap-1.5">
{device.tags.map((tag) => (
<span class="rounded-full border border-border px-2 py-0.5 text-[11px] text-muted-foreground">{tag}</span>
))}
</div>
)
}
{device.summary && <p class="mt-3 max-w-2xl text-sm text-muted-foreground">{device.summary}</p>}
</header>
@@ -248,7 +277,37 @@ const cameras = [
))
}
<p class="mt-12 text-xs text-muted-foreground">
共 {device.meta.length} 条字段级来源记录,其中人工核实 {device.meta.filter((m) => m.verified).length} 条。
</p>
<section class="mt-12 border-t border-border/60 pt-6">
<h2 class="text-sm font-semibold">数据来源</h2>
<ul class="mt-3 space-y-1.5 text-xs text-muted-foreground">
{
device.meta.map((item) => (
<li class="flex flex-wrap items-baseline gap-2">
<span class="font-mono text-[11px] text-foreground/70">{item.path}</span>
<span
class:list={[
'rounded-full border px-1.5 py-0.5 text-[10px]',
item.confidence === 'high'
? 'border-primary/40 text-primary'
: item.confidence === 'medium'
? 'border-yellow-500/40 text-yellow-500'
: 'border-destructive/40 text-destructive',
]}
>
{item.confidence}
</span>
<span>{item.verified ? '已核实' : '待核实'}</span>
{item.sourceUrl && (
<a href={item.sourceUrl} rel="nofollow noopener" target="_blank" class="underline hover:text-foreground">
来源
</a>
)}
</li>
))
}
{device.meta.length === 0 && <li>暂无字段级来源记录。</li>}
</ul>
</section>
<script type="application/ld+json" set:html={JSON.stringify(productLd)} />
</BaseLayout>
+113 -6
View File
@@ -1,14 +1,113 @@
---
import BaseLayout from '@/layouts/BaseLayout.astro';
import { listDevices } from '@/lib/repo';
import { listBrands, listDevices, type DeviceSort } from '@/lib/repo';
const devices = listDevices({ category: 'phone' });
const params = Astro.url.searchParams;
const q = (params.get('q') ?? '').trim();
const brand = params.get('brand') ?? undefined;
const sortParam = params.get('sort') ?? 'latest';
const sort: DeviceSort = sortParam === 'name' || sortParam === 'brand' ? sortParam : 'latest';
const devices = listDevices({ category: 'phone', q: q || undefined, brand, sort });
const brands = listBrands('phone');
/** 保留其他筛选条件,只覆盖指定项 */
function urlWith(overrides: Record<string, string | undefined>): string {
const next = new URLSearchParams();
const merged: Record<string, string | undefined> = {
q: q || undefined,
brand,
sort: sort === 'latest' ? undefined : sort,
...overrides,
};
for (const [key, value] of Object.entries(merged)) {
if (value) next.set(key, value);
}
const query = next.toString();
return query ? `/devices?${query}` : '/devices';
}
const sortOptions: { key: DeviceSort; label: string }[] = [
{ key: 'latest', label: '最新发布' },
{ key: 'name', label: '按型号' },
{ key: 'brand', label: '按品牌' },
];
---
<BaseLayout title="手机规格库 · LFSpecs">
<div class="flex items-baseline justify-between">
<header class="flex flex-wrap items-baseline justify-between gap-3">
<h1 class="text-2xl font-semibold tracking-tight">手机</h1>
<span class="tabular text-sm text-muted-foreground">{devices.length} 款</span>
</header>
<form action="/devices" method="get" class="mt-5 flex flex-wrap gap-2">
<input
type="search"
name="q"
value={q}
placeholder="搜索型号、别名、简介"
class="h-9 min-w-0 flex-1 rounded-md border border-border bg-card px-3 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
/>
{brand && <input type="hidden" name="brand" value={brand} />}
{sort !== 'latest' && <input type="hidden" name="sort" value={sort} />}
<button
type="submit"
class="h-9 rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90"
>
搜索
</button>
{q && (
<a
href={urlWith({ q: undefined })}
class="inline-flex h-9 items-center rounded-md border border-border px-3 text-sm text-muted-foreground transition-colors hover:text-foreground"
>
清除
</a>
)}
</form>
<div class="mt-4 flex flex-wrap items-center gap-2">
<a
href={urlWith({ brand: undefined })}
class:list={[
'rounded-full border px-3 py-1 text-xs transition-colors',
brand ? 'border-border text-muted-foreground hover:text-foreground' : 'border-primary/50 bg-primary/10 text-primary',
]}
>
全部品牌
</a>
{
brands.map((item) => (
<a
href={urlWith({ brand: item.brand })}
class:list={[
'rounded-full border px-3 py-1 text-xs transition-colors',
brand === item.brand
? 'border-primary/50 bg-primary/10 text-primary'
: 'border-border text-muted-foreground hover:text-foreground',
]}
>
{item.brand} <span class="tabular opacity-60">{item.count}</span>
</a>
))
}
</div>
<div class="mt-4 flex flex-wrap items-center gap-1 text-xs text-muted-foreground">
<span class="mr-1">排序</span>
{
sortOptions.map((option) => (
<a
href={urlWith({ sort: option.key === 'latest' ? undefined : option.key })}
class:list={[
'rounded-md px-2 py-1 transition-colors',
sort === option.key ? 'bg-accent text-foreground' : 'hover:text-foreground',
]}
>
{option.label}
</a>
))
}
</div>
<div class="mt-6 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
@@ -20,11 +119,19 @@ const devices = listDevices({ category: 'phone' });
>
<div class="flex items-start justify-between gap-2">
<div>
<div class="text-xs text-muted-foreground">{device.brand}</div>
<div class="text-xs text-muted-foreground">
<a href={`/brands/${encodeURIComponent(device.brand)}`} class="hover:text-foreground">
{device.brand}
</a>
</div>
<div class="mt-0.5 text-base font-semibold">{device.model}</div>
</div>
<span class="rounded-full border border-border px-2 py-0.5 text-[11px] text-muted-foreground">
{device.lifecycle === 'discontinued' ? '已停产' : device.lifecycle === 'announced' ? '已发布' : '在售'}
{device.lifecycle === 'discontinued'
? '已停产'
: device.lifecycle === 'announced'
? '已发布'
: '在售'}
</span>
</div>
@@ -48,7 +155,7 @@ const devices = listDevices({ category: 'phone' });
{
devices.length === 0 && (
<p class="mt-6 rounded-lg border border-dashed border-border p-8 text-center text-sm text-muted-foreground">
暂无手机数据,运行 <code class="font-mono text-foreground">pnpm db:seed</code> 写入种子数据。
没有匹配的设备。试试清除关键词或换一个品牌。
</p>
)
}
+23
View File
@@ -0,0 +1,23 @@
import type { APIRoute } from 'astro';
import { listBrands, listChips, listDevices } from '@/lib/repo';
const SITE = 'https://specs.atie.fun';
export const GET: APIRoute = () => {
const paths: string[] = ['', '/devices', '/chips', '/brands'];
for (const device of listDevices()) paths.push(`/devices/${device.slug}`);
for (const chip of listChips()) paths.push(`/chips/${chip.slug}`);
for (const item of listBrands()) paths.push(`/brands/${encodeURIComponent(item.brand)}`);
const body = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${paths.map((path) => ` <url><loc>${SITE}${path}</loc></url>`).join('\n')}
</urlset>`;
return new Response(body, {
headers: {
'content-type': 'application/xml; charset=utf-8',
'cache-control': 'public, max-age=3600',
},
});
};