notion-to-weixin
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNotion to Weixin
Notion转微信
Config (Optional)
配置(可选)
Set a default in :
author~/.agents/config.yamlyaml
notion_to_weixin:
author: "Alice Wang"You can also set a global default:
yaml
author: "Alice Wang"在中设置默认:
~/.agents/config.yamlauthoryaml
notion_to_weixin:
author: "Alice Wang"你也可以设置全局默认值:
yaml
author: "Alice Wang"Workflow (Sequential)
工作流(顺序执行)
- Resolve Notion page ID from the given title.
- Export the page to Markdown.
- Ensure exists in Markdown front matter (and inject a byline if needed).
author - Process images (upload to Weixin and replace URLs in Markdown).
- Prepare :
thumb_media_id- If the Notion page has a cover, upload it as a Weixin material and use that ID.
thumb - If no cover, use the last image material ID.
- If the Notion page has a cover, upload it as a Weixin
- Create a new Weixin draft using Markdown input () and always pass
--format markdown.--css-path
- 根据给定标题解析Notion页面ID。
- 将页面导出为Markdown。
- 确保Markdown front matter中存在(必要时插入署名行)。
author - 处理图片(上传到微信并替换Markdown中的URL)。
- 准备:
thumb_media_id- 如果Notion页面有封面,将其作为微信素材上传并使用返回的ID。
thumb - 如果没有封面,使用最近上传的图片素材ID。
- 如果Notion页面有封面,将其作为微信
- 使用Markdown输入()创建新的微信草稿,且始终传入
--format markdown参数。--css-path
Inputs (Ask the user if missing)
输入项(缺失时询问用户)
- : exact Notion page title to publish.
notion_title - : optional author name (used for Markdown front matter and node-wxcli
author). If missing, read from--author.~/.agents/config.yaml - : required when using
css_path; if missing, default to--format markdown.assets/default.css - : only required if cover and image fallback both fail.
thumb_media_id
- :要发布的Notion页面的准确标题。
notion_title - :可选的作者名称(用于Markdown front matter和node-wxcli的
author参数)。如果缺失,从--author读取。~/.agents/config.yaml - :使用
css_path时必填;如果缺失,默认使用--format markdown。assets/default.css - :仅当封面和图片回退方案都失效时需要提供。
thumb_media_id
Prerequisites
前置要求
- installed and authenticated (NOTION_TOKEN or
notion-cli).notion auth set - installed and authenticated (
node-wxcliornode-wxcli auth set).node-wxcli auth login - and
curlavailable.jq
- 已安装并完成认证(通过NOTION_TOKEN或
notion-cli)。notion auth set - 已安装并完成认证(通过
node-wxcli或node-wxcli auth set)。node-wxcli auth login - 环境中存在和
curl工具。jq
Step 1: Resolve Page ID by Title
步骤1:根据标题解析页面ID
- Copy to a temp file and replace
references/notion-search.json.__TITLE__ - Run .
notion search --body @query.json - Choose the exact-title match. If multiple matches remain, pick the most recently edited or ask the user to confirm.
- If no match is found, ask for a Notion page ID or URL and extract the ID.
- 将复制到临时文件并替换
references/notion-search.json占位符。__TITLE__ - 执行。
notion search --body @query.json - 选择标题完全匹配的结果。如果存在多个匹配项,选择最近编辑的版本或询问用户确认。
- 如果未找到匹配项,请求用户提供Notion页面ID或URL并从中提取ID。
Step 2: Export Page to Markdown
步骤2:将页面导出为Markdown
- Use when the page contains images.
notion pages export <page_id> --assets=download -o <workdir>/page.md - Use a workdir like .
/tmp/notion-to-weixin/<slug-or-timestamp>
- 当页面包含图片时,使用命令。
notion pages export <page_id> --assets=download -o <workdir>/page.md - 使用类似的工作目录。
/tmp/notion-to-weixin/<slug-or-timestamp>
Step 3: Default Author Handling
步骤3:默认作者处理
- If is not provided, read it from
author.~/.agents/config.yaml - Ensure exists in Markdown front matter (and add a byline if you want it visible in content).
author
- 如果未提供,从
author读取该配置。~/.agents/config.yaml - 确保Markdown front matter中存在(如果需要在内容中显示,可添加署名行)。
author
Step 4: Process Images (Recommended)
步骤4:处理图片(推荐执行)
If the Notion page contains images, upload them to Weixin and replace Markdown image URLs
so they remain valid for draft rendering.
- Find image links in . Notion exports local images under the assets folder.
<workdir>/page.md - For each local image file, upload it and capture the :
url
bash
node-wxcli material upload --type image --file <workdir>/assets/<image-file> --json | jq -r '.url'- Replace the Markdown image URL with the returned :
url
markdown
If you skip this step, images that reference local files or expiring Notion URLs may not render in Weixin.
如果Notion页面包含图片,将其上传到微信并替换Markdown中的图片URL,以确保草稿渲染时图片可正常显示。
- 查找中的图片链接。Notion导出的本地图片存放在assets文件夹下。
<workdir>/page.md - 对每个本地图片文件,上传并获取返回的:
url
bash
node-wxcli material upload --type image --file <workdir>/assets/<image-file> --json | jq -r '.url'- 用返回的替换Markdown中的图片URL:
url
markdown
如果跳过此步骤,引用本地文件或临时Notion URL的图片可能无法在微信中渲染。
Step 5: Prepare thumb_media_id
thumb_media_id步骤5:准备thumb_media_id
thumb_media_id5.1 If Notion page has a cover
5.1 如果Notion页面有封面
- Fetch page metadata (use notion-cli):
bash
notion pages get <page_id> > <workdir>/page.json- Extract cover type + cover URL:
bash
cover_type=$(jq -r '.cover.type // ""' <workdir>/page.json)
cover_url=$(jq -r '.cover | if .==null then "" elif .type=="external" then .external.url else .file.url end' <workdir>/page.json)- If cover type is , download via notion-cli; if
file, use curl:external
bash
if [ "$cover_type" = "file" ]; then
jq -c '.cover' <workdir>/page.json | notion files read --body @- --output <workdir>/cover.jpg
else
curl -L "$cover_url" -o <workdir>/cover.jpg
fi
thumb_media_id=$(node-wxcli material upload --type thumb --file <workdir>/cover.jpg --json | jq -r '.media_id')Note: Notion file URLs expire quickly. If download fails, re-fetch page metadata and retry.
- 获取页面元数据(使用notion-cli):
bash
notion pages get <page_id> > <workdir>/page.json- 提取封面类型+封面URL:
bash
cover_type=$(jq -r '.cover.type // ""' <workdir>/page.json)
cover_url=$(jq -r '.cover | if .==null then "" elif .type=="external" then .external.url else .file.url end' <workdir>/page.json)- 如果封面类型是,通过notion-cli下载;如果是
file,使用curl下载:external
bash
if [ "$cover_type" = "file" ]; then
jq -c '.cover' <workdir>/page.json | notion files read --body @- --output <workdir>/cover.jpg
else
curl -L "$cover_url" -o <workdir>/cover.jpg
fi
thumb_media_id=$(node-wxcli material upload --type thumb --file <workdir>/cover.jpg --json | jq -r '.media_id')注意:Notion文件URL会快速过期。如果下载失败,重新获取页面元数据并重试。
5.2 If no cover exists
5.2 如果没有封面
- Get image material count:
bash
image_count=$(node-wxcli material count --json | jq -r '.image_count')- If , fetch the last image and use its
image_count > 0:media_id
bash
offset=$((image_count - 1))
thumb_media_id=$(node-wxcli material list --type image --offset "$offset" --count 1 --json | jq -r '.item[0].media_id')- If no images exist, ask the user to provide a or upload a thumb manually.
thumb_media_id
- 获取图片素材数量:
bash
image_count=$(node-wxcli material count --json | jq -r '.image_count')- 如果,获取最近上传的图片并使用其
image_count > 0:media_id
bash
offset=$((image_count - 1))
thumb_media_id=$(node-wxcli material list --type image --offset "$offset" --count 1 --json | jq -r '.item[0].media_id')- 如果没有任何图片,请求用户提供或手动上传封面。
thumb_media_id
Step 6: Create Weixin Draft (Markdown input)
步骤6:创建微信草稿(Markdown输入)
When using Markdown format, always pass . If is missing, set:
--css-pathcss_pathbash
css_path=${css_path:-assets/default.css}bash
node-wxcli draft add \
--title "<notion_title>" \
--author "<author>" \
--format markdown \
--content - \
--css-path <css_path> \
--need-open-comment=1 \
--only-fans-can-comment=0 \
--thumb-media-id "$thumb_media_id" < <workdir>/page.md- If you need machine-readable output, add and capture the returned
--json.media_id
使用Markdown格式时,始终传入参数。如果缺失,设置:
--css-pathcss_pathbash
css_path=${css_path:-assets/default.css}bash
node-wxcli draft add \
--title "<notion_title>" \
--author "<author>" \
--format markdown \
--content - \
--css-path <css_path> \
--need-open-comment=1 \
--only-fans-can-comment=0 \
--thumb-media-id "$thumb_media_id" < <workdir>/page.md- 如果需要机器可读的输出,添加参数并捕获返回的
--json。media_id
Resources
资源
- : JSON template for Notion title search.
references/notion-search.json - : Canonical CLI command examples for
references/cli-commands.mdandnotion-cli.node-wxcli - : Default CSS theme for
assets/default.css(--format markdown).--css-path
Notes:
- Use if the title search is ambiguous.
--page-id - Use only if cover and image fallback are unavailable.
--thumb-media-id
- :用于Notion标题搜索的JSON模板。
references/notion-search.json - :
references/cli-commands.md和notion-cli的标准CLI命令示例。node-wxcli - :
assets/default.css模式下使用的默认CSS主题(--format markdown参数)。--css-path
注意:
- 如果标题搜索结果不明确,使用参数。
--page-id - 仅当封面和图片回退方案都不可用时,才使用参数。
--thumb-media-id