1623
This commit is contained in:
1 parent
310be913ef
commit
fe8c99a53e
8 files changed
+367
-157
No files matched your search
@@ -27,7 +27,7 @@ export default function PostEditor({ initialData, isEditing }: PostEditorProps)
|
||||
date: initialData?.frontMatter.date ? new Date(initialData.frontMatter.date).toISOString().slice(0, 10) : today,
|
||||
categories: initialData?.frontMatter.categories?.join("、") || "",
|
||||
tags: initialData?.frontMatter.tags?.join("、") || "",
|
||||
author: initialData?.frontMatter.author || "小赵",
|
||||
author: initialData?.frontMatter.author || (() => { try { return JSON.parse(localStorage.getItem("wauth_user") || "{}").name || "小赵"; } catch { return "小赵"; } })(),
|
||||
});
|
||||
const [content, setContent] = useState(initialData?.content || "");
|
||||
const [uploading, setUploading] = useState(false);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { RefObject } from "react";
|
||||
import { Heading2, Heading3, Code, Quote, Image, Link, Minus, Bold, FileCode, Grid3X3 } from "lucide-react";
|
||||
import { Heading2, Heading3, Code, Quote, Image, Link, Minus, Bold, FileCode, Grid3X3, Video, Play } from "lucide-react";
|
||||
|
||||
interface ShortcutPanelProps {
|
||||
textareaRef: RefObject<HTMLTextAreaElement | null>;
|
||||
@@ -51,6 +51,15 @@ export default function ShortcutPanel({ textareaRef, value, onChange }: Shortcut
|
||||
{{< /grid >}}
|
||||
`;
|
||||
|
||||
const videoTemplate = `{{< video src="/video/example.mp4" caption="视频说明" >}}
|
||||
`;
|
||||
|
||||
const bilibiliTemplate = `{{< bilibili BV1xx411c7mD >}}
|
||||
`;
|
||||
|
||||
const youtubeTemplate = `{{< youtube dQw4w9WgXcQ >}}
|
||||
`;
|
||||
|
||||
const shortcuts = [
|
||||
{ label: "H2", icon: Heading2, action: () => insert("## ", "\n", "二级标题") },
|
||||
{ label: "H3", icon: Heading3, action: () => insert("### ", "\n", "三级标题") },
|
||||
@@ -60,6 +69,9 @@ export default function ShortcutPanel({ textareaRef, value, onChange }: Shortcut
|
||||
{ label: "引用", icon: Quote, action: () => insert("> ", "\n", "引用内容") },
|
||||
{ label: "图片", icon: Image, action: () => insert("![", "]()", "描述") },
|
||||
{ label: "图片网格", icon: Grid3X3, action: () => insertBlock(gridTemplate) },
|
||||
{ label: "本地视频", icon: Video, action: () => insertBlock(videoTemplate) },
|
||||
{ label: "B站视频", icon: Play, action: () => insertBlock(bilibiliTemplate) },
|
||||
{ label: "YouTube", icon: Play, action: () => insertBlock(youtubeTemplate) },
|
||||
{ label: "链接", icon: Link, action: () => insert("[", "]()", "链接文本") },
|
||||
{ label: "分割线", icon: Minus, action: () => insert("\n---\n", "", "") },
|
||||
];
|
||||
@@ -86,7 +98,8 @@ export default function ShortcutPanel({ textareaRef, value, onChange }: Shortcut
|
||||
<ul className="text-[11px] text-muted/70 space-y-1 leading-relaxed">
|
||||
<li>选中文字后点按钮可包裹</li>
|
||||
<li>未选中则插入模板 + 占位文字</li>
|
||||
<li>代码块自动补全语言标注</li>
|
||||
<li>视频需替换 src 中的路径</li>
|
||||
<li>B站/YouTube 替换 BV号/ID</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -257,11 +257,17 @@ async function handleDocument(chatId: number, fileId: string, fileName?: string,
|
||||
const filename = Date.now() + "-" + fileId.slice(0, 8) + "." + ext;
|
||||
fs.writeFileSync(path.join(articleDir, filename), Buffer.from(fileBuffer));
|
||||
|
||||
// GIF 用图片语法,其他用链接
|
||||
const isImage = ["gif", "webp", "png", "jpg", "jpeg"].includes(ext.toLowerCase());
|
||||
// GIF 用图片语法,视频用 shortcode,其他用链接
|
||||
const extLower = ext.toLowerCase();
|
||||
const isImage = ["gif", "webp", "png", "jpg", "jpeg"].includes(extLower);
|
||||
const isVideo = ["mp4", "webm", "mov", "avi", "mkv", "flv"].includes(extLower);
|
||||
const fileCaption = caption || fileName || "file";
|
||||
if (isImage) {
|
||||
appendContent(chatId, `\n\n`);
|
||||
} else if (isVideo) {
|
||||
appendContent(chatId, `\n{{< video src="${filename}" caption="${fileCaption}" >}}\n`);
|
||||
await sendMessage(chatId, `🎬 视频已保存:${filename}`);
|
||||
return;
|
||||
} else {
|
||||
appendContent(chatId, `\n[${fileCaption}](${filename})\n`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user