This commit is contained in:
Vaica committed 2026-06-22 12:14:53 +08:00
1 parent fd200e018d
commit a1dd087bcc
4 files changed
+41 -10

No files matched your search

+20 -4
View File
@@ -71,11 +71,27 @@ export default function EditPostPage({
</div>
<button
type="button"
onClick={async () => {
await fetch("/api/hugo");
window.open(`/preview/${post.frontMatter.slug}.html`, "_blank");
onClick={async (e) => {
const btn = e.currentTarget;
const orig = btn.innerHTML;
btn.disabled = true;
btn.textContent = "⏳ 启动中...";
try {
const res = await fetch("/api/hugo");
const data = await res.json();
if (data.running) {
window.open(`/preview/${post.frontMatter.slug}.html`, "_blank");
} else {
alert("Hugo 预览启动失败");
}
} catch {
alert("Hugo 预览启动失败");
} finally {
btn.disabled = false;
btn.innerHTML = orig;
}
}}
className="flex items-center gap-1.5 px-3 py-1.5 text-[12px] rounded-md border border-line text-muted hover:text-accent hover:border-accent/30 transition-colors"
className="flex items-center gap-1.5 px-3 py-1.5 text-[12px] rounded-md border border-line text-muted hover:text-accent hover:border-accent/30 transition-colors disabled:opacity-50"
title="预览"
>
<Eye size={13} /> 预览
+17 -5
View File
@@ -76,9 +76,21 @@ export default function HomePage() {
}
};
const handlePreview = async (slug: string) => {
await fetch("/api/hugo");
window.open(`/preview/${slug}.html`, "_blank");
const handlePreview = async (slug: string, btn?: HTMLButtonElement) => {
if (btn) { btn.disabled = true; btn.textContent = "启动中..."; }
try {
const res = await fetch("/api/hugo");
const data = await res.json();
if (data.running) {
window.open(`/preview/${slug}.html`, "_blank");
} else {
alert("Hugo 预览启动失败,请稍后再试");
}
} catch {
alert("Hugo 预览启动失败");
} finally {
if (btn) { btn.disabled = false; btn.textContent = ""; }
}
};
const toggleSelect = (slug: string) => {
@@ -304,8 +316,8 @@ export default function HomePage() {
{!selectMode && (
<div className="flex items-center gap-0.5 md:opacity-0 md:group-hover:opacity-100 transition-opacity">
<button type="button" onClick={() => handlePreview(post.slug)}
className="p-1.5 rounded hover:bg-accent/8 text-muted hover:text-accent transition-colors" title="预览"><Eye size={14} /></button>
<button type="button" onClick={(e) => handlePreview(post.slug, e.currentTarget)}
className="p-1.5 rounded hover:bg-accent/8 text-muted hover:text-accent transition-colors disabled:opacity-50" title="预览"><Eye size={14} /></button>
<button type="button" onClick={() => router.push(`/edit/${post.slug}`)}
className="p-1.5 rounded hover:bg-accent/8 text-muted hover:text-accent transition-colors" title="编辑"><Edit size={14} /></button>
<button type="button" onClick={() => handleDelete(post.slug, post.title)}