diff --git a/CHANGELOG.md b/CHANGELOG.md index c2c7f73..3ddc8f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#1183](https://github.com/org-roam/org-roam/pull/1183) add interactive functions for managing aliases and tags in Org-roam file, namely `org-roam-alias-add`, `org-roam-alias-delete`, `org-roam-tag-add`, and `org-roam-tag-delete`. - [#1215](https://github.com/org-roam/org-roam/pull/1215) Multiple `ROAM_KEY` keywords can now be specified in one file. This allows bibliographical entries to share the same note file. - [#1238](https://github.com/org-roam/org-roam/pull/1238) add `org-roam-prefer-id-links` variable to select linking method +- [#1239](https://github.com/org-roam/org-roam/pull/1239) Allow `org-roam-protocol` to capture the webpage's selection, and add a toggle for storing the links to the pages ### Bugfixes diff --git a/org-roam-capture.el b/org-roam-capture.el index 49dc7c7..b2cb550 100644 --- a/org-roam-capture.el +++ b/org-roam-capture.el @@ -512,7 +512,8 @@ GOTO and KEYS argument have the same functionality as `org-capture'." (let* ((org-capture-templates (mapcar #'org-roam-capture--convert-template org-roam-capture-templates)) (one-template-p (= (length org-capture-templates) 1)) - org-capture-templates-contexts) + org-capture-templates-contexts + (org-capture-link-is-already-stored t)) (when one-template-p (setq keys (caar org-capture-templates))) (if (or one-template-p diff --git a/org-roam-protocol.el b/org-roam-protocol.el index 38bbac4..9fe4a0e 100644 --- a/org-roam-protocol.el +++ b/org-roam-protocol.el @@ -39,6 +39,11 @@ (require 'org-roam) (require 'ol) ;; for org-link-decode +(defcustom org-roam-protocol-store-links nil + "Whether to store links when capturing websites with `org-roam-protocol'." + :type 'boolean + :group 'org-roam) + ;;;; Functions (defun org-roam-protocol-open-ref (info) "Process an org-protocol://roam-ref?ref= style url with INFO. @@ -46,7 +51,7 @@ It opens or creates a note with the given ref. javascript:location.href = \\='org-protocol://roam-ref?template=r&ref=\\='+ \\ - encodeURIComponent(location.href) + \\='&title=\\=' \\ + encodeURIComponent(location.href) + \\='&title=\\=' + \\ encodeURIComponent(document.title) + \\='&body=\\=' + \\ encodeURIComponent(window.getSelection())" (when-let* ((alist (org-roam--plist-to-alist info)) @@ -58,6 +63,20 @@ It opens or creates a note with the given ref. (error "No ref key provided")) (when-let ((title (cdr (assoc 'title decoded-alist)))) (push (cons 'slug (funcall org-roam-title-to-slug-function title)) decoded-alist)) + (let-alist decoded-alist + (let* ((ref (org-protocol-sanitize-uri .ref)) + (type (and (string-match "^\\([a-z]+\\):" ref) + (match-string 1 ref))) + (title (or .title "")) + (body (or .body "")) + (orglink + (org-link-make-string ref (or (org-string-nw-p title) ref)))) + (when org-roam-protocol-store-links + (push (list ref title) org-stored-links)) + (org-link-store-props :type type + :link ref + :annotation orglink + :initial body))) (let* ((org-roam-capture-templates org-roam-capture-ref-templates) (org-roam-capture--context 'ref) (org-roam-capture--info decoded-alist)