aiworkskills/wechat-article-skills / skills/aws-wechat-article-publish
aws-wechat-article-publish
Verified公众号发布|公众号草稿箱|公众号群发|图文推送|微信 API|wechat automation|WeChat API automation|auto publish|scheduled publish — 公众号 API 发布工具,图文入草稿箱或直接群发,支持封面素材上传、发布前检查与 draft/published 模式切换。面向公众号运营、自动化内容团队、开发者。触发词:「发布」「提交」「群发」「推送」「发出去」「上传到公众号」「发到公众号」「可以发了吗」「发布前检查」。需要多环节串联(写+审+排+配图+发)请走 aws-wechat-article-main。
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 8.3 KB |
| references/api-reference.md | markdown | 4.9 KB |
| references/branches.md | markdown | 5.0 KB |
| references/pre-publish-checklist.md | markdown | 1.5 KB |
| references/submit-guide.md | markdown | 2.4 KB |
| references/usage.md | markdown | 2.4 KB |
| scripts/article_init.py | script | 9.4 KB |
| scripts/getdraft.py | script | 16.3 KB |
| scripts/publish.py | script | 45.8 KB |
| skill.json | config | 494 B |
scripts/article_init.py
View on GitHub#!/usr/bin/env python3
"""
文章元数据初始化工具(发布子 skill)
在流程中的位置:
- **本篇准备**(总览 main):建好 `drafts/…` 目录后,可初始化本篇 **`article.yaml`**(标题/作者/摘要等)。
- **发布前**:定稿后再次更新 **`article.yaml`**(与 **`publish.py`** 读取的字段一致)。
不属于七步箭头里的单独一格:元数据贯穿 **写稿 → … → 发布**,脚本主要在 **「建目录之后、写稿前后」** 与 **「发布前」** 使用。
用途:
- 为某一篇文章目录初始化或更新元数据(**`article.yaml`**)
- 可选生成文末链接文件(**`closing.md`**)
约定:
- 文章目录结构:
<article_dir>/
├── article.yaml # 元信息(标题/作者/摘要等)
├── *.md # 正文 Markdown(可选)
├── closing.md # 本篇专属文末(可选,若存在会在排版时自动追加)
└── imgs/ # 正文图片(可选)
"""
import argparse
from pathlib import Path
import sys
import yaml
def _info(msg: str):
print(f"[INFO] {msg}")
def _ok(msg: str):
print(f"[OK] {msg}")
def _err(msg: str):
print(f"[ERROR] {msg}", file=sys.stderr)
sys.exit(1)
def _load_yaml_example() -> str:
"""优先加载仓库内 .aws-article/article.example.yaml 的内容,找不到则给出最小模板。
仅在当前仓库根 `.aws-article/` 下查找;不再回退到用户主目录,避免读取仓库外的文件。
"""
repo_example = Path(".aws-article/article.example.yaml")
if repo_example.exists():
return repo_example.read_text(encoding="utf-8")
# 最小可用模板
return (
"# 文章元数据\n"
"title: \"\"\n"
"author: \"\"\n"
"digest: \"\"\n"
"cover_image: \"\"\n"
"content_source: \"article.html\"\n"
"image_source: \"generated\"\n"
# 本篇信息位配图的媒介(白板 / 便签 / 终端等宽 等),由 images skill 的
# image-method 第四步选定并写回。下一篇据此避开最近几篇用过的,
# 否则整个号会只剩一种长相。
"image_medium: \"\"\n"
"user_images_dir: \"imgs/\"\n"
"img_analysis_file: \"img_analysis.md\"\n"
"need_open_comment: 1\n"
"only_fans_can_comment: 0\n"
"publish_completed: false\n"
)
def _parse_links(links: str) -> list[tuple[str, str]]:
"""
将形如 '标题A|https://a; 标题B|https://b' 的字符串解析为列表。
忽略空项与不合法项。
"""
items: list[tuple[str, str]] = []
if not links:
return items
for part in links.split(";"):
part = part.strip()
if not part:
continue
if "|" not in part:
continue
name, url = part.split("|", 1)
name = name.strip()
url = url.strip()
if name and url:
items.append((name, url))
return items
def _write_closing_md(article_dir: Path, links: list[tuple[str, str]], overwrite: bool) -> Path | None:
"""根据 links 生成/更新 closing.md;若无 links 且文件已存在且非覆盖,则不动。"""
closing_path = article_dir / "closing.md"
if not links:
return closing_path if closing_path.exists() else None
if closing_path.exists() and not overwrite:
_info(f"closing.md 已存在,跳过写入(使用 --overwrite 可覆盖):{closing_path}")
return closing_path
lines = ["---", "延伸阅读:"]
for title, url in links:
lines.append(f"- [{title}]({url})")
content = "\n".join(lines) + "\n"
closing_path.write_text(content, encoding="utf-8")
_ok(f"写入文末链接: {closing_path}")
return closing_path
# 这些字段即使 config.yaml 里没有也要建出来。
#
# 排版那两项(模版 + 配色)都是**本篇的选择**,不是账号级候选池,网站导出的
# config.yaml 里可以整个没有这两个键。而本函数原本要求「config 里有这个键才补」,
# 于是它们永远不会出现在 article.yaml 里,main 第 4 步却要求本篇必须落盘。
#
# 后果是静默的:format.py 读不到 default_format_preset 就退回内置默认模版 亲和,
# 不报错也不提醒——一篇本该用「资讯」的稿子会长成「亲和」的样子,而日志里只有
# 一行「主题来自内置默认」。实测 2026-09-11 跑全流程时就是这样:config 里两个键
# 都没有,article_init 建出来的 article.yaml 也就两个都缺。
#
# 「必须用 article_init 初始化」这条规则正是为了不依赖 Agent 记性,所以补在这里,
# 而不是指望每次都有人想起来手加。
ALWAYS_PRESET_FIELDS = frozenset({"default_format_preset", "default_format_scheme"})
PRESET_FIELDS = [
"default_structure",
"default_closing_block",
"default_title_style",
"default_format_preset",
"default_format_scheme",
"default_cover_image_style",
"default_article_image_style",
"default_sticker_style",
]
def _ensure_preset_fields(article_yaml_path: Path):
"""
若仓库存在 .aws-article/config.yaml,则在 article.yaml 中补齐预设字段,
初始值统一为空列表 [](仅补缺,不覆盖已有值)。
若 config 不存在则不处理,保持 article.yaml 可为空。
"""
cfg_path = Path(".aws-article/config.yaml")
if not cfg_path.is_file():
_info("未发现 .aws-article/config.yaml,跳过预设字段初始化")
return
try:
cfg_data = yaml.safe_load(cfg_path.read_text(encoding="utf-8")) or {}
except (OSError, yaml.YAMLError):
_info("读取 .aws-article/config.yaml 失败,跳过预设字段初始化")
return
if not isinstance(cfg_data, dict):
_info(".aws-article/config.yaml 不是 YAML 对象,跳过预设字段初始化")
return
try:
art_data = yaml.safe_load(article_yaml_path.read_text(encoding="utf-8")) or {}
except (OSError, yaml.YAMLError):
_info("读取 article.yaml 失败,跳过预设字段初始化")
return
if not isinstance(art_data, dict):
_info("article.yaml 不是 YAML 对象,跳过预设字段初始化")
return
changed = False
for key in PRESET_FIELDS:
if key not in art_data and (key in cfg_data or key in ALWAYS_PRESET_FIELDS):
art_data[key] = []
changed = True
if changed:
article_yaml_path.write_text(
yaml.safe_dump(art_data, allow_unicode=True, sort_keys=False),
encoding="utf-8",
)
_ok(f"已补齐预设字段(初始为空): {article_yaml_path}")
else:
_info("预设字段已齐全或 config 未声明对应字段,跳过写入")
def _merge_article_yaml(existing_text: str, title: str, author: str, digest: str) -> str:
"""
朴素合并:逐行替换常见键;若不存在则在末尾追加。
仅处理少量关键字段,避免引入额外依赖。
"""
lines = existing_text.splitlines()
keys = {
"title": title,
"author": author,
"digest": digest,
}
found = {k: False for k in keys}
for i, line in enumerate(lines):
for key, val in keys.items():
if val is None or val == "":
continue
prefix = f"{key}:"
if line.strip().startswith(prefix):
# 保留引号以避免 YAML 解析歧义
lines[i] = f'{key}: "{val}"'
found[key] = True
# 追加缺失键
for key, val in keys.items():
if val is None or val == "":
continue
if not found[key]:
lines.append(f'{key}: "{val}"')
return "\n".join(lines) + ("\n" if not existing_text.endswith("\n") else "")
def main():
parser = argparse.ArgumentParser(
description="初始化或更新某一篇文章的元数据与文末链接",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument("article_dir", help="文章目录(如 drafts/20260326-标题slug)")
parser.add_argument("--title", help="文章标题")
parser.add_argument("--author", help="作者名")
parser.add_argument("--digest", help="摘要(80-128字建议)")
parser.add_argument(
"--links",
help="文末链接,使用 '标题A|URLA; 标题B|URLB' 形式;将写入 closing.md",
)
parser.add_argument(
"--overwrite",
action="store_true",
help="若 closing.md 已存在则允许覆盖",
)
args = parser.parse_args()
article_dir = Path(args.article_dir)
article_dir.mkdir(parents=True, exist_ok=True)
article_yaml_path = article_dir / "article.yaml"
if article_yaml_path.exists():
text = article_yaml_path.read_text(encoding="utf-8")
_info(f"更新 article.yaml: {article_yaml_path}")
else:
_info("未发现 article.yaml,基于示例创建")
text = _load_yaml_example()
merged = _merge_article_yaml(text, args.title or "", args.author or "", args.digest or "")
article_yaml_path.write_text(merged, encoding="utf-8")
_ok(f"已写入: {article_yaml_path}")
_ensure_preset_fields(article_yaml_path)
links = _parse_links(args.links or "")
if links:
_write_closing_md(article_dir, links, overwrite=args.overwrite)
else:
_info("未提供 --links,跳过生成 closing.md")
_ok("初始化完成")
if __name__ == "__main__":
main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |