This commit is contained in:
Vaica committed 2026-06-22 00:41:05 +08:00
1 parent 7b3173e89d
commit b8d16016d8
8 files changed
+39 -14

No files matched your search

+2 -2
View File
@@ -4,7 +4,6 @@ import { useState, useEffect, use } from "react";
import { useRouter } from "next/navigation";
import { ArrowLeft, Eye } from "lucide-react";
import PostEditor from "@/components/PostEditor";
import { HUGO_PREVIEW } from "@/lib/config";
import type { Post } from "@/lib/posts";
export default function EditPostPage({
@@ -74,7 +73,8 @@ export default function EditPostPage({
type="button"
onClick={async () => {
await fetch("/api/hugo");
window.open(`${HUGO_PREVIEW}/${post.frontMatter.slug}.html`, "_blank");
const previewBase = `${location.protocol}//${location.hostname}:1313`;
window.open(`${previewBase}/${post.frontMatter.slug}.html`, "_blank");
}}
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"
title="预览"
+13 -4
View File
@@ -8,7 +8,6 @@ import {
FileText as PostIcon, Rss, Link2, GripVertical, X, CheckSquare, Square,
} from "lucide-react";
import Pagination from "@/components/Pagination";
import { HUGO_PREVIEW } from "@/lib/config";
interface PostItem {
slug: string;
@@ -64,13 +63,23 @@ export default function HomePage() {
const handleDelete = async (slug: string, title: string) => {
if (!confirm(`确定删除「${title}」吗?`)) return;
await fetch(`/api/posts/${slug}`, { method: "DELETE" });
fetchPosts();
try {
const res = await fetch(`/api/posts/${slug}`, { method: "DELETE" });
const data = await res.json();
if (!res.ok) {
alert("删除失败:" + (data.error || "未知错误"));
return;
}
fetchPosts();
} catch (e) {
alert("删除失败:" + (e instanceof Error ? e.message : String(e)));
}
};
const handlePreview = async (slug: string) => {
await fetch("/api/hugo");
window.open(`${HUGO_PREVIEW}/${slug}.html`, "_blank");
const previewBase = `${location.protocol}//${location.hostname}:1313`;
window.open(`${previewBase}/${slug}.html`, "_blank");
};
const toggleSelect = (slug: string) => {