← 返回
开发者工具 Key 中文

Notion Sync

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...
使用 notion-sync CLI 或程序化 API 将本地工作区目录和文件同步到 Notion 页面。用于将文件推送到 Notion。
kitakitsune0x kitakitsune0x 来源
开发者工具 clawhub v0.1.0 1 版本 99895.2 Key: 需要
★ 0
Stars
📥 953
下载
💾 12
安装
1
版本
#latest

概述

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.json in 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.json under checksums field. Used by --diff to 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 folderCache avoids 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/.

版本历史

共 1 个版本

  • v0.1.0 当前
    2026-03-29 11:29 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

office-efficiency

Word / DOCX

ivangdavila
创建、检查和编辑 Microsoft Word 文档及 DOCX 文件,支持样式、编号、修订记录、表格、分节符及兼容性检查等功能。
★ 451 📥 150,287
office-efficiency

Excel / XLSX

ivangdavila
创建、检查和编辑 Microsoft Excel 工作簿及 XLSX 文件,支持可靠的公式、日期、类型、格式、重算及模板保留功能。
★ 376 📥 142,968
office-efficiency

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 924 📥 186,339