complete-computing-environment/org_protocol.org

249 lines
10 KiB
Org Mode

:PROPERTIES:
:ID: cce/org_protocol
:ROAM_ALIASES: "an example of using makeDesktopItem nix derivation" org-protocol org-roam-protocol
:END:
#+TITLE: org-protocol to quickly annotate web pages
#+filetags: :CCE:
#+PROPERTY: header-args :mkdirp yes :results none
#+PROPERTY: header-args:yaml :tangle roles/endpoint/tasks/org-protocol.yml
#+PROPERTY: header-args:emacs-lisp :tangle org-protocol.el
#+ARCOLOGY_KEY: cce/org-protocol
#+ARCOLOGY_ALLOW_CRAWL: t
#+ARROYO_MODULE_WANTS: cce/org-roam.org
#+ARROYO_HOME_MODULE: hm/org-protocol.nix
#+ARROYO_SYSTEM_EXCLUDE: droid
#+ARROYO_EMACS_MODULE: org-protocol
In [[id:26c9e4fd-4501-4b8b-95ce-a2a5230d7c1e][Email and News and Information Pipelines]] I sketched out a data-flow of information from the internet in to my brain and my exobrain, the [[id:4cc8c5fc-ece0-4a34-8bf8-8fd0ac626bb4][Zettelkasten]]. I am zooming in here on a specific *edge* of that graph on this page, a direct conduit between Firefox Desktop and my [[id:d17a9ccf-0bfe-426e-85b3-d15771d3ee03][Archive]]. When I am actively reading a web page, when I need to jot a quick piece of information down, or remember a GitHub project, or capture a YouTube video to add to my queue later in the night, I want to get the information in to Emacs as quickly as possible. For anything that needs longer work or more thinking or will be done at a later date, I put it in to my Read It Later bag.
This page is a [[id:cce/cce][CCE]] module based on two sources[fn:1:https://cestlaz.github.io/post/using-emacs-70-org-protocol/][fn:2:https://org-roam.readthedocs.io/en/develop/roam_protocol/] from the WWW (Probably one of Sacha's Emacs weeklies) and the [[id:cce/org-roam][org-roam]] documentation.
[[id:cce/org-roam][org-roam]] provides native functionality for this in the =org-roam-protocol= library. I create a second capture template that just uses plain old org-protocol on its own to quickly capture YouTube videos or other things I wish to watch.
This =desktop= file creates an =org-protocol://= URL handler and forwards the URL to emacsclient. the =roam-ref= =org-protocol= handler will create a document in the wiki, with the title and ROAM_REF property keyword filled in. The javascript at the end is saved as bookmark in my Firefox toolbar and can be bound to keyboard with a thing like [[id:shortcutkey2url_webextensions][ShortcutKey2URL (WebExtensions)]] or the bookmarklets can be placed in the Bookmarks toolbar or to use the Awesomebar [[https://river.me/blog/url-bar-is-a-cli/][as a CLI]].
#+begin_src nix :tangle ~/arroyo-nix/hm/org-protocol.nix
{ pkgs, ... }:
{
home.packages = [
(pkgs.makeDesktopItem {
name = "org-protocol";
desktopName = "Emacs org-protocol handler";
exec = "emacsclient -c %u";
terminal = false;
categories = ["System"];
mimeTypes = ["x-scheme-handler/org-protocol"];
})
];
programs.firefox.profiles.default.settings = {
"network.protocol-handler.expose.org-protocol" = true;
"network.protocol-handler.warn-external.org-protocol" = false;
"security.external_protocol_requires_permission" = false; # sickos.jpg
};
}
#+end_src
** DONE figure out why [[id:cce/firefox_nix][Firefox on Nix]] always asks if it's okay to open external on each domain despite =warn-external= set
:LOGBOOK:
- State "DONE" from "NEXT" [2022-04-06 Wed 12:07]
:END:
* Capture Templates
** [[id:cce/org-roam][org-roam]] reference capture
Wiring it all together, the [[id:cce/org-roam][org-roam]] reference capture:
#+begin_src emacs-lisp
(with-eval-after-load 'org-roam
(require 'org-roam-protocol)
(add-to-list 'org-roam-capture-ref-templates
`("r" "reference" plain
,(s-join
"\n"
'("#+BEGIN_QUOTE"
"${body}"
"#+END_QUOTE"
""
"%?"))
:unnarrowed t
:if-new
(file+head
"%<%Y%m%d%H%M%S>-${slug}.org"
,(s-join
"\n"
'(":PROPERTIES:"
":roam_refs: ${ref}"
":END:"
"#+title: ${title}"
"#+filetags: Archive"
"[[file:archive.org][Archive]]"))))))
#+end_src
#+begin_src javascript
javascript:location.href = 'org-protocol://roam-ref?template=r&ref='+ encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title) + '&body=' + encodeURIComponent(window.getSelection())
#+end_src
** [[id:cce/org-roam][org-roam]] capture to clock
#+begin_src emacs-lisp
(with-eval-after-load 'org-capture
(add-to-list 'org-capture-templates
`("R" "Capture to Clock" entry
(clock)
,(s-join "\n"
'("* %a %? :Archive:"
":PROPERTIES:"
":ROAM_REF: %l"
":END:"
"%U"))
:unnarrowed
:jump-to-captured)))
#+end_src
#+begin_src javascript
javascript:location.href='org-protocol://capture?template=R&url='+encodeURIComponent(location.href)+'&title='+ encodeURIComponent(document.title)+'&body='+ encodeURIComponent(window.getSelection())
#+end_src
** [[id:94841773-88a0-4c41-9af8-fbf0d0a133d0][Videos]] queue capture
And one for capturing videos in to a watch queue.
#+begin_src emacs-lisp
(with-eval-after-load 'org-roam
(require 'org-roam-protocol)
(add-to-list 'org-roam-capture-ref-templates
`("O" "org-protocol video" plain
,(s-join
"\n"
'("* NEXT [[${ref}][${title}]]"
":PROPERTIES:"
":roam_refs: ${ref}"
":END:"
""
"${body}"))
:if-new
(file+head
"~/org/Video.org"
,(s-join
"\n"
'("#+title: Video Queue"
"#+ARCHIVE: video_archive.org::"
"#+filetags: Archive"))))))
#+end_src
#+begin_src javascript
javascript:location.href = 'org-protocol://roam-ref?template=O&ref='+ encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title) + '&body=' + encodeURIComponent(window.getSelection())
#+end_src
** NEXT [[id:eb4acb70-056e-405b-b5bd-0ccd2c809e1a][Interesting Github Projects]] collects projects I'm likely to want to use or peruse some day
need to just make this use regular org-protocol capture templates..... or figure out how to use org-roam-capture-ref-templates better...
#+begin_src emacs-lisp :comments none
(with-eval-after-load 'org-roam
(require 'org-roam-protocol)
(add-to-list 'org-roam-capture-ref-templates
`("P" "org-protocol project bookmark" entry
,(s-join
"\n"
'("* [[${ref}][${title}]]"
":PROPERTIES:"
":roam_refs: ${ref}"
":END:"
""
"${body} %?"))
:if-new
(file+head
"~/org/interesting_github_projects.org"
,(s-join
"\n"
'("#+title: Interesting GitHub Projects"
"#+filetags: Archive Topic"))))))
#+end_src
#+begin_src javascript
javascript:location.href='org-protocol://capture?template=P&url='+encodeURIComponent(location.href)+'&title='+ encodeURIComponent(document.title)+'&body='+ encodeURIComponent(window.getSelection())
#+end_src
** [[id:8803fda8-20cd-4d62-878d-dcb1b7853183][People]] capture
And one for quickly capturing Facebook friends' list in to [[id:8803fda8-20cd-4d62-878d-dcb1b7853183][People]] pages
#+begin_src emacs-lisp
(with-eval-after-load 'org-roam
(require 'org-roam-protocol)
(add-to-list 'org-roam-capture-ref-templates
`("p" "person" plain
,(s-join
"\n"
'("[[file:People.org][People]]"
"#+BIRTHDAY: %^{Birthday}t%?"
"#+BEGIN_QUOTE"
"${body}"
"#+END_QUOTE"))
:unnarrowed t
:if-new
(file+head
"%<%Y%m%d%H%M%S>-${slug}.org"
,(s-join
"\n"
'(":PROPERTIES:"
":roam_refs: ${ref}"
":END:"
"#+title: ${title}"
"#+filetags: Person"))))))
#+end_src
#+begin_src javascript
javascript:location.href = 'org-protocol://roam-ref?template=p&ref='+ encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title) + '&body=' + encodeURIComponent(window.getSelection())
#+end_src
** [[id:threads][Thread]] capture
And one for quickly capturing [[id:threads][Twitter Threads]] and posts in to my [[id:d17a9ccf-0bfe-426e-85b3-d15771d3ee03][Archive]]
#+begin_src emacs-lisp
(with-eval-after-load 'org-roam
(require 'org-roam-protocol)
(add-to-list 'org-roam-capture-ref-templates
`("t" "thread" plain
,(s-join
"\n"
'("[[id:d17a9ccf-0bfe-426e-85b3-d15771d3ee03][Archive]] [[id:threads][Thread]] about $?"
"#+BEGIN_QUOTE"
"${body}"
"#+END_QUOTE"))
:unnarrowed t
:if-new
(file+head
"%<%Y%m%d%H%M%S>-${slug}.org"
,(s-join
"\n"
'(":PROPERTIES:"
":roam_refs: ${ref}"
":END:"
"#+title: ${title}"
"#+filetags: :Archive:Thread:"))))))
#+end_src
This one extracts the quoted tweet out of the title:
#+begin_src javascript
javascript:location.href = 'org-protocol://roam-ref?template=t&ref='+ encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title.match(/"(.*)"/)[0].substring(0,64)) + '&body=' + encodeURIComponent(window.getSelection().toString() || document.title.match(/"(.*)"/))
#+end_src
* Provide the ELisp feature at the end
This is a stub...
#+begin_src emacs-lisp
(provide 'cce/org-protocol)
#+end_src