Skip to content

Commit

Permalink
Add hexo-insert-file-link
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanyui committed Apr 17, 2016
1 parent 64be582 commit a69f93e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The following commands are only available in ~markdown-mode~
| Command | Description |
|------------------------------------+------------------------------------------------------------------------------------|
| ~hexo-insert-article-link~ | Insert a link to specific article in ~_posts/~. |
| ~hexo-insert-file-link~ | Insert a link to file. (not article) |
| ~hexo-update-current-article-date~ | Update article's date stamp by current time. *This may change its permanent link!* |
| ~hexo-follow-post-link~ | Open the article file link under the cursor. <ex> ~[Hello](/2016/05/hello/)~ |

Expand Down
24 changes: 24 additions & 0 deletions hexo.el
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,30 @@ Return absolute path of the article file."
(read-from-minibuffer "Title: "))
permalink)))))

;;;###autoload
(defun hexo-insert-file-link ()
"Insert the link toward the files in source/ ,
exclude _posts/ & _drafts/"
(interactive)
(if (or (not (eq major-mode 'markdown-mode))
(not (hexo-find-root-dir))
(not (member (hexo-get-article-parent-dir-name (buffer-file-name)) '("_posts" "_drafts"))))
(message "This command only usable in a hexo article buffer (markdown).")
(let* ((source-dir-fullpath (concat (hexo-find-root-dir) "source/"))
(file-fullpath (file-truename ;[FIXME] Fucking useless ido-read-file-name
(ido-read-file-name "Input file path: "
source-dir-fullpath
nil
t
nil
(lambda (x) (not (or (string-match "_posts/" x)
(string-match "_drafts/" x)))))))
(file-link (substring file-fullpath (1- (length source-dir-fullpath))))
(text (file-name-nondirectory file-fullpath)))
(insert (ido-completing-read "Select one to insert: "
(list (format "[%s](%s)" text file-link)
file-link))))))

;;;###autoload
(defun hexo-follow-post-link ()
"`find-file' a markdown format link.
Expand Down

0 comments on commit a69f93e

Please sign in to comment.