Rename library to org-roam-export-backlinks

The old name conflicts with a module added to org-roam.
This commit is contained in:
Correl Roush 2022-10-29 00:54:27 -04:00
parent e0b67c4396
commit 3faf4382e3
2 changed files with 32 additions and 32 deletions

View file

@ -1,12 +1,12 @@
;;; org-roam-export.el --- Description -*- lexical-binding: t; -*- ;;; org-roam-export-backlinks.el --- Include backlinks in exported org documents -*- lexical-binding: t; -*-
;; ;;
;; Copyright (C) 2022 Correl Roush ;; Copyright (C) 2022 Correl Roush
;; ;;
;; Author: Correl Roush <correl@gmail.com> ;; Author: Correl Roush <correl@gmail.com>
;; Maintainer: Correl Roush <correl@gmail.com> ;; Maintainer: Correl Roush <correl@gmail.com>
;; Created: June 10, 2022 ;; Created: June 10, 2022
;; Modified: June 10, 2022 ;; Modified: October 29, 2022
;; Version: 0.0.1 ;; Version: 0.0.2
;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp ;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp
;; Homepage: https://github.com/correlr/org-roam-export ;; Homepage: https://github.com/correlr/org-roam-export
;; Package-Requires: ((emacs "25.1") (org-roam "2.2.1")) ;; Package-Requires: ((emacs "25.1") (org-roam "2.2.1"))
@ -21,7 +21,7 @@
(require 'org-roam) (require 'org-roam)
(defun org-roam-export-backlink-title (backlink) (defun org-roam-export-backlinks-title (backlink)
"Get exportable title of BACKLINK." "Get exportable title of BACKLINK."
(mapconcat #'identity (mapconcat #'identity
(append (append
@ -29,11 +29,11 @@
(plist-get (org-roam-backlink-properties backlink) :outline)) (plist-get (org-roam-backlink-properties backlink) :outline))
" > ")) " > "))
(defun org-roam-export-backlink-link (backlink) (defun org-roam-export-backlinks-link (backlink)
"Get Org link to BACKLINK." "Get Org link to BACKLINK."
(concat "id:" (org-roam-node-id (org-roam-backlink-source-node backlink)))) (concat "id:" (org-roam-node-id (org-roam-backlink-source-node backlink))))
(defun org-roam-export--excerpt (&optional buffer element) (defun org-roam-export-backlinks--excerpt (&optional buffer element)
"Extract an excerpt from ELEMENT in BUFFER." "Extract an excerpt from ELEMENT in BUFFER."
(with-current-buffer (or buffer (current-buffer)) (with-current-buffer (or buffer (current-buffer))
(let ((element (or element (org-element-at-point)))) (let ((element (or element (org-element-at-point))))
@ -45,14 +45,14 @@
(buffer-substring begin end) (buffer-substring begin end)
""))))) "")))))
(defun org-roam-export-backlink-excerpt (backlink) (defun org-roam-export-backlinks-excerpt (backlink)
"Get the Org element containing the link from BACKLINK as an excerpt." "Get the Org element containing the link from BACKLINK as an excerpt."
(with-temp-buffer (with-temp-buffer
(insert-file-contents (org-roam-node-file (org-roam-backlink-source-node backlink))) (insert-file-contents (org-roam-node-file (org-roam-backlink-source-node backlink)))
(goto-char (org-roam-backlink-point backlink)) (goto-char (org-roam-backlink-point backlink))
(org-roam-export--excerpt))) (org-roam-export-backlinks--excerpt)))
(defun org-roam-export--format-backlink (link title excerpt) (defun org-roam-export-backlinks--format (link title excerpt)
"Format a backlink with TITLE and EXCERPT for inclusion in an Org document." "Format a backlink with TITLE and EXCERPT for inclusion in an Org document."
(with-temp-buffer (with-temp-buffer
(org-mode) (org-mode)
@ -61,14 +61,14 @@
(insert excerpt)) (insert excerpt))
(buffer-string))) (buffer-string)))
(defun org-roam-export-format-backlink (backlink) (defun org-roam-export-backlinks-format (backlink)
"Format a BACKLINK for inclusion in an Org document." "Format a BACKLINK for inclusion in an Org document."
(org-roam-export--format-backlink (org-roam-export-backlinks--format
(org-roam-export-backlink-link backlink) (org-roam-export-backlinks-link backlink)
(org-roam-export-backlink-title backlink) (org-roam-export-backlinks-title backlink)
(org-roam-export-backlink-excerpt backlink))) (org-roam-export-backlinks-excerpt backlink)))
(defun org-roam-export-preprocessor (backend) (defun org-roam-export-backlinks-preprocessor (backend)
"Append org-roam backlinks with content when applicable before "Append org-roam backlinks with content when applicable before
passing to the org export BACKEND." passing to the org export BACKEND."
(when-let ((node (org-roam-node-at-point))) (when-let ((node (org-roam-node-at-point)))
@ -77,7 +77,7 @@ passing to the org export BACKEND."
(save-excursion (save-excursion
(goto-char (point-max)) (goto-char (point-max))
(insert (concat "\n* Backlinks\n" (insert (concat "\n* Backlinks\n"
(string-join (mapcar #'org-roam-export-format-backlink backlinks))))))))) (string-join (mapcar #'org-roam-export-backlinks-format backlinks)))))))))
(provide 'org-roam-export) (provide 'org-roam-export-backlinks)
;;; org-roam-export.el ends here ;;; org-roam-export-backlinks.el ends here

View file

@ -12,7 +12,7 @@
(require 'ert) (require 'ert)
(require 'org-roam) (require 'org-roam)
(require 'org-roam-export) (require 'org-roam-export-backlinks)
(setq org-roam-directory (expand-file-name "./test-slipbox") (setq org-roam-directory (expand-file-name "./test-slipbox")
org-roam-db-location (expand-file-name "./test-slipbox/org-roam.db")) org-roam-db-location (expand-file-name "./test-slipbox/org-roam.db"))
@ -22,19 +22,19 @@
(ert-deftest lorem-backlink-titles () (ert-deftest lorem-backlink-titles ()
(should (equal '("Ipsum > II") (should (equal '("Ipsum > II")
(mapcar #'org-roam-export-backlink-title (org-roam-backlinks-get (org-roam-node-from-id "d12a1ce4-3199-42f4-b39b-b68c03458669") :unique t))))) (mapcar #'org-roam-export-backlinks-title (org-roam-backlinks-get (org-roam-node-from-id "d12a1ce4-3199-42f4-b39b-b68c03458669") :unique t)))))
(ert-deftest ipsum-backlink-titles () (ert-deftest ipsum-backlink-titles ()
(should (equal '("Lorem") (should (equal '("Lorem")
(mapcar #'org-roam-export-backlink-title (org-roam-backlinks-get (org-roam-node-from-id "e6c17c1a-6b05-40d2-a01f-b147633c51b1") :unique t))))) (mapcar #'org-roam-export-backlinks-title (org-roam-backlinks-get (org-roam-node-from-id "e6c17c1a-6b05-40d2-a01f-b147633c51b1") :unique t)))))
(ert-deftest lorem-backlink-link () (ert-deftest lorem-backlink-link ()
(should (equal '("id:e6c17c1a-6b05-40d2-a01f-b147633c51b1") (should (equal '("id:e6c17c1a-6b05-40d2-a01f-b147633c51b1")
(mapcar #'org-roam-export-backlink-link (org-roam-backlinks-get (org-roam-node-from-id "d12a1ce4-3199-42f4-b39b-b68c03458669") :unique t))))) (mapcar #'org-roam-export-backlinks-link (org-roam-backlinks-get (org-roam-node-from-id "d12a1ce4-3199-42f4-b39b-b68c03458669") :unique t)))))
(ert-deftest ipsum-backlink-link () (ert-deftest ipsum-backlink-link ()
(should (equal '("id:d12a1ce4-3199-42f4-b39b-b68c03458669") (should (equal '("id:d12a1ce4-3199-42f4-b39b-b68c03458669")
(mapcar #'org-roam-export-backlink-link (org-roam-backlinks-get (org-roam-node-from-id "e6c17c1a-6b05-40d2-a01f-b147633c51b1") :unique t))))) (mapcar #'org-roam-export-backlinks-link (org-roam-backlinks-get (org-roam-node-from-id "e6c17c1a-6b05-40d2-a01f-b147633c51b1") :unique t)))))
(defmacro with-test-document (&rest body) (defmacro with-test-document (&rest body)
`(with-temp-buffer `(with-temp-buffer
@ -64,17 +64,17 @@ Opening paragraph.
(ert-deftest excerpt-opening-paragraph-test () (ert-deftest excerpt-opening-paragraph-test ()
(with-test-document (with-test-document
(goto-line 6) (goto-line 6)
(should (equal "Opening paragraph.\n" (org-roam-export--excerpt))))) (should (equal "Opening paragraph.\n" (org-roam-export-backlinks--excerpt)))))
(ert-deftest excerpt-heading-paragraph-test () (ert-deftest excerpt-heading-paragraph-test ()
(with-test-document (with-test-document
(goto-line 10) (goto-line 10)
(should (equal " Heading one paragraph.\n" (org-roam-export--excerpt))))) (should (equal " Heading one paragraph.\n" (org-roam-export-backlinks--excerpt)))))
(ert-deftest excerpt-list-test () (ert-deftest excerpt-list-test ()
(with-test-document (with-test-document
(goto-line 14) (goto-line 14)
(should (equal " - List item 1\n - List item 2\n" (org-roam-export--excerpt))))) (should (equal " - List item 1\n - List item 2\n" (org-roam-export-backlinks--excerpt)))))
(ert-deftest excerpt-heading-with-subheadings-test () (ert-deftest excerpt-heading-with-subheadings-test ()
(with-test-document (with-test-document
@ -88,12 +88,12 @@ Opening paragraph.
- List item 1 - List item 1
- List item 2 - List item 2
" (org-roam-export--excerpt))))) " (org-roam-export-backlinks--excerpt)))))
(ert-deftest excerpt-simple-heading-test () (ert-deftest excerpt-simple-heading-test ()
(with-test-document (with-test-document
(goto-line 17) (goto-line 17)
(should (equal "* Heading Two\n\n Heading two paragraph.\n" (org-roam-export--excerpt))))) (should (equal "* Heading Two\n\n Heading two paragraph.\n" (org-roam-export-backlinks--excerpt)))))
(ert-deftest lorem-backlink-excerpt () (ert-deftest lorem-backlink-excerpt ()
(should (equal '("Aliquam [[id:d12a1ce4-3199-42f4-b39b-b68c03458669][lorem]] ante, suscipit a lorem molestie, aliquet elementum eros. Proin (should (equal '("Aliquam [[id:d12a1ce4-3199-42f4-b39b-b68c03458669][lorem]] ante, suscipit a lorem molestie, aliquet elementum eros. Proin
@ -106,7 +106,7 @@ commodo, lacinia odio vitae, blandit metus. Nam et tempus ipsum. Aenean lobortis
mauris sit amet lorem accumsan blandit. Fusce eleifend, tellus non tristique mauris sit amet lorem accumsan blandit. Fusce eleifend, tellus non tristique
auctor, ligula justo varius dolor, id bibendum nulla elit ac dui. Vestibulum auctor, ligula justo varius dolor, id bibendum nulla elit ac dui. Vestibulum
sodales enim eget tristique tempor.\n") sodales enim eget tristique tempor.\n")
(mapcar #'org-roam-export-backlink-excerpt (org-roam-backlinks-get (org-roam-node-from-id "d12a1ce4-3199-42f4-b39b-b68c03458669") :unique t))))) (mapcar #'org-roam-export-backlinks-excerpt (org-roam-backlinks-get (org-roam-node-from-id "d12a1ce4-3199-42f4-b39b-b68c03458669") :unique t)))))
(ert-deftest ipsum-backlink-excerpt () (ert-deftest ipsum-backlink-excerpt ()
(should (equal '("Lorem [[id:e6c17c1a-6b05-40d2-a01f-b147633c51b1][ipsum]] dolor sit amet, consectetur adipiscing elit. Mauris eget viverra mi. (should (equal '("Lorem [[id:e6c17c1a-6b05-40d2-a01f-b147633c51b1][ipsum]] dolor sit amet, consectetur adipiscing elit. Mauris eget viverra mi.
@ -116,14 +116,14 @@ Morbi id malesuada nisi. Praesent ipsum velit, commodo vel bibendum vitae,
dignissim in magna. Pellentesque vehicula enim ante, interdum laoreet dolor dignissim in magna. Pellentesque vehicula enim ante, interdum laoreet dolor
venenatis eget. Proin laoreet nulla a enim bibendum finibus. Proin mattis venenatis eget. Proin laoreet nulla a enim bibendum finibus. Proin mattis
lobortis quam non eleifend. Pellentesque vitae imperdiet nisl.\n") lobortis quam non eleifend. Pellentesque vitae imperdiet nisl.\n")
(mapcar #'org-roam-export-backlink-excerpt (org-roam-backlinks-get (org-roam-node-from-id "e6c17c1a-6b05-40d2-a01f-b147633c51b1") :unique t))))) (mapcar #'org-roam-export-backlinks-excerpt (org-roam-backlinks-get (org-roam-node-from-id "e6c17c1a-6b05-40d2-a01f-b147633c51b1") :unique t)))))
(ert-deftest format-backlink-test () (ert-deftest format-backlink-test ()
(should (equal "** [[id:34cf17c6-f804-4adb-b386-3c6dfb83cfad][Heading > Subheading]] (should (equal "** [[id:34cf17c6-f804-4adb-b386-3c6dfb83cfad][Heading > Subheading]]
Paragraph text. Paragraph text.
" "
(org-roam-export--format-backlink (org-roam-export-backlinks--format
"id:34cf17c6-f804-4adb-b386-3c6dfb83cfad" "id:34cf17c6-f804-4adb-b386-3c6dfb83cfad"
"Heading > Subheading" "Heading > Subheading"
"Paragraph text.\n")))) "Paragraph text.\n"))))
@ -141,7 +141,7 @@ Paragraph text.
Paragraph text. Paragraph text.
" "
(org-roam-export--format-backlink (org-roam-export-backlinks--format
"id:9428184d-5030-4e5b-91f6-b865d5cc311b" "id:9428184d-5030-4e5b-91f6-b865d5cc311b"
"Heading" "Heading"
"** Subheading One "** Subheading One