调整
This commit is contained in:
1 parent
787544eec1
commit
4ff9146910
81 files changed
+18417
-545
No files matched your search
+172
-11
@@ -1,48 +1,209 @@
|
||||
---
|
||||
import { ClientRouter } from 'astro:transitions';
|
||||
import CompareTray from '@/components/CompareTray.astro';
|
||||
import '../styles/global.css';
|
||||
|
||||
interface Props {
|
||||
title?: string;
|
||||
description?: string;
|
||||
/** OG 图路径,默认站点通用图;详情页传设备 slug */
|
||||
ogImage?: string;
|
||||
/** 用于 og:url 与 canonical 的路径,默认取当前路径 */
|
||||
path?: string;
|
||||
}
|
||||
|
||||
const {
|
||||
title = 'LFSpecs',
|
||||
description = '公开硬件规格库:收录手机、芯片等设备的详细参数,支持横向对比。',
|
||||
ogImage,
|
||||
path,
|
||||
} = Astro.props;
|
||||
|
||||
const site = Astro.site ?? new URL('https://specs.atie.fun');
|
||||
const canonical = new URL(path ?? Astro.url.pathname, site).href;
|
||||
const image = new URL(ogImage ?? '/og/site.png', site).href;
|
||||
const ogType = path?.startsWith('/devices/') ? 'article' : 'website';
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<html lang="zh-CN" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<script is:inline>
|
||||
(() => {
|
||||
try {
|
||||
const saved = localStorage.getItem('lfs-theme');
|
||||
const theme =
|
||||
saved === 'light' || saved === 'dark'
|
||||
? saved
|
||||
: window.matchMedia('(prefers-color-scheme: light)').matches
|
||||
? 'light'
|
||||
: 'dark';
|
||||
document.documentElement.dataset.theme = theme;
|
||||
} catch {
|
||||
document.documentElement.dataset.theme = 'dark';
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<meta name="description" content={description} />
|
||||
<link rel="canonical" href={canonical} />
|
||||
|
||||
<meta property="og:type" content={ogType} />
|
||||
<meta property="og:site_name" content="LFSpecs" />
|
||||
<meta property="og:locale" content="zh_CN" />
|
||||
<meta property="og:title" content={title} />
|
||||
<meta property="og:description" content={description} />
|
||||
<meta property="og:url" content={canonical} />
|
||||
<meta property="og:image" content={image} />
|
||||
<meta property="og:image:width" content="1200" />
|
||||
<meta property="og:image:height" content="630" />
|
||||
<meta property="og:image:alt" content={title} />
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:title" content={title} />
|
||||
<meta name="twitter:description" content={description} />
|
||||
<meta name="twitter:image" content={image} />
|
||||
|
||||
<title>{title}</title>
|
||||
<ClientRouter />
|
||||
</head>
|
||||
<body class="min-h-dvh">
|
||||
<header class="border-b border-border/60">
|
||||
<div class="mx-auto flex h-14 max-w-6xl items-center gap-6 px-5">
|
||||
<a href="/" class="text-sm font-semibold tracking-tight">LFSpecs</a>
|
||||
<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>
|
||||
<header class="site-header border-b border-border/60 print-hidden">
|
||||
<div class="mx-auto flex h-14 max-w-6xl items-center gap-4 px-5">
|
||||
<a href="/" class="shrink-0 text-sm font-semibold tracking-tight">LFSpecs</a>
|
||||
<nav class="flex min-w-0 items-center gap-0.5 text-xs text-muted-foreground sm:gap-1 sm:text-sm">
|
||||
<a href="/devices" class="rounded-md px-2 py-1.5 transition-colors hover:bg-accent hover:text-foreground sm:px-2.5">手机</a>
|
||||
<a href="/chips" class="rounded-md px-2 py-1.5 transition-colors hover:bg-accent hover:text-foreground sm:px-2.5">芯片</a>
|
||||
<a href="/rankings" class="rounded-md px-2 py-1.5 transition-colors hover:bg-accent hover:text-foreground sm:px-2.5">排行</a>
|
||||
<a href="/compare" class="rounded-md px-2 py-1.5 transition-colors hover:bg-accent hover:text-foreground sm:px-2.5">对比</a>
|
||||
<a href="/brands" class="rounded-md px-2 py-1.5 transition-colors hover:bg-accent hover:text-foreground sm:px-2.5">品牌</a>
|
||||
<a href="/poc" class="hidden rounded-md px-2.5 py-1.5 transition-colors hover:bg-accent hover:text-foreground sm:inline-flex">组件自检</a>
|
||||
</nav>
|
||||
<button
|
||||
type="button"
|
||||
data-theme-toggle
|
||||
aria-label="切换日间 / 夜间主题"
|
||||
title="切换日间 / 夜间主题"
|
||||
class="ml-auto inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
||||
>
|
||||
<svg class="theme-icon-sun h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="4"></circle>
|
||||
<path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"></path>
|
||||
</svg>
|
||||
<svg class="theme-icon-moon h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 9.79 9.79z"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="mx-auto max-w-6xl px-5 py-10">
|
||||
<main class="mx-auto max-w-6xl px-5 py-10" transition:animate="fade">
|
||||
<slot />
|
||||
</main>
|
||||
|
||||
<footer class="mt-16 border-t border-border/60 py-8">
|
||||
<footer class="site-footer mt-16 border-t border-border/60 py-8 print-hidden">
|
||||
<div class="mx-auto max-w-6xl px-5 text-xs text-muted-foreground">
|
||||
<p>数据由人工与 AI 辅助整理,仅供参考。</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<CompareTray />
|
||||
|
||||
<dialog id="lfs-lightbox" class="image-lightbox" aria-label="图片预览">
|
||||
<button type="button" class="image-lightbox-close" data-lightbox-close aria-label="关闭图片预览">×</button>
|
||||
<img data-lightbox-image alt="" />
|
||||
</dialog>
|
||||
|
||||
<script is:inline>
|
||||
(() => {
|
||||
if (window.__lfsLightboxReady) return;
|
||||
window.__lfsLightboxReady = true;
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const target = event.target;
|
||||
if (!(target instanceof Element)) return;
|
||||
|
||||
const dialog = document.getElementById('lfs-lightbox');
|
||||
|
||||
if (target.closest('[data-lightbox-close]')) {
|
||||
if (dialog && dialog.open) dialog.close();
|
||||
return;
|
||||
}
|
||||
if (dialog && dialog.open && target === dialog) {
|
||||
dialog.close();
|
||||
return;
|
||||
}
|
||||
|
||||
const trigger = target.closest('[data-lightbox]');
|
||||
if (!trigger) return;
|
||||
const src = trigger.getAttribute('data-lightbox') || trigger.getAttribute('href');
|
||||
const alt = trigger.getAttribute('data-alt') || '';
|
||||
const image = dialog?.querySelector('[data-lightbox-image]');
|
||||
if (!dialog || !image || !src) return;
|
||||
|
||||
if (typeof dialog.showModal !== 'function') {
|
||||
window.open(src, '_blank', 'noopener');
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
image.src = src;
|
||||
image.alt = alt;
|
||||
dialog.showModal();
|
||||
document.documentElement.classList.add('lightbox-open');
|
||||
dialog.addEventListener(
|
||||
'close',
|
||||
() => document.documentElement.classList.remove('lightbox-open'),
|
||||
{ once: true },
|
||||
);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<script is:inline>
|
||||
(() => {
|
||||
if (window.__lfsThemeReady) return;
|
||||
window.__lfsThemeReady = true;
|
||||
|
||||
const savedTheme = () => {
|
||||
try {
|
||||
const saved = localStorage.getItem('lfs-theme');
|
||||
return saved === 'light' || saved === 'dark' ? saved : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const restoreTheme = () => {
|
||||
const theme = savedTheme();
|
||||
if (theme) document.documentElement.dataset.theme = theme;
|
||||
};
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const target = event.target;
|
||||
if (!(target instanceof Element)) return;
|
||||
if (!target.closest('[data-theme-toggle]')) return;
|
||||
const next = document.documentElement.dataset.theme === 'light' ? 'dark' : 'light';
|
||||
document.documentElement.dataset.theme = next;
|
||||
try {
|
||||
localStorage.setItem('lfs-theme', next);
|
||||
} catch {}
|
||||
});
|
||||
|
||||
// ClientRouter 会换入服务端渲染的 <html data-theme="dark">,
|
||||
// 跨页导航后需要把用户选择的主题重新写回去。
|
||||
document.addEventListener('astro:before-swap', (event) => {
|
||||
const theme = savedTheme();
|
||||
if (theme && event.newDocument?.documentElement) {
|
||||
event.newDocument.documentElement.dataset.theme = theme;
|
||||
}
|
||||
});
|
||||
document.addEventListener('astro:after-swap', restoreTheme);
|
||||
document.addEventListener('astro:page-load', restoreTheme);
|
||||
restoreTheme();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user