Skip to content

Notebooks

Notebooks 是一款笔记和写作应用。Protocol Launcher 可以生成 Notebooks URL scheme 链接,用于打开文档、添加笔记、搜索、创建项目、追加文本、从 URL 导入,以及启动共享或同步。

使用

这个库有两种使用方式:

  • 从子路径按需导入,支持 Tree Shaking 并保持较小的包体积。
  • 从根包完整导入更适合快速脚本或演示,但会包含所有应用模块。

生产构建建议选择按需导入;完整导入适合快速脚本或演示。

选择安装方式

按需加载
推荐使用。生产环境优化。
全量导入
使用便捷。适合快速脚本。

打开文档

Notebooks 官方文档列出了两种打开文档的形式:notebooks://show/<path> 和直接内部链接形式 notebooks://<path>。路径相对于 Notebooks 根目录。

On-Demand
ts
import { openDocument, openInternalLink } from 'protocol-launcher/notebooks'

const showUrl = openDocument({
  path: 'escaped path to document',
})

const internalUrl = openInternalLink({
  path: 'escaped path to document',
})

添加、搜索和追加

addNote() 对应 notebooks://addnote/search() 对应 notebooks://search/append() 对应 notebooks://append/。可选的 parentscopedoc 值都是 Notebooks 路径。

On-Demand
ts
import { addNote, search, append } from 'protocol-launcher/notebooks'

const noteUrl = addNote({
  text: 'note body',
  title: 'Title is optional',
  parent: 'path to parent',
})

const searchUrl = search({
  term: 'term to search for',
  scope: 'book/to/search',
})

const appendUrl = append({
  text: 'text to add',
  doc: 'path to document.txt',
})

新建文档、任务和手绘

Notebooks 官方文档列出了 addNewDocaddNewTaskaddNewSketch。每个 URL 都可以选择传入父级 book 路径。

On-Demand
ts
import { newDocument, newTask, newSketch } from 'protocol-launcher/notebooks'

const documentUrl = newDocument({
  parent: 'path to parent',
})

const taskUrl = newTask({
  parent: 'path to parent',
})

const sketchUrl = newSketch({
  parent: 'path to parent',
})

导入、共享和同步

使用 grab() 可以从 URL 导入文档。Notebooks 还为 iPhone 和 iPad 官方记录了 wifi_sharingwebdav_sync,两者都可以选择限定到某个 book 路径。

On-Demand
ts
import { grab, wifiSharing, webdavSync } from 'protocol-launcher/notebooks'

const grabUrl = grab({
  url: 'URL',
  title: 'Title of document',
  parent: 'Path to target book',
})

const sharingUrl = wifiSharing({
  path: 'Path To Book To Share',
})

const syncUrl = webdavSync({
  path: 'Path To Book To Sync',
})

生成的 URL

ts
openDocument({ path: 'escaped path to document' })
// => 'notebooks://show/escaped%20path%20to%20document'

openInternalLink({ path: 'escaped path to document' })
// => 'notebooks://escaped%20path%20to%20document'

addNote({ text: 'note body', title: 'Title is optional', parent: 'path to parent' })
// => 'notebooks://addnote/note%20body&title=Title%20is%20optional&parent=path%20to%20parent'

addNote({ text: 'note body', title: 'title for document' })
// => 'notebooks://addnote/note%20body&title=title%20for%20document'

addNote({ text: 'note body' })
// => 'notebooks://addnote/note%20body'

search({ term: 'term to search for', scope: 'book/to/search' })
// => 'notebooks://search/term%20to%20search%20for&scope=book/to/search'

newDocument({ parent: 'path to parent' })
// => 'notebooks://addNewDoc&parent=path%20to%20parent'

newDocument()
// => 'notebooks://addNewDoc'

newTask({ parent: 'path to parent' })
// => 'notebooks://addNewTask&parent=path%20to%20parent'

newSketch({ parent: 'path to parent' })
// => 'notebooks://addNewSketch&parent=path%20to%20parent'

append({ text: 'text to add', doc: 'path to document.txt' })
// => 'notebooks://append/text%20to%20add&doc=path%20to%20document.txt'

grab({ url: 'URL', title: 'Title of document' })
// => 'notebooks://grab/URL&title=Title%20of%20document'

grab({ url: 'URL', title: 'Title of document', parent: 'Path to target book' })
// => 'notebooks://grab/URL&title=Title%20of%20document&parent=Path%20to%20target%20book'

grab({ url: 'URL' })
// => 'notebooks://grab/URL'

wifiSharing({ path: 'Path To Book To Share' })
// => 'notebooks://wifi_sharing/Path%20To%20Book%20To%20Share'

wifiSharing()
// => 'notebooks://wifi_sharing'

webdavSync({ path: 'Path To Book To Sync' })
// => 'notebooks://webdav_sync/Path%20To%20Book%20To%20Sync'

参考资料