This article has been deprecated. Because now I have rewritten all following functions and do more & more jobs as a real major-mode in kuanyui/hexo.el. If you want to use Hexo in Emacs, please take a look of that. Any update in future will be pushed onto that repositor
(defun hexo-new () "Call `hexo new` anywhere as long as in any child directory under a Hexo repository. That's to say, you can use this function to create new post, even though under theme/default/layout/" (interactive) (let* (BUFFER-STRING OUTPUT (DEF-DIR (if (boundp 'DEF-DIR) DEF-DIR default-directory))) (if (file-exists-p (format"%s%s" DEF-DIR "_config.yml")) (progn (with-temp-buffer (insert-file-contents (format"%s%s" DEF-DIR "_config.yml")) (setq BUFFER-STRING (buffer-string))) (if (and (string-match"title: " BUFFER-STRING) (string-match"url: " BUFFER-STRING) (string-match"new_post_name: " BUFFER-STRING)) ;; call `hexo new` command (let ((default-directory DEF-DIR)) (setq OUTPUT (shell-command-to-string (concat"hexo new '" (read-from-minibuffer "Title of the new article: ") "'"))) (string-match"/.*\\.md$" OUTPUT) (find-file (match-string0 OUTPUT))) (progn (setq DEF-DIR (file-truename (concat DEF-DIR "../"))) (hexo-new)))) (progn (if (not (equal DEF-DIR "/")) (progn (setq DEF-DIR (file-truename (concat DEF-DIR "../"))) (hexo-new)) (progn (message"Not in a hexo or its child directory.")))))))
(defun hexo-move-article () "Move current file between _post and _draft; You can run this function in dired or a hexo article." (interactive) (if (string-match"/\\(_posts/\\|_drafts/\\)$" default-directory) (let* ((parent-dir (file-truename (concat default-directory "../"))) (dest-dir (if (string-match"_drafts/$" default-directory) "_posts/""_drafts/"))) (cond ((eq major-mode 'markdown-mode) (let* ((cur-file (buffer-file-name)) (new-file (concat parent-dir dest-dir (buffer-name)))) (save-buffer) (kill-buffer) (rename-file cur-file new-file) (find-file new-file) (message (format"Now in %s" dest-dir)))) ((eq major-mode 'dired-mode) (dired-rename-file (dired-get-filenamenil) (concat parent-dir dest-dir (dired-get-filenamet)) nil) (message (format"The article has been moved to %s" dest-dir))))) (message"You have to run this in a hexo article buffer or dired")))
(defun hexo-update-current-article-date () "Update article's date by current time. Please run this function in the article." (interactive) (save-excursion (goto-char (point-min)) (save-match-data (if (re-search-forward"^date: [0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}"nil:no-error) (let ((current-time (format-time-string"date: %Y-%m-%d %H:%M:%S"))) (replace-match current-time) (save-buffer) (message (concat"Date updated: " current-time))) (message"Didn't find any time stamp in this article, abort.")))))