Skip to content

Commit

Permalink
feat: download images from logseq server
Browse files Browse the repository at this point in the history
  • Loading branch information
llcc committed Apr 3, 2021
1 parent 73730b2 commit feba4fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Org-logseq supports to open [[https://github.com/logseq/logseq][logseq]]-style l
+ Display logseq block references in buffer as overlays:
- =((6064f6c6-440a-46ca-b8df-59131adab5a1))= to =[[id:6064f6c6-440a-46ca-b8df-59131adab5a1][Block heading]]=
- ={{embed ((6064f6c6-440a-46ca-b8df-59131adab5a1))}}= to the content of the referred block.
+ Download images stored in the logseq server to local.

* Installation

Expand Down
15 changes: 15 additions & 0 deletions org-logseq.el
Original file line number Diff line number Diff line change
Expand Up @@ -486,5 +486,20 @@ object (e.g., within a comment). In these case, you need to use
(org-logseq-activate)
(org-logseq-deactivate)))

(defun org-logseq-download-images ()
(interactive)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "https://cdn.logseq.com" nil t)
(let* ((context (org-element-context)))
(when (eq (car context) 'link)
(let ((link-begin (org-element-property :begin context))
(link-end (org-element-property :end context))
(path (org-element-property :raw-link context))
(image-path (concat "images/"
(make-temp-name "org-logseq-") (format-time-string "-%Y%m%d.png"))))
(start-process "org logseq" nil "curl" path "--output" image-path)
(setf (buffer-substring link-begin link-end) (format "[[./%s]]" image-path))))))))

(provide 'org-logseq)
;;; org-logseq.el ends here

0 comments on commit feba4fd

Please sign in to comment.