(defun hexo-deploy (dir) "Deploy hexo site. If called with a prefix argument, the user is asked for directory of the site. Otherwise, the directory is guessed from `default-directory'." (interactive (list (if current-prefix-arg (file-name-as-directory (read-directory-name"Hexo site directory: " default-directory)) default-directory))) (let ((old-dir default-directory)) (if (file-exists-p (concat dir "db.json")) (progn (setq default-directory dir) (start-process"hexo-deploy""*Hexo Deploy Output*""hexo""d""-g") (setq default-directory old-dir)) (progn (if (file-exists-p (expand-file-name (concat old-dir "../../db.json"))) (progn (setq default-directory (expand-file-name (concat old-dir "../../"))) (start-process"hexo-deploy" "*Hexo Deploy Output*""hexo""d""-g") (setq default-directory old-dir)) (error"Hexo deploy failed. Wrong directory?"))))))
(defun hexo-wait-and-visit (proc max) "Use timer to wait hexo process finish then visit the created file." (if (eq (process-status proc) 'exit) ;; Exit normally. (let ((hexo-buffer (process-buffer proc))) (set-buffer hexo-buffer) (goto-char (point-min)) (if (search-forward"File created at "nilt1) (progn (find-file (buffer-substring-no-properties (point) (line-end-position))) (kill-buffer hexo-buffer)))) (when (< max 5) (run-with-timer1nil `(lambda () (funcall 'hexo-wait-and-visit ,proc ,(1+ max)))))))
(defun hexo-new (dir type title) "Create an hexo draft/page/photo/post/. If called with a prefix argument, the user is asked for type of the created item. By default, `tpye' is post." (interactive (list (file-name-as-directory (read-directory-name"Hexo site directory: " default-directory)) (if current-prefix-arg (read-string"Type to create: ""post"nil"post") "post") (read-string"title: "))) (let ((old-dir default-directory)) (if (and (file-exists-p (concat dir "db.json")) title) (progn (setq default-directory dir) (hexo-wait-and-visit (start-process"hexo-new""*Hexo New Output*""hexo""n" type title) 0) (setq default-directory old-dir) ) (error"Input directory is wrong."))))