Xiaohongshu Images Skill
This skill transforms markdown, HTML, or text content into beautifully styled HTML pages with AI-generated cover images, then captures them as sequential screenshots at 3:4 ratio for Xiaohongshu posting.Overview
The skill performs the following workflow:- Accept Content: Receives markdown, HTML, or txt format content from the user
- Load Prompt Template: Reads the prompt template from
prompts/default.mdin this skill’s directory - Determine Output Account: Determines which account folder to use (see Account Folder Resolution below)
- Generate Cover Image: Uses
/baoyu-cover-imageskill to generate a cover image based on the article content - Generate HTML: Creates a beautifully styled HTML page following the prompt template specifications
- Save Output: Saves the HTML to
~/Dev/obsidian/{account_folder}/articles/<date-title>/xhs-preview.html - Capture Screenshots: Takes sequential 3:4 ratio screenshots of the entire page without cutting text
Account Folder Resolution
The skill determines the output account folder using the following priority:Priority 1: Explicit --account Parameter
If the user specifies --account, use the corresponding folder:
Priority 2: Infer from Input File Path
If no--account is specified, try to infer from the input file path:
Priority 3: Fallback to Template Mapping
If the account cannot be determined from the path (e.g., raw content input), use template-based mapping:Account Folder Mapping Reference
Usage
When the user invokes this skill, follow these steps:Step 1: Identify the Input
The user will provide one of the following:- A file path to a markdown, HTML, or txt file (e.g.,
/path/to/article.md) - Raw content directly in the conversation
- A URL to fetch content from
Step 2: Read the Prompt Template
Read the prompt template from this skill’s directory:Step 3: Extract Article Title, Date, and Determine Account
From the content, extract:- Title: The main heading (h1) or first significant title in the content
- Date: Current date in YYYY-MM-DD format
- Account Folder: Determine using the priority rules above (—account → path inference → template mapping)
~/Dev/obsidian/{account_folder}/articles/<date>-<sanitized-title>/
- Replace spaces with hyphens
- Remove special characters
- Keep the title reasonably short (max 50 characters)
- All images go in
_attachments/subfolder
Step 4: Generate Cover Image with baoyu-cover-image Skill
⚠️ COMPLIANCE CHECK: Before generating, ensure the image concept complies with Xiaohongshu community guidelines (Section 11 of the prompt template). The image must:- Be age-appropriate with no revealing clothing or suggestive poses
- Avoid political symbols, violence, gambling, smoking, or alcohol abuse
- Convey positive, constructive messages
- Be culturally sensitive and original
/baoyu-cover-image skill to generate the cover image:
- Invoke the skill with the article content:
-
Style Selection:
- Let baoyu-cover-image auto-select based on content signals, OR
- Specify a style that matches the article tone:
tech- AI, coding, digital topicswarm- Personal stories, emotional contentbold- Controversial, attention-grabbing topicsminimal- Simple, zen-like contentplayful- Fun, casual, beginner-friendly contentnature- Wellness, health, organic topicsretro- History, vintage, traditional topicselegant- Business, professional content (default)
mom-reading-clubtemplate, override the default cover style with calligraphy & ink-wash illustration (书法水墨风): -
Use
--no-titleflag since Xiaohongshu covers typically use visual-only images without embedded text. -
Move the generated image to the correct location:
- baoyu-cover-image saves to
imgs/cover.pngrelative to the article - Move/copy to
~/Dev/obsidian/{account_folder}/articles/<date>-<title>/_attachments/cover-xhs.png
- baoyu-cover-image saves to
Step 5: Generate HTML
⚠️ COMPLIANCE CHECK: Before generating HTML, review the text content for compliance:- No absolute/superlative claims (最好、第一、国家级、最高级、全网最低价)
- No exaggerated effect claims (一分钟见效、吃完就变白)
- No false or unverified medical/financial advice
- No defamatory or offensive language
- If health/investment topics are involved, add disclaimer text
-
Parse the content to identify:
- Title (h1)
- Subtitles (h2-h6)
- Paragraphs
- Lists
- Code blocks
- Links
- Emphasis/bold text
- Blockquotes
-
Generate complete HTML following the template specifications:
- Dark gradient background
- 600px × 800px cream-colored card
- Proper typography with Google Fonts (Noto Serif SC, Inter, JetBrains Mono)
- Cover image at the top
- All specified styling for text, links, lists, code blocks, etc.
- Responsive design for mobile
- Important HTML Structure:
- Save the HTML to
~/Dev/obsidian/{account_folder}/articles/<date>-<title>/xhs-preview.html
Step 6: Take Screenshots
After generating the HTML, capture sequential screenshots of the.container element at exact 3:4 aspect ratio:
Screenshot Specifications:
- Container viewport: 600px × 800px (3:4 ratio)
- Output resolution: 1200px × 1600px (2x device scale factor)
- Each screenshot captures exactly the
.containerelement, not the full page
- Open the HTML page using Playwright browser with viewport larger than container
- Configure browser context:
- Viewport: 800px × 1000px (larger than container to ensure full visibility)
- Device scale factor: 2x for high-resolution output
- Scroll within the container:
- The
.containerelement hasoverflow-y: auto, making it internally scrollable - Start from
scrollTop = 0and increment through the content - Each scroll position captures one 3:4 ratio screenshot
- The
- Smart text boundary detection:
- Before each screenshot, analyze visible block elements (p, h1-h6, li, blockquote, pre, img)
- If an element would be cut at the bottom boundary, end the current screenshot before that element
- Add whitespace mask to cover partial content, maintaining clean 3:4 frame
- Next screenshot starts with the cut element at the top
- Capture the complete
.containercontent:- Use
container.screenshot()to capture only the container element (excludes page background) - Continue until all content is captured (scrollTop reaches scrollHeight - clientHeight)
- Use
- Save screenshots to
~/Dev/obsidian/{account_folder}/articles/<date>-<title>/_attachments/:- Sequential naming:
xhs-01.png,xhs-02.png,xhs-03.png, etc.
- Sequential naming:
- Each screenshot: exactly 1200×1600 pixels (3:4 ratio at 2x scale)
- Only the cream-colored card content is captured
- No text is cut off between screenshots
Step 7: Report Results
After completion, report to the user:- HTML file location
- Number of screenshots generated
- Screenshots folder location
- Preview of the first screenshot (if possible)
Directory Structure
Dependencies
This skill depends on:/baoyu-cover-imageskill for cover image generation (must be installed in~/.claude/skills/)
Example Workflow
User: Create a styled article page from this markdown:- Read prompt template from
prompts/default.md - Extract title: “My Article Title”
- Determine account folder (no —account specified, no path to infer from, using default template →
10_在悉尼和稀泥) - Create output folder:
~/Dev/obsidian/10_在悉尼和稀泥/articles/2024-01-14-my-article-title/ - Invoke
/baoyu-cover-imageskill with--no-titleflag to generate cover image - Move generated cover from
imgs/cover.pngto_attachments/cover-xhs.png - Generate styled HTML following template specifications
- Save to
~/Dev/obsidian/10_在悉尼和稀泥/articles/2024-01-14-my-article-title/xhs-preview.html - Open in browser and take 3:4 ratio screenshots
- Save screenshots to
~/Dev/obsidian/10_在悉尼和稀泥/articles/2024-01-14-my-article-title/_attachments/xhs-01.png, etc. - Report completion with file locations
--account mom-reading-clubspecified → use12_妈妈在读- Output to:
~/Dev/obsidian/12_妈妈在读/articles/2024-01-14-article-title/
- No —account specified
- Input path contains
12_妈妈在读→ infer account folder - Output to same folder:
~/Dev/obsidian/12_妈妈在读/articles/2024-01-14-xxx/
Custom Prompt Templates
Users can provide custom prompt templates by:- Placing a
.mdfile in theprompts/directory - Specifying the template name when invoking the skill
xiaohongshu-style template for this article”
Available Templates
Mom Reading Club Template
Use this template for all “Mom Reading Club” branded content:- Font: TsangerJinKai02 (仓耳今楷02) for titles - requires local installation
- Cover style: Chinese calligraphy & ink-wash illustration (书法水墨风)
- Aesthetic: Zen simplicity, elegant restraint, generous white space
- Color accent: Subtle gold (#C9A962)
- Target audience: Cultured mothers aged 30-45
Error Handling
If the/baoyu-cover-image skill fails:
- Display the error message to the user
- Offer to retry or proceed without cover image
- If proceeding without image, use a placeholder or omit the cover
- Verify the HTML file exists and is valid
- Check browser dependencies
- Report the specific error to the user
System Requirements
This skill requires:- Python 3.8+
- Playwright for screenshot capture (installed via pip:
pip install playwright && playwright install chromium) /baoyu-cover-imageskill installed in~/.claude/skills/
Notes
- The skill preserves all original content exactly as provided
- No modifications, simplifications, or deletions to the content
- The cover image is generated based on the article’s main theme
- Screenshots are optimized for Xiaohongshu’s 3:4 aspect ratio
- Text is never cut off in screenshots - boundaries are adjusted intelligently
Community Compliance (社区规范合规)
IMPORTANT: All generated content must comply with Xiaohongshu community guidelines.Quick Reference - Prohibited Content:
Official Guidelines:
- 社区规范: https://www.xiaohongshu.com/crown/community/rules
- 社区公约: https://www.xiaohongshu.com/crown/community/agreement
Compliance Workflow:
- Before image generation: Review theme for appropriateness
- Before HTML generation: Scan text for prohibited phrases
- Before final output: Run through compliance checklist in prompt template (Section 11.5)