From yux-publish
Publish articles to Zhihu (知乎专栏) via automated browser. Triggers on "发知乎", "post to zhihu", "知乎专栏", "zhihu publish", "发布知乎", "知乎文章".
npx claudepluginhub wuyuxiangx/yux-claude-hub --plugin yux-publishThis skill is limited to using the following tools:
**Match user's language**: Respond in the same language the user uses.
Publishes Markdown articles to Zsxq (知识星球) as drafts via browser automation with Playwright or Chrome DevTools MCP. Use for Zsxq publish requests or '发布到知识星球' mentions.
Posts articles or image-text content to WeChat Official Accounts via API or Chrome CDP. Supports HTML, Markdown, plain text input, and multiple images for 图文/贴图.
Posts articles from HTML, Markdown, or plain text and image-text content with multiple images to WeChat Official Accounts via API or Chrome CDP. Converts Markdown external links to bottom citations.
Share bugs, ideas, or general feedback.
Match user's language: Respond in the same language the user uses.
PLUGIN_DIR is the root of this plugin (two levels above this SKILL.md directory).
Resolve: PLUGIN_DIR = ${SKILL_DIR}/../..
| Script | Path | Purpose |
|---|---|---|
zhihu-publish.ts | ${PLUGIN_DIR}/scripts/zhihu/zhihu-publish.ts | MDX/Markdown → Zhihu HTML conversion + clipboard copy |
npx -y bunCheck ${SKILL_DIR}/EXTEND.md or user config path for settings:
# Check project-level first
test -f .yux-publish/yux-publish-zhihu/EXTEND.md && echo "project"
# Then user-level
test -f "$HOME/.yux-publish/yux-publish-zhihu/EXTEND.md" && echo "user"
Supported settings:
| Key | Default | Description |
|---|---|---|
default_theme | zhihu | HTML rendering theme |
default_tags | empty | Default topic tags (comma-separated) |
default_action | draft | Default action: draft or publish |
Priority: CLI arguments > Frontmatter > EXTEND.md > Skill defaults
Copy this checklist and check off items as you complete them:
Publishing Progress:
- [ ] Step 0: Load preferences (EXTEND.md)
- [ ] Step 1: Convert content → HTML
- [ ] Step 2: Validate metadata
- [ ] Step 3: Dry-run checkpoint
- [ ] Step 4: Ensure browser debug port
- [ ] Step 5: Check Zhihu login status
- [ ] Step 6: Navigate to article editor
- [ ] Step 7: Fill title
- [ ] Step 8: Paste content into editor
- [ ] Step 9: Add topic tags
- [ ] Step 10: Save draft or publish
- [ ] Step 11: Report completion
Read EXTEND.md and parse configuration.
Input type detection:
| Input Type | Detection | Action |
|---|---|---|
| MDX file | Path ends with .mdx | Run conversion script |
| Markdown file | Path ends with .md | Run conversion script |
| HTML file | Path ends with .html | Use directly, skip to Step 2 |
Execute conversion:
npx -y bun ${PLUGIN_DIR}/scripts/zhihu/zhihu-publish.ts <file> --dry-run
Parse JSON output to get: title, description, tags, htmlPath, htmlContentPath, contentLength, imageCount
| Field | If Missing |
|---|---|
| Title | Prompt user or auto-extract from content |
| Description | Auto-extract from first paragraph (truncate to 120 chars) |
| Tags | Use EXTEND.md defaults, or prompt user |
If user specified --dry-run, show metadata summary and stop:
Zhihu Article Preview:
Title: [title]
Description: [description]
Tags: [tag list]
Content Length: [character count]
Images: [image count]
HTML Preview: [htmlPath]
Check if browser debug port is available:
curl -s http://127.0.0.1:9222/json/version
If unavailable:
/Applications/Arc.app/Contents/MacOS/Arc --remote-debugging-port=9222
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
mcp__chrome-devtools__navigate_page → https://www.zhihu.commcp__chrome-devtools__take_snapshot → check page contentIf not logged in:
Zhihu not logged in. Please log in manually:
1. Open https://www.zhihu.com/signin in the browser
2. Log in via SMS code or QR scan
3. Tell me when done
Use mcp__chrome-devtools__wait_for to detect login completion (user avatar appears).
mcp__chrome-devtools__navigate_page({ url: "https://zhuanlan.zhihu.com/write" })
Wait for editor to load:
mcp__chrome-devtools__wait_for — wait for title input to appearmcp__chrome-devtools__take_snapshot — confirm editor DOM structuremcp__chrome-devtools__take_snapshot — find title input areamcp__chrome-devtools__click — click title inputmcp__chrome-devtools__fill or mcp__chrome-devtools__type_text — enter titleZhihu title limit: Max 100 characters. If too long, truncate and prompt user.
Primary method — Clipboard paste:
npx -y bun ${PLUGIN_DIR}/scripts/zhihu/zhihu-publish.ts <file> --copy-html
mcp__chrome-devtools__take_snapshot — find content editor areamcp__chrome-devtools__click — click editor areamcp__chrome-devtools__press_key({ key: "Meta+a" }) — select all (clear placeholder)mcp__chrome-devtools__press_key({ key: "Meta+v" }) — pasteVerify paste result:
mcp__chrome-devtools__take_snapshot — check editor content is filledFallback method — JavaScript ClipboardEvent simulation (recommended):
If clipboard paste fails, read htmlContentPath file content and inject via evaluate_script.
CRITICAL: Zhihu editor is based on Draft.js. Content injection priority:
mcp__chrome-devtools__evaluate_script({
function: "() => { const editor = document.querySelector('[contenteditable=\"true\"]'); if (!editor) return 'editor_not_found'; editor.focus(); document.execCommand('selectAll'); document.execCommand('delete'); const html = decodeURIComponent('ENCODED_HTML'); const dt = new DataTransfer(); dt.setData('text/html', html); dt.setData('text/plain', ''); const evt = new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true }); editor.dispatchEvent(evt); return 'ok'; }"
})
Note: URL-encode HTML content before passing to decodeURIComponent. dispatchEvent returning false is normal (Draft.js calls preventDefault() to handle paste).
If Chrome DevTools MCP connection times out (common with many tabs), use CDP REST API + WebSocket directly:
# 1. Open new tab
curl --noproxy '*' -s -X PUT 'http://127.0.0.1:9222/json/new?https://zhuanlan.zhihu.com/write'
# 2. Use Runtime.evaluate via WebSocket
mcp__chrome-devtools__take_snapshot — find topic tag areamcp__chrome-devtools__type_text — enter tag text
c. mcp__chrome-devtools__wait_for — wait for autocomplete dropdown
d. mcp__chrome-devtools__take_snapshot — view dropdown options
e. mcp__chrome-devtools__click — click matching option
f. If no exact match, press Enter for custom tagZhihu limit: Max 5 topic tags.
Based on default_action or user instruction:
Save as draft (default):
mcp__chrome-devtools__take_snapshot — find "保存草稿" buttonmcp__chrome-devtools__click — click savemcp__chrome-devtools__wait_for — wait for success messagePublish:
mcp__chrome-devtools__take_snapshot — find "发布" buttonmcp__chrome-devtools__click — click publishmcp__chrome-devtools__wait_for — wait for publish successIMPORTANT: Always save as draft by default, unless user explicitly says "发布"/"直接发布"/"publish".
Zhihu Publishing Complete!
Input: [file type] - [file path]
Article:
Title: [title]
Description: [description]
Tags: [tag list]
Images: [N] images
Content: [character count] characters
Result:
[Saved as draft / Published]
Next Steps:
Manage articles: https://zhuanlan.zhihu.com/write
| Issue | Solution |
|---|---|
| Browser debug port unavailable | Close existing browser process, restart with debug mode |
| Zhihu login expired | Prompt user to manually re-login in browser |
| Editor load timeout | Refresh page and retry, check network connection |
| Clipboard paste loses formatting | Switch to JavaScript injection method |
| Topic tag no match | Use closest suggestion, or press Enter for custom tag |
| Title exceeds 100 chars | Truncate and prompt user to confirm |
| Images fail to load | Zhihu auto-downloads images — takes time, check in editor after saving draft |
| Content style abnormal | Zhihu editor overrides some styles, check actual result after publishing |