(feat): add customizable org-roam-title-to-slug-function (#833)

Co-authored-by: Jethro Kuan <jethrokuan95@gmail.com>
This commit is contained in:
Zachary
2020-06-17 14:58:11 +08:00
committed by GitHub
parent 04d335cc40
commit 1276e801c0
4 changed files with 12 additions and 7 deletions

View File

@ -6,7 +6,7 @@
### Features
- [#814] Implement `org-roam-insert-immediate`
- [#833](https://github.com/org-roam/org-roam/pull/833) Add customization of file titles with `org-roam-title-to-slug-function`.
### Bugfixes
## 1.2.0 (12-06-2020)

View File

@ -39,12 +39,12 @@
(defvar org-roam-encrypt-files)
(defvar org-roam-directory)
(defvar org-roam-mode)
(defvar org-roam-title-to-slug-function)
(declare-function org-roam--get-title-path-completions "org-roam")
(declare-function org-roam--get-ref-path-completions "org-roam")
(declare-function org-roam--file-path-from-id "org-roam")
(declare-function org-roam--find-file "org-roam")
(declare-function org-roam--format-link "org-roam")
(declare-function org-roam--title-to-slug "org-roam")
(declare-function org-roam-mode "org-roam")
(declare-function org-roam-completion--completing-read "org-roam-completion")
@ -349,7 +349,7 @@ This uses the templates defined at `org-roam-capture-templates'."
(title (or (plist-get res :title) title-with-keys))
(file-path (plist-get res :path)))
(let ((org-roam-capture--info (list (cons 'title title)
(cons 'slug (org-roam--title-to-slug title))
(cons 'slug (funcall org-roam-title-to-slug-function title))
(cons 'file file-path)))
(org-roam-capture--context 'capture))
(setq org-roam-capture-additional-template-props (list :capture-fn 'org-roam-capture))

View File

@ -56,7 +56,7 @@ It opens or creates a note with the given ref.
(unless (assoc 'ref decoded-alist)
(error "No ref key provided"))
(when-let ((title (cdr (assoc 'title decoded-alist))))
(push (cons 'slug (org-roam--title-to-slug title)) decoded-alist))
(push (cons 'slug (funcall org-roam-title-to-slug-function title)) decoded-alist))
(let* ((org-roam-capture-templates org-roam-capture-ref-templates)
(org-roam-capture--context 'ref)
(org-roam-capture--info decoded-alist)

View File

@ -70,7 +70,6 @@
(defvar org-id-link-to-org-use-id)
(declare-function org-id-find-id-in-file "ext:org-id" (id file &optional markerp))
;;;; Customizable variables
(defgroup org-roam nil
"Roam Research replica in Org-mode."
@ -208,6 +207,12 @@ extraction methods:
(const :tag "sub-directories" all-directories)
(const :tag "parent directory" last-directory)))
(defcustom org-roam-title-to-slug-function #'org-roam--title-to-slug
"Function to be used in converting a title to the filename slug.
Function should return a filename string based on title."
:type 'function
:group 'org-roam)
(defcustom org-roam-title-sources '((title headline) alias)
"The list of sources from which to retrieve a note title.
Each element in the list is either:
@ -1297,7 +1302,7 @@ which takes as its argument an alist of path-completions. See
(if file-path
(org-roam--find-file file-path)
(let ((org-roam-capture--info `((title . ,title-with-tags)
(slug . ,(org-roam--title-to-slug title-with-tags))))
(slug . ,(funcall org-roam-title-to-slug-function title-with-tags))))
(org-roam-capture--context 'title))
(add-hook 'org-capture-after-finalize-hook #'org-roam-capture--find-file-h)
(org-roam--with-template-error 'org-roam-capture-templates
@ -1372,7 +1377,7 @@ If DESCRIPTION is provided, use this as the link label. See
(when (org-roam-capture--in-process-p)
(user-error "Nested Org-roam capture processes not supported"))
(let ((org-roam-capture--info `((title . ,title-with-tags)
(slug . ,(org-roam--title-to-slug title-with-tags))))
(slug . ,(funcall org-roam-title-to-slug-function title-with-tags))))
(org-roam-capture--context 'title))
(add-hook 'org-capture-after-finalize-hook #'org-roam-capture--insert-link-h)
(setq org-roam-capture-additional-template-props (list :region region