content-forge/.claude/skills/import-draft/SKILL.md

184 lines
6.2 KiB
Markdown

---
name: import-draft
description: "Import external drafts into content-forge vault for publishing workflow. Use when the user has an existing draft file from another project or external location and wants to bring it into the content-forge production pipeline. Trigger words: import draft, 迁移草稿, 入库, 导入文章, bring into vault, move to drafts."
---
# Import Draft
Import external draft files into content-forge vault's `02-drafts/` directory, preparing them for the standard publishing workflow (format → assets → review → publish).
## When to Use
Use this skill when:
- User has a draft written outside the vault (another project, external file, etc.)
- User says "import this draft", "migrate this article", "bring into vault"
- Draft needs to go through content-forge publishing pipeline
- Draft may need modifications (image paths, frontmatter, etc.)
Do NOT use this skill when:
- Draft already exists in `02-drafts/` → use edit commands instead
- User wants to create new content from topic → use `write-article` skill instead
## Workflow
### Step 1: Read External Draft
Read the external draft file using the Read tool.
```
Read the file at <external_path>
```
Execution requirements:
- Read the complete file content
- Note the file location and any embedded resources (images, etc.)
### Step 2: Quality Check
Analyze the draft and list issues that need fixing before import.
Check for:
- **Image references**: Are paths correct? Do images exist?
- **Frontmatter**: Does it exist? Is it complete?
- **Structure**: Is the markdown well-formed?
- **Content issues**: Dead links, missing sections, formatting problems
Output format:
```markdown
## 草稿检查报告
### 文件信息
- 路径: <original_path>
- 行数: <N>
- 大小: <X>KB
### 🔴 必须修改(入库前)
| # | 问题 | 当前 | 建议 |
|---|------|------|------|
| 1 | ... | ... | ... |
### 🟡 建议修改(可选)
| # | 问题 | 建议 |
|---|------|------|
| 1 | ... | ... |
### ✅ 无问题项
- ...
```
### Step 3: Wait for User Confirmation
**CRITICAL**: Do NOT proceed to write without user confirmation.
Ask the user:
1. Which issues to fix
2. Whether to fix now or import as-is
3. Confirmation before any vault write
Output:
```
请确认:
1. 需要修改哪些问题?
2. 现在修改还是先入库再改?
3. 确认后我将写入 vault
```
### Step 4: Prepare Frontmatter
Generate standard frontmatter based on content-forge specification.
Required fields (see `references/frontmatter-spec.md`):
- `id`, `title`, `slug`, `status`, `content_type`, `channels`
- `language`, `source_urls`, `assets`, `cover_image`, `template`
- `owner`, `created_at`, `updated_at`
Slug generation:
- Extract from filename if possible
- Or generate from title (lowercase, hyphens, no special chars)
- Format: `YYYY-MM-DD-<slug>.md`
### Step 5: Write to Vault
Write the draft to `02-drafts/` directory.
```bash
# First cd to vault directory
cd /home/kang/apps/content-forge/content-forge
# Create the draft file
obsidian create path="02-drafts/<YYYY-MM-DD>-<slug>.md" content="<DRAFT_WITH_FRONTMATTER>"
```
Execution requirements:
- Must cd to vault directory first (obsidian CLI bug workaround)
- File must go to `02-drafts/` directory
- Filename must have date prefix
### Step 6: Set Frontmatter Properties
Set each frontmatter field using obsidian property:set.
```bash
# Required fields
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="id" value="<YYYY-MM-DD>-<slug>"
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="title" value="<title>"
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="slug" value="<slug>"
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="status" value="draft"
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="content_type" value="article"
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="channels" value='["wechat","x"]' type=list
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="language" value="zh-CN"
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="source_urls" value='[]' type=list
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="assets" value='[]' type=list
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="cover_image" value=""
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="template" value="article"
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="owner" value="content-forge"
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="created_at" value="<YYYY-MM-DD>T00:00:00+08:00"
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="updated_at" value="<YYYY-MM-DD>T00:00:00+08:00"
```
### Step 7: Migrate Assets (Optional)
If the draft has images, offer to migrate them to `05-assets/<slug>/`.
```bash
# Create assets directory
mkdir -p /home/kang/apps/content-forge/content-forge/05-assets/<slug>/
# Copy images
cp <external_image_paths> /home/kang/apps/content-forge/content-forge/05-assets/<slug>/
# Update draft's assets field
obsidian property:set path="02-drafts/<YYYY-MM-DD>-<slug>.md" name="assets" value='["05-assets/<slug>/cover.png"]' type=list
```
## Output Constraints
- Always wait for user confirmation before writing to vault
- List all issues before asking for confirmation
- Generate complete frontmatter, don't skip required fields
- Report success/failure clearly after write
## Quality Checklist
Before marking complete, verify:
- [ ] External draft fully read
- [ ] Quality issues listed and categorized
- [ ] User confirmed which issues to fix
- [ ] Frontmatter generated per spec
- [ ] Draft written to `02-drafts/`
- [ ] All frontmatter fields set correctly
- [ ] Assets migrated (if applicable)
- [ ] Final verification: `obsidian read path="02-drafts/<file>"` succeeds
## Failure Handling
- File not found: Return `[✗] 文件不存在: <path>`
- Vault not accessible: Return `[✗] Vault 不可用,请运行 obsidian vault 检查`
- Write failed: Return `[✗] 写入失败: <error>` and do not proceed
- User denies confirmation: Stop and wait for further instructions
## References
- `references/frontmatter-spec.md` — Complete frontmatter specification