简介
CLI 工具将本地目录双向同步至 Notion 页面,支持增量更新、智能分块与 ignore 规则管理
原始描述
Sync local workspace directories and files to Notion pages using the notion-sync CLI or programmatic API. Use when the user wants to push files to Notion, mi...
通过你的 Agent 添加
安装目录:notion-sync/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
notion-sync 是一款 Node.js CLI 工具与程序化库,用于将本地文件系统镜像同步到 Notion 工作区。核心工作流为:
- 初始化配置:运行
notion-sync init生成.notion-sync.json,需预先在 Notion 创建 Integration 并授权目标页面 - 执行同步:
notion-sync sync将文件夹转为带图标的页面,文件转为子页面内容 - 增量策略:
--diff模式通过 MD5 校验比对跳过未变更文件,显著降低 API 调用量 - 内容分块:自动将文件拆分为 1800 字符块以适应 Notion API 限制,采用"清空-重填"的 upsert 策略
显著优点
- 双向 CLI + API:既支持命令行快速操作,也提供完整 TypeScript 类型定义的程序化接口
- 智能增量同步:内置 checksum 缓存机制,避免冗余上传
- 灵活过滤:支持
.gitignore风格的 glob 模式,默认排除node_modules、密钥文件等 - dry-run 预览:所有变更可先预览再执行,降低误操作风险
潜在局限
- 单向同步:仅支持本地→Notion 推送,无法将 Notion 端修改回写本地
- 破坏性更新:现有页面采用"删除全部 blocks 再追加"策略,会丢失 Notion 端的评论、格式微调等元数据
- Rate Limit 敏感:大规模目录易触发 Notion API 限流,需自行处理重试
- Token 安全:配置文件中明文存储 Integration Token,需配合
.gitignore使用
适合人群
- 技术文档团队:需将 Markdown/代码库自动发布至 Notion 知识库
- 个人开发者:希望用 Git 管理内容,同时利用 Notion 作为阅读端
- CI/CD 场景:在构建流程中自动同步 changelog、API 文档
常规风险
| 风险点 | 说明 |
|---|---|
| Token 泄露 | ntn_xxx 具有完整工作区权限,误提交至版本控制将导致严重数据暴露 |
| 数据覆盖 | 同步会不可逆覆盖 Notion 端同名页面内容 |
| API 配额 | 免费版 Integration 有请求频率限制,大仓库可能同步失败 |
技能正文
name: notion-sync description: Sync local workspace directories and files to Notion pages using the notion-sync CLI or programmatic API. Use when the user wants to push files to Notion, mirror a directory structure into Notion, initialize notion-sync config, manage ignore patterns, or check sync status.
notion-sync
CLI and library for syncing a local directory tree into Notion. Folders become Notion pages, files become sub-pages with content.
Quick Reference
Installation
npm install -g @kitakitsune/notion-sync
Requires Node.js >= 18.
Initialization
notion-sync init --token ntn_xxx --page <notion-page-id> [--dir <path>]
- Creates
.notion-sync.jsonin the target directory - The Notion integration must be shared with the target root page first
Sync Commands
notion-sync sync # sync everything
notion-sync sync --dry-run # preview changes
notion-sync sync --diff # only sync changed files
notion-sync sync --dir /some/path # sync a specific directory
notion-sync status # show sync state
notion-sync ignore list # list ignore patterns
notion-sync ignore add "*.env" # add ignore pattern
Default Ignore Patterns
node_modules, .git, dist, .notion-sync.json, *.lock, *.log
Programmatic Usage
import { syncWorkspace, initConfig, loadConfig, saveConfig } from '@kitakitsune/notion-sync';
import type { NotionSyncConfig } from '@kitakitsune/notion-sync';
const config = loadConfig(process.cwd());
const result = await syncWorkspace(config, { dryRun: false, diffOnly: true });
// result.pushed - files that were synced
// result.skipped - files unchanged (when diffOnly)
// result.errors - files that failed
Architecture
src/
cli.ts - Commander.js CLI (init, sync, ignore, status)
sync.ts - Core sync logic, Notion API calls, checksum diffing
config.ts - Load/save/init .notion-sync.json
types.ts - NotionSyncConfig interface
index.ts - Public API exports
bin/
notion-sync.js - CLI entry point
Key Implementation Details
- Checksums: MD5 hashes stored in
.notion-sync.jsonunderchecksumsfield. Used by--diffto skip unchanged files. - Content chunking: File content is split into 1800-character blocks for the Notion API.
- Page upsert: Existing pages are updated by deleting all blocks then re-appending. New pages are created with content inline.
- Folder hierarchy: Directories are created as Notion pages with folder icon. A
folderCacheavoids redundant API calls.
Config File Structure
.notion-sync.json:
{
"path": "/absolute/path",
"notion": {
"token": "ntn_...",
"rootPageId": "page-id"
},
"ignore": ["node_modules", ".git", "dist", ".notion-sync.json", "*.lock", "*.log"],
"checksums": { "src/index.ts": "md5hash" }
}
Development
npm run dev # watch mode (tsup)
npm run build # production build
Build uses tsup to bundle TypeScript to ESM format. Output goes to dist/.
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。