coldnew / hexo-renderer-org

Hexo renderer plugin for emacs org-mode
GNU General Public License v3.0
165 stars 38 forks source link

Define custom links #49

Open MephistoMMM opened 7 years ago

MephistoMMM commented 7 years ago

I defined a custom link (img) in my spacemacs layer :

(defun mp-org/custom-link-img-follow (path)
  "Click event of custom link img."
  (org-open-file-with-emacs path)
   )

(defun mp-org/custom-link-img-export (path desc format)
  "export event of custom link img."
  (cond
   ((eq format 'html)
    ;; concat custom img host and final two section of the path
    (message path)
    (let (uri-slices slices-len url)
         (setq uri-slices (split-string path "/"))
         (setq slices-len (length uri-slices))
         (setq url (if (< slices-len 2)
                    (concat custom-link-img-export-host "/" (car uri-slices))
                    (concat custom-link-img-export-host "/"
                    (nth (- slices-len 2) uri-slices) "/"
                    (nth (- slices-len 1) uri-slices))))
      (message (url-encode-url url))
      (format "<img src=\"%s\" alt=\"%s\"/>" (url-encode-url url) desc))))
  )

 (org-add-link-type "img" 'mp-org/custom-link-img-follow 'mp-org/custom-link-img-export)

It looks like following in org buffers:

[[img:../../../../Dropbox/org/statics/1473343845-django-asgi-websockets_2017-03-14_16-49-55.png]]

Maybe it need a customlinks (or pre) item in config file whose value is the string of elisp codes.

frapples commented 6 years ago

You can try the config item export_cfg . Its default value is:

(progn
   (package-initialize)
   (require 'org) 
   (require 'org-clock)
    (require 'ox))

This code is run when hexo-renderer-org starts emacs rendering. You can modify it to join your personalized configuration.