From 0ab319143bd41e78399f9078d5fe071d9a2c281f Mon Sep 17 00:00:00 2001
From: xiezhouwei {children}
;
+function SubSection({ id, children, className = '' }) {
+ return {children}
;
}
/* ─── Paragraph ─── */
@@ -145,6 +146,90 @@ function InfoCard({ icon: Icon, title, children, className = '' }) {
);
}
+/* ─── Right Page TOC ─── */
+function RightToc({ contentRef, HEADER_OFFSET, activeSection }) {
+ const { t } = useTranslation();
+ const [tocItems, setTocItems] = useState([]);
+ const [activeTocId, setActiveTocId] = useState('');
+
+ // Build TOC from all h2/h3 headings in the content area
+ useEffect(() => {
+ if (!contentRef.current) return;
+ const timer = setTimeout(() => {
+ const headings = contentRef.current.querySelectorAll('h2[id], h3[id]');
+ const items = [];
+ headings.forEach((h) => {
+ items.push({
+ id: h.id,
+ text: h.textContent.trim(),
+ level: h.tagName === 'H2' ? 2 : 3,
+ });
+ });
+ setTocItems(items);
+ }, 100);
+ return () => clearTimeout(timer);
+ }, [contentRef, activeSection]);
+
+ // TOC scroll-spy
+ useEffect(() => {
+ if (tocItems.length === 0) return;
+ const observer = new IntersectionObserver(
+ (entries) => {
+ for (const entry of entries) {
+ if (entry.isIntersecting) {
+ setActiveTocId(entry.target.id);
+ break;
+ }
+ }
+ },
+ { rootMargin: `-${HEADER_OFFSET}px 0px -80% 0px`, threshold: 0 }
+ );
+
+ tocItems.forEach((item) => {
+ const el = document.getElementById(item.id);
+ if (el) observer.observe(el);
+ });
+
+ return () => observer.disconnect();
+ }, [tocItems, HEADER_OFFSET]);
+
+ const scrollToHeading = (id) => {
+ const el = document.getElementById(id);
+ if (!el) return;
+ const top = el.getBoundingClientRect().top + window.scrollY - HEADER_OFFSET;
+ window.scrollTo({ top, behavior: 'smooth' });
+ };
+
+ if (tocItems.length === 0) return null;
+
+ return (
+
+ );
+}
+
/* ─── MAIN DOCS PAGE ─── */
export default function Docs() {
const { t } = useTranslation();
@@ -256,7 +341,7 @@ export default function Docs() {
)}
{/* ── Content ── */}
-
登录后进入 控制台 → API Key, 点击"新建 API Key",填写名称后即可生成。请务必妥善保存密钥,关闭页面后将无法再次查看完整密钥。
-在所有 API 请求中,通过 Bearer Token 方式传递密钥:
设置 stream: true 即可启用 SSE 流式响应:
支持语音转文字(STT)和文字转语音(TTS),兼容 OpenAI Audio API 格式。
-