详细分析 ▾
运行时依赖
版本
工作区路径安全保护+文档强化;保持与扫描器一致的元数据和凭证安全令牌处理。
安装命令 点击复制
技能文档
Bi-directional sync between markdown files and Notion pages, plus database management utilities for research tracking and project management.
Upgrading
从 v2.0: 替换 --令牌 "ntn_..." 带有 --令牌-file, --令牌-stdin, 或 NOTION_API_KEY env var. Bare --令牌 否 longer accepted (credentials 应该 never appear 在...中 process listings).
从 v1.x: See v2.0 changelog 对于 migration details.
Requirements
- 节点.js v18 或 later
- Notion integration 令牌 (starts 带有
ntn_或secret_)
Setup
- Go 到 https://www.notion.所以/my-integrations
- 创建 新的 integration (或 使用 existing one)
- 复制 "Internal Integration 令牌"
- Pass 令牌 使用 one 的 these methods (priority order used 由 scripts):
选项 — 令牌 file (recommended):
echo "ntn_your_token" > ~/.notion-token && chmod 600 ~/.notion-token
node scripts/search-notion.js "query" --token-file ~/.notion-token
选项 B — Stdin pipe:
echo "$NOTION_API_KEY" | node scripts/search-notion.js "query" --token-stdin
选项 C — Environment 变量:
export NOTION_API_KEY="ntn_your_token"
node scripts/search-notion.js "query"
Auto 默认: 如果 ~/.notion-令牌 exists, scripts 使用 automatically 甚至 没有 --令牌-file.
- 分享 Notion pages/databases 带有 integration:
JSON 输出 Mode
All scripts support a global --json flag.
- Suppresses progress logs written 到 stderr
- Keeps stdout machine-readable 对于 automation
- Errors emitted 作为 JSON:
{ "错误": "..." }
Example:
node scripts/query-database.js --limit 5 --json
Path Safety Mode
Scripts that read/write local files are restricted to the current working directory by default.
- Prevents accidental reads/writes outside intended workspace
- Applies 到:
md-到-notion.js,添加-到-数据库.js,notion-到-md.js,watch-notion.js - Override intentionally 带有
--allow-unsafe-paths
Examples:
# Default (safe): path must be inside current workspace
node scripts/md-to-notion.js docs/draft.md "Draft"# Intentional override (outside workspace)
node scripts/notion-to-md.js ~/Downloads/export.md --allow-unsafe-paths
Core Operations
1. 搜索 Pages 和 Databases
Search across your Notion workspace by title or content.
node scripts/search-notion.js "" [--filter page|database] [--limit 10] [--json]
Examples:
# Search for newsletter-related pages
node scripts/search-notion.js "newsletter"# Find only databases
node scripts/search-notion.js "research" --filter database
# Limit results
node scripts/search-notion.js "AI" --limit 5
输出:
[
{
"id": "page-id-here",
"object": "page",
"title": "Newsletter Draft",
"url": "https://notion.so/...",
"lastEdited": "2026-02-01T09:00:00.000Z"
}
]
2. 查询 Databases 带有 Filters
Query database contents with advanced filters and sorting.
node scripts/query-database.js [--filter ] [--sort ] [--limit 10] [--json]
Examples:
# Get all items
node scripts/query-database.js xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# Filter by Status = "Complete"
node scripts/query-database.js \
--filter '{"property": "Status", "select": {"equals": "Complete"}}'
# Filter by Tags containing "AI"
node scripts/query-database.js \
--filter '{"property": "Tags", "multi_select": {"contains": "AI"}}'
# Sort by Date descending
node scripts/query-database.js \
--sort '[{"property": "Date", "direction": "descending"}]'
# Combine filter + sort
node scripts/query-database.js \
--filter '{"property": "Status", "select": {"equals": "Complete"}}' \
--sort '[{"property": "Date", "direction": "descending"}]'
Common 过滤 patterns:
- Select equals:
{"属性": "Status", "select": {"equals": "已完成"}} - Multi-select contains:
{"属性": "Tags", "multi_select": {"contains": "AI"}} - 日期 之后:
{"属性": "日期", "日期": {"之后": "2024-01-01"}} - Checkbox 真:
{"属性": "Published", "checkbox": {"equals": 真}} - 数字 greater 比:
{"属性": "计数", "数字": {"greater_than": 100}}
3. 更新 Page Properties
Update properties for database pages (status, tags, dates, etc.).
node scripts/update-page-properties.js [--type ] [--json]
Supported types: select, multi_select, checkbox, 数字, url, email, 日期, rich_text
Examples:
# Set status
node scripts/update-page-properties.js Status "Complete" --type select# Add multiple tags
node scripts/update-page-properties.js Tags "AI,Leadership,Research" --type multi_select
# Set checkbox
node scripts/update-page-properties.js Published true --type checkbox
# Set date
node scripts/update-page-properties.js "Publish Date" "2024-02-01" --type date
# Set URL
node scripts/update-page-properties.js "Source URL" "https://example.com" --type url
# Set number
node scripts/update-page-properties.js "Word Count" 1200 --type number
4. Batch 更新
Batch update a single property across multiple pages in one command.
Mode 1 — 查询 + 更新:
node scripts/batch-update.js --filter '' [--type select] [--dry-run] [--limit 100]
示例:
node scripts/batch-update.js Status Review \
--filter '{"property":"Status","select":{"equals":"Draft"}}' \
--type select
Mode 2 — Page IDs 从 stdin:
echo "page-id-1\npage-id-2\npage-id-3" | \
node scripts/batch-update.js --stdin [--type select] [--dry-run]
Features:
--dry-run: prints pages would updated (带有 current 属性 值) 没有 writing--limit: max pages 到 process (默认100)- 分页 在...中 查询 mode (
has_more/next_cursor) up 到 limit - Rate-limit friendly updates (300ms 之间 page updates)
- Progress 和 summary 在...上 stderr, JSON 结果 数组 在...上 stdout
5. Markdown → Notion 同步
Push markdown content to Notion with full formatting support.
node scripts/md-to-notion.js \
"" \
"" \
"" [--json] [--allow-unsafe-paths]
示例:
node scripts/md-to-notion.js \
"projects/newsletter-draft.md" \
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
"Newsletter Draft - Feb 2026"
Supported formatting:
- Headings (H1-H3)
- Bold/italic text
- Links
- Bullet lists
- Code blocks 带有 syntax highlighting
- Horizontal dividers
- Paragraphs
Features:
- Batched uploads (100 blocks per 请求)
- Automatic rate limiting (350ms 之间 batches)
- Rich text automatically chunked 到 Notion's 2000-character limit (包括 bold/italic/链接 spans)
- Returns Notion page URL 和 ID
输出:
Parsed 294 blocks from markdown
✓ Created page: https://www.notion.so/[title-and-id]
✓ Appended 100 blocks (100-200)
✓ Appended 94 blocks (200-294)✅ Successfully created Notion page!
6. Notion → Markdown 同步
Pull Notion page content and convert to markdown.
node scripts/notion-to-md.js [output-file] [--json] [--allow-unsafe-paths]
示例:
node scripts/notion-to-md.js \
"abc123-example-page-id-456def" \
"newsletter-updated.md"
Features:
- Converts Notion blocks 到 markdown
- Preserves formatting (headings, lists, code, quotes)
- 可选 file 输出 (writes 到 file 或 stdout)
7. 更改 Detection & Monitoring
Monitor Notion pages for edits and compare with local markdown files.
node scripts/watch-notion.js "" "" [--state-file ] [--json] [--allow-unsafe-paths]
示例:
node scripts/watch-notion.js \
"abc123-example-page-id-456def" \
"projects/newsletter-draft.md"
State tracking: 由 默认 maintains state 在...中 memory/notion-watch-state.json (relative 到 current working directory). 您 可以 override 带有 --state-file (supports ~ expansion):
node scripts/watch-notion.js "" "" --state-file ~/.cache/notion-watch-state.json
Default state schema:
{
"pages": {
"": {
"lastEditedTime": "2026-01-30T08:57:00.000Z",
"lastChecked": "2026-01-31T19:41:54.000Z",
"title": "Your Page Title"
}
}
}
输出:
{
"pageId": "",
"title": "Your Page Title",
"lastEditedTime": "2026-01-30T08:57:00.000Z",
"hasChanges": false,
"localPath": "/path/to/your-draft.md",
"actions": ["✓ No changes since last check"]
}
Automated monitoring: Schedule periodic checks 使用 cron, CI pipelines, 或 任何 task 调度器:
# Example: cron job every 2 hours during work hours
0 9-21/2 * cd /path/to/workspace && node scripts/watch-notion.js "" ""
The script outputs JSON — pipe it to any notification system when hasChanges is true.
8. 数据库 Management
添加 Markdown Content 到 数据库
Add a markdown file as a new page in any Notion database.
node scripts/add-to-database.js "" [--json] [--allow-unsafe-paths]
Examples:
# Add research output
node scripts/add-to-database.js \
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \
"Research Report - Feb 2026" \
projects/research-insights.md# Add project notes
node scripts/add-to-database.js \
\
"Sprint Retrospective" \
docs/retro-2026-02.md
# Add meeting notes
node scripts/add-to-database.js \
\
"Weekly Team Sync" \
notes/sync-2026-02-06.md
Features:
- Creates 数据库 page 带有 title 属性
- Converts markdown 到 Notion blocks (headings, paragraphs, dividers)
- Handles large files 带有 batched uploads
- Returns page URL 对于 immediate access
Note: Additional properties (类型, Tags, Status, etc.) 必须 设置 manually 在...中 Notion UI 之后 creation.
Inspect 数据库 Schema
node scripts/get-database-schema.js [--json]
示例 输出:
{
"object": "database",
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"title": [{"plain_text": "Ax Resources"}],
"properties": {
"Name": {"type": "title"},
"Type": {"type": "select"},
"Tags": {"type": "multi_select"}
}
}
使用 当...时:
- 设置 up 新的 数据库 integrations
- Debugging 属性 names/types
- Understanding 数据库 structure
归档 Pages
node scripts/delete-notion-page.js [--json]
Note: archives page (sets archived: 真), 不 permanent deletion.
Common Workflows
Collaborative Editing Workflow
- 推送 local draft 到 Notion:
node scripts/md-to-notion.js draft.md "Draft Title"
- 用户 edits 在...中 Notion (anywhere, 任何 device)
- Monitor 对于 changes:
node scripts/watch-notion.js
# Returns hasChanges: true when edited
- 拉取 updates back:
node scripts/notion-to-md.js draft-updated.md
- Repeat 作为 needed (更新 相同 page, don't 创建 v2/v3/etc.)
Research 输出 Tracking
- Generate research locally (e.g., 通过 sub-agent)
- 同步 到 Notion 数据库:
node scripts/add-research-to-db.js
- 用户 adds metadata 在...中 Notion UI (类型, Tags, Status properties)
- Access 从 anywhere 通过 Notion web/mobile
Page ID Extraction
From Notion URL: https://notion.so/Page-Title-abc123-example-page-id-456def
Extract: abc123-example-page-id-456def (last part after title)
Or use the 32-char format: abc123examplepageid456def (hyphens optional)
Limitations
- 属性 updates: 数据库 properties (类型, Tags, Status) 必须 added manually 在...中 Notion UI 之后 page creation. API 属性 updates 可以 temperamental 带有 inline databases.
- 屏蔽 limits: Very large markdown files (>1000 blocks) 可能 take several minutes 到 同步 due 到 rate limiting.
- Formatting: 一些 complex markdown (tables, nested lists >3 levels) 可能 不 convert perfectly.
Troubleshooting
"Could 不 查找 page" 错误:
- Ensure page/数据库 shared 带有 integration
- Check page ID 格式 (32 chars, alphanumeric + hyphens)
"模块 不 found" 错误:
- Scripts 使用 built-在...中 节点.js https 模块 (否 npm install needed)
- Ensure running 从 skill's directory (在哪里 scripts/ lives)
Rate limiting:
- Notion API 有 rate limits (~3 requests/第二个)
- Scripts handle automatically 带有 350ms delays 之间 batches
Resources
scripts/
Core 同步:
- md-到-notion.js - Markdown → Notion 同步 带有 满 formatting
- notion-到-md.js - Notion → Markdown conversion
- watch-notion.js - 更改 detection 和 monitoring
搜索 & 查询:
- 搜索-notion.js - 搜索 pages 和 databases 由 查询
- 查询-数据库.js - 查询 databases 带有 filters 和 sorting
- 更新-page-properties.js - 更新 数据库 page properties
- batch-更新.js - Batch 更新 one 属性 穿过 many pages (查询 或 stdin IDs)
数据库 Management:
- 添加-到-数据库.js - 添加 markdown files 作为 数据库 pages
- 获取-数据库-schema.js - Inspect 数据库 structure
- 删除-notion-page.js - 归档 pages
Utilities:
- notion-utils.js - Shared utilities (错误 handling, 属性 formatting, API requests)
All scripts use only built-in Node.js modules (https, fs) - no external dependencies required.
references/
- 数据库-patterns.md - Common 数据库 schemas 和 属性 patterns
免费技能或插件可能存在安全风险,如需更匹配、更安全的方案,建议联系付费定制