Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jubnzv/7af1c4bdb504a980e0ea31e8ae138371 to your computer and use it in GitHub Desktop.
Save jubnzv/7af1c4bdb504a980e0ea31e8ae138371 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.
(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