Forked from daviderestivo/drestivo-org-download-method.el
Created
December 21, 2018 00:33
-
-
Save rfelix/cacc68a5b1a1296db82f8813865573cf to your computer and use it in GitHub Desktop.
This is an helper function for org-download. It creates an \"./image\" folder within the same directory of the org file. Images are separated inside that image folder by additional folders one per org file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun drestivo/org-download-method (link) | |
"This is an helper function for org-download. | |
It creates an \"./image\" folder within the same directory of the org file. | |
Images are separated inside that image folder by additional folders one per | |
org file. | |
More info can be found here: https://github.com/abo-abo/org-download/issues/40. | |
See the commit message for an example: | |
https://github.com/abo-abo/org-download/commit/137c3d2aa083283a3fc853f9ecbbc03039bf397b" | |
(let ((filename | |
(file-name-nondirectory | |
(car (url-path-and-query | |
(url-generic-parse-url link))))) | |
(dir (concat | |
(file-name-directory (buffer-file-name)) | |
(format "%s/%s/%s" | |
"images" | |
(file-name-base (buffer-file-name)) | |
(org-download--dir-2))))) | |
(progn | |
(setq filename-with-timestamp (format "%s%s.%s" | |
(file-name-sans-extension filename) | |
(format-time-string org-download-timestamp) | |
(file-name-extension filename))) | |
;; Check if directory exists otherwise creates it | |
(unless (file-exists-p dir) | |
(make-directory dir t)) | |
(message (format "Image: %s saved!" (expand-file-name filename-with-timestamp dir))) | |
(expand-file-name filename-with-timestamp dir)))) | |
(setq org-download-method 'drestivo/org-download-method) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment