Skip to content

konglong87/superPM / skills/pm-preview

pm-preview

Verified

产品文档实时预览 - 在浏览器中预览 docs/ 下的所有 MD 文档,文档更新时自动刷新 Use when: 需要预览产品文档、查看 PRD/BRD/MRD 等 MD 文档的渲染效果 Do NOT use when: 文档尚未生成(docs/ 为空)

FileKindSize
SKILL.mdskill md4.2 KB
scripts/preview-frame.htmlother8.1 KB
scripts/preview-helper.jsscript5.0 KB
scripts/preview-server.cjsscript14.4 KB
scripts/start-preview.shexecutablescript4.7 KB
scripts/stop-preview.shexecutablescript1.3 KB

scripts/preview-helper.js

View on GitHub
(function() {
  const WS_URL = 'ws://' + window.location.host;
  let ws = null;
  let eventQueue = [];
  let currentDoc = null;
  let docTree = [];

  // ========== WebSocket ==========

  function connect() {
    ws = new WebSocket(WS_URL);

    ws.onopen = () => {
      eventQueue.forEach(e => ws.send(JSON.stringify(e)));
      eventQueue = [];
    };

    ws.onmessage = (msg) => {
      const data = JSON.parse(msg.data);
      if (data.type === 'reload') {
        // Refresh the document tree and re-render current doc
        refreshDocTree().then(() => {
          if (currentDoc) {
            loadDocument(currentDoc, false);
          }
        });
      }
    };

    ws.onclose = () => {
      setTimeout(connect, 1000);
    };
  }

  // ========== Document Tree ==========

  async function refreshDocTree() {
    try {
      const resp = await fetch('/api/docs');
      docTree = await resp.json();
      renderDocTree(docTree);
      updateDocCount(docTree);
    } catch (e) {
      document.getElementById('doc-tree').innerHTML =
        '<div class="sidebar-empty">Failed to load documents</div>';
    }
  }

  function countDocs(nodes) {
    let count = 0;
    for (const node of nodes) {
      if (node.children) {
        count += countDocs(node.children);
      } else {
        count++;
      }
    }
    return count;
  }

  function updateDocCount(tree) {
    const count = countDocs(tree);
    const el = document.getElementById('doc-count');
    if (el) el.textContent = '(' + count + ')';
  }

  function renderDocTree(tree) {
    const container = document.getElementById('doc-tree');
    if (!tree || tree.length === 0) {
      container.innerHTML = '<div class="sidebar-empty">No documents found in docs/</div>';
      return;
    }

    container.innerHTML = '';
    for (const node of tree) {
      renderTreeNode(node, container, 0);
    }
  }

  function renderTreeNode(node, parent, depth) {
    if (node.children) {
      // Directory group
      const group = document.createElement('div');
      group.className = 'dir-group';

      const toggle = document.createElement('button');
      toggle.className = 'dir-toggle';
      toggle.innerHTML = '<span class="arrow">▼</span>' + escapeHtml(node.name);
      toggle.onclick = () => {
        toggle.classList.toggle('collapsed');
        children.classList.toggle('collapsed');
      };

      const children = document.createElement('div');
      children.className = 'dir-children';

      for (const child of node.children) {
        renderTreeNode(child, children, depth + 1);
      }

      group.appendChild(toggle);
      group.appendChild(children);
      parent.appendChild(group);
    } else {
      // Document file
      const item = document.createElement('a');
      item.className = 'doc-item';
      item.textContent = node.name.replace(/\.md$/, '');
      item.title = node.path;
      item.href = '#';
      item.dataset.path = node.path;
      item.onclick = (e) => {
        e.preventDefault();
        loadDocument(node.path, true);
      };
      parent.appendChild(item);
    }
  }

  // ========== Document Loading ==========

  async function loadDocument(docPath, scrollToTop) {
    try {
      const resp = await fetch('/api/doc?path=' + encodeURIComponent(docPath));
      if (!resp.ok) {
        throw new Error('Document not found');
      }
      const doc = await resp.json();

      // Render Markdown
      renderDoc(doc, scrollToTop);
    } catch (e) {
      document.getElementById('content-area').innerHTML =
        '<div class="welcome"><h2>Failed to load document</h2><p>' + escapeHtml(e.message) + '</p></div>';
    }
  }

  function renderDoc(doc, scrollToTop) {
    currentDoc = doc.path;

    // Update sidebar active state
    document.querySelectorAll('.doc-item.active').forEach(el => el.classList.remove('active'));
    const activeItem = document.querySelector('[data-path="' + CSS.escape(doc.path) + '"]');
    if (activeItem) activeItem.classList.add('active');

    // Render content
    const area = document.getElementById('content-area');
    // Fail closed if either local renderer is unavailable; never inject unsanitized HTML.
    if (typeof marked === 'undefined' || typeof DOMPurify === 'undefined') {
      area.textContent = doc.content;
      return;
    }
    const html = DOMPurify.sanitize(marked.parse(doc.content));
    area.innerHTML = '<div class="rendered-markdown">' + html + '</div>';

    if (scrollToTop) {
      document.querySelector('.main').scrollTop = 0;
    }
  }

  // ========== Utilities ==========

  function escapeHtml(str) {
    const div = document.createElement('div');
    div.textContent = str;
    return div.innerHTML;
  }

  // ========== Expose API ==========

  window.superpm = {
    refresh: refreshDocTree,
    loadDoc: loadDocument,
    getTree: () => docTree
  };

  // ========== Init ==========

  // Use pre-loaded tree for instant first render (no fetch needed)
  if (typeof DOC_TREE !== 'undefined' && DOC_TREE.length > 0) {
    docTree = DOC_TREE;
    renderDocTree(docTree);
    updateDocCount(docTree);
  }

  connect();
})();
rea-changelog-updatemorluto/reaPrepare or rewrite REA release changelogs and GitHub release notes from pinned Git history, with verified contributor thanks and Release Please synchronization.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
academy-guideanthropics/skillsStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
claude-apianthropics/skillsReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any form (Claude, Anthropic, Fable, Opus, Sonnet, Haiku, `anthropic`, `@anthropic-ai`, `claude-*`, `us.anthropic.*`, `[1m]`); the user asks about an LLM (pricing/model choice/limits/caching) — never answer from memory; OR the task is LLM-shaped with provider unstated (agent/MCP/tool-definition/multi-agent/RAG/LLM-judge/computer-use; generate/summarize/extract/classify/rewrite/converse over NL; debugging refusals/cutoffs/streaming/tool-calls/tokens). SKIP only when another provider is being worked on (overrides all triggers): OpenAI/GPT/Gemini/Llama/Mistral/Cohere/Ollama named in the query; OR `grep -rE 'openai|langchain_openai|google.generativeai|genai|mistralai|cohere|ollama'` over the project hits (run this grep FIRST if no provider named — don't Read the file).Stars: 198kUpdated Claude CodeCodexUnverifiedInstall
doc-coauthoringanthropics/skillsGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.Stars: 198kUpdated Claude CodeCodexVerifiedInstall