(bugfix): keep unicode alphanumerics in filename (#164)

Ref #158

Example output:
    (mapcar #'org-roam--title-to-slug
            '("!!!!Org-Roam is great!!!!"
              "Sobre a formação dos planetas"
              "1\\2.3///**"
              "10-2+3=45"))
    ;; ("org_roam_is_great" "sobre_a_formação_dos_planetas" "1_2_3" "10_2_3_45")
This commit is contained in:
Herbert Jones
2020-02-22 10:53:16 -06:00
committed by GitHub
parent c2c25f7d83
commit d2843b816f

View File

@@ -235,11 +235,14 @@ If `ABSOLUTE', return an absolute file-path. Else, return a relative file-path."
(defun org-roam--title-to-slug (title) (defun org-roam--title-to-slug (title)
"Convert TITLE to a filename-suitable slug." "Convert TITLE to a filename-suitable slug."
(let* ((s (s-downcase title)) (cl-flet ((replace (title pair)
(s (replace-regexp-in-string "[^a-zA-Z0-9_ ]" "" s)) (replace-regexp-in-string (car pair) (cdr pair) title)))
(s (s-split " " s)) (let* ((pairs `(("[^[:alnum:][:digit:]]" . "_") ;; convert anything not alphanumeric
(s (s-join "_" s))) ("__*" . "_") ;; remove sequential underscores
s)) ("^_" . "") ;; remove starting underscore
("_$" . ""))) ;; remove ending underscore
(slug (-reduce-from #'replace title pairs)))
(s-downcase slug))))
(defun org-roam--file-name-timestamp-title (title) (defun org-roam--file-name-timestamp-title (title)
"Return a file name (without extension) for new files. "Return a file name (without extension) for new files.