有设置roam-ref protocol成功的吗?(linux)

虽然迟了,但是还是上了org-roam的车。卡在roam-ref protocol的设置上了,有配置成功的吗?

OS:archlinux

Emacs:27

没啥问题,配置(有需要可以自己改 org-roam-capture-ref-templates

(use-package org-roam-protocol :after org-protocol)

原始 org protocol inbox 的书签长这样

javascript:location.href='org-protocol://capture?template=ll&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title||"UNTITLED%20PAGE")+'&body='+encodeURIComponent(function()%7Bvar%20html%20=%20%22%22;var%20sel%20=%20window.getSelection();if%20(sel.rangeCount)%20%7Bvar%20container%20=%20document.createElement(%22div%22);for%20(var%20i%20=%200,%20len%20=%20sel.rangeCount;%20i%20%3C%20len;%20++i)%20%7Bcontainer.appendChild(sel.getRangeAt(i).cloneContents());%7Dhtml%20=%20container.innerHTML;%7Dvar%20dataDom%20=%20document.createElement('div');dataDom.innerHTML%20=%20html;dataDom.querySelectorAll('a').forEach(function(item,%20idx)%20%7Bconsole.log('find%20a%20link');var%20url%20=%20new%20URL(item.href,%20window.location.href).href;var%20content%20=%20item.innerText;item.innerText%20=%20'%5B%5B'+url+'%5D%5B'+content+'%5D%5D';%7D);%5B'p',%20'h1',%20'h2',%20'h3',%20'h4'%5D.forEach(function(tag,%20idx)%7BdataDom.querySelectorAll(tag).forEach(function(item,%20index)%20%7Bvar%20content%20=%20item.innerHTML.trim();if%20(content.length%20%3E%200)%20%7Bitem.innerHTML%20=%20content%20+%20'&%2313;&%2310;';%7D%7D);%7D);return%20dataDom.innerText.trim();%7D())

用 org roam protocol 长这样

javascript:location.href='org-protocol://roam-ref?template=r&ref='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&body='+encodeURIComponent(function()%7Bvar%20html%20=%20%22%22;var%20sel%20=%20window.getSelection();if%20(sel.rangeCount)%20%7Bvar%20container%20=%20document.createElement(%22div%22);for%20(var%20i%20=%200,%20len%20=%20sel.rangeCount;%20i%20%3C%20len;%20++i)%20%7Bcontainer.appendChild(sel.getRangeAt(i).cloneContents());%7Dhtml%20=%20container.innerHTML;%7Dvar%20dataDom%20=%20document.createElement('div');dataDom.innerHTML%20=%20html;dataDom.querySelectorAll('a').forEach(function(item,%20idx)%20%7Bconsole.log('find%20a%20link');var%20url%20=%20new%20URL(item.href,%20window.location.href).href;var%20content%20=%20item.innerText;item.innerText%20=%20'%5B%5B'+url+'%5D%5B'+content+'%5D%5D';%7D);%5B'p',%20'h1',%20'h2',%20'h3',%20'h4'%5D.forEach(function(tag,%20idx)%7BdataDom.querySelectorAll(tag).forEach(function(item,%20index)%20%7Bvar%20content%20=%20item.innerHTML.trim();if%20(content.length%20%3E%200)%20%7Bitem.innerHTML%20=%20content%20+%20'&%2313;&%2310;';%7D%7D);%7D);return%20dataDom.innerText.trim();%7D())

GNU Emacs 28.0.50 (build 1, x86_64-apple-darwin20.6.0, NS appkit-2022.60 Version 11.5.2 (Build 20G95)) of 2021-09-19

1赞

谢谢!

刚才又看了一遍文档,发现我有两个地方疏漏了:

  1. 想当然地以为org-roam-protocol已经autoload了
  2. roam-ref的模板变量(org-roam-capture-ref-templates)与普通org-roam-capture的模板变量(org-roam-capture-templates)不同

是的,我当初好像也被坑了😂

1赞

org-roam v2里 #+roam_keyROAM_REFS 属性取代了,roam-ref的模板应该怎样设置呢?能分享一下你的模板吗?

issue tracker 里找到了(把ROAM_ALIASES换成ROAM_REFS就行了),贴在这里吧。roam v2 还是太新了,文档里没有提到。

(setq org-roam-capture-templates
        '(("d" "default" plain
           "%?"
           :if-new (file+head "${slug}.org"
                              ":PROPERTIES:
:ROAM_ALIASES: %^{aliases}
:END:
#+title: ${title}\n")
           :immediate-finish t
           :unnarrowed t)))

edit:对于roam-ref,用默认模板即可,不需要设置模板,也不需要设置ROAM_REFS属性。默认模板得到的效果如下:

1赞

设置模板也是可以的。我的是这样(:if-new在新版中改成了:target):

(setq org-roam-capture-ref-templates
      '(("w" "website" plain
         "%?"
         :target
         (file+head "web/%<%Y%m%d%H%M%S>-${slug}.org"
                    "* ${title}\n${body}\n")
         :unnarrowed t)))

另外,sacha chua 的这篇 Capturing links quickly with emacsclient, org-protocol, and Chrome Shortcut Manager on Microsoft Windows 8 ,提到了一个好用的 Chrome插件 Shortcut-Manager,很好用。我找了好久,忘了在哪找到的了。分享在这里