以把 capture 手机浏览器页面为例。在手机上利用 bookmarklet 把当前页面的标题和 URL,发送到 org-capture。
假设用这样一个 org-capture 模版保存链接:
(add-to-list
'org-capture-templates
'("l" "Link" entry (file "links.org")
"* %a"))
开启一个 HTTP 服务器,当有人访问 http://localhost:3000/?url=...&title=...
时,自动调用上面的 org-capture 模版:
(defun chunyang-org-capture-server (request)
(pcase-let (((eieio process headers) request))
(message "%S" headers)
(let ((path (assoc-default :GET headers)))
;; 只处理 GET /
(if (not (and path (string= path "/")))
(ws-send-404 process)
(let ((href (assoc-default "href" headers))
(title (assoc-default "title" headers)))
(setq title (decode-coding-string title 'utf-8))
(push (list href title) org-stored-links)
;; XXX 不确定这对不对
(org-link-store-props :type "http"
:link href
:description title
:annotation (org-link-make-string href title))
(let ((org-capture-link-is-already-stored t))
(org-capture nil "l"))
(let ((body "Successfully sent to Org Capture"))
(ws-response-header
process 200
(cons "Content-Type" "text/plain")
(cons "Content-Length" (string-bytes body)))
(ws-send process body)))))))
(ws-start #'chunyang-org-capture-server 3000)
然后在手机上建立 bookmarklet,类似以下(1、要把 *.xyz 网址改成你的,不然可能会发送到我的 Emacs 里;2、应该把 URLSearchParams 改成 encodeURIComponent,我刚刚发现前者有问题)
javascript:location.href = "https://frp.cadr.xyz/?" + \
new URLSearchParams({"href": location.href, "title": document.title})