import {previewUrl} from '@/content/page-links'; import Head from 'next/head'; import Link from 'next/link'; import {useState,useEffect,useRef} from 'react'; import {X,PanelRight,Copy,ExternalLink} from 'lucide-react'; import {Shell} from './Shell'; import {getGuidance,guidanceMarkdown,guidanceBacklinks,humanDocumentUrl,markdownDocumentUrl,legacyDocumentPath,type GuidanceResource} from '@/content/skills/guidance'; export function SkillDocs({documentPath,documentId='index',skillId='street-people'}:{documentPath?:string;documentId?:string;skillId?:string}){ const path=documentPath??legacyDocumentPath(skillId,documentId); const doc=getGuidance(path)!; const [open,setOpen]=useState(false); const [selected,setSelected]=useState(null); const [copied,setCopied]=useState(false); const panel=useRef(null); useEffect(()=>{setOpen(window.innerWidth>760)},[]); useEffect(()=>{setSelected(null);setCopied(false)},[path]); useEffect(()=>{if(!open)return;const handler=(e:KeyboardEvent)=>{if(e.key==='Escape')setOpen(false)};window.addEventListener('keydown',handler);return()=>window.removeEventListener('keydown',handler)},[open]); const resource=(id:string)=>doc.resources.find(r=>r.id===id)!; const incoming=guidanceBacklinks(path); async function copy(){ try{ const value=new URL(markdownDocumentUrl(path),location.origin).href; if(navigator.clipboard)await navigator.clipboard.writeText(value); else{const input=document.createElement('textarea');input.value=value;document.body.appendChild(input);input.select();const ok=document.execCommand('copy');input.remove();if(!ok)throw Error('Copy unavailable');} setCopied(true); }catch{setCopied(false)} } return {doc.title} · 指导文档 · 啡跃 Endoleap
← 全部指导文档
{doc.collection} / 指导文档

{doc.title}

本文 Markdown ↗

网页与 Markdown 来自同一份文档。每篇都有独立地址,可以直接进入,也可以沿引用继续阅读。

{doc.blocks.map((b,i)=>b.type==='heading'?

{b.text}

:b.type==='code'?
{b.text}
:b.type==='links'?
{b.refs!.map(id=>{ const r=resource(id); return r.kind==='document'?文档 · {r.title}:{e.preventDefault();setSelected(r);setOpen(true);panel.current?.focus()}}>{r.kind==='image'?'图片':r.method} · {r.title}; })}
:

{b.text}

)} {incoming.length>0&&<>

引用本文的文档

{incoming.map(d=>{d.title})}
}
{open&&}
; }