Skip to content

Commit

Permalink
Make hugo's binary changeable for each blog
Browse files Browse the repository at this point in the history
  • Loading branch information
masasam committed May 31, 2018
1 parent f26a5ec commit 3b0516c
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions easy-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

;; Author: Masashı Mıyaura
;; URL: https://github.com/masasam/emacs-easy-hugo
;; Version: 3.2.27
;; Version: 3.3.27
;; Package-Requires: ((emacs "24.4") (popup "0.5.3"))

;; This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -44,6 +44,11 @@
:group 'easy-hugo
:type 'string)

(defcustom easy-hugo-bin "hugo"
"Hugo binary."
:group 'easy-hugo
:type 'string)

(defcustom easy-hugo-preview-url "http://localhost:1313/"
"Preview url of easy-hugo."
:group 'easy-hugo
Expand Down Expand Up @@ -241,6 +246,7 @@ Because only two are supported by hugo."
:type 'string)

(push `((easy-hugo-basedir . ,easy-hugo-basedir)
(easy-hugo-bin . ,easy-hugo-bin)
(easy-hugo-url . ,easy-hugo-url)
(easy-hugo-root . ,easy-hugo-root)
(easy-hugo-sshdomain . ,easy-hugo-sshdomain)
Expand Down Expand Up @@ -277,6 +283,10 @@ Because only two are supported by hugo."
(make-list (length easy-hugo-bloglist) 'nil)
"Timer list for cansel google cloud storage deploy timer.")

(defconst easy-hugo--default-bin
easy-hugo-bin
"Default easy-hugo-bin.")

(defconst easy-hugo--default-github-deploy-script
easy-hugo-github-deploy-script
"Default easy-hugo github-deploy-script.")
Expand Down Expand Up @@ -337,7 +347,7 @@ Report an error if hugo is not installed, or if `easy-hugo-basedir' is unset."
`(progn
(unless easy-hugo-basedir
(error "Please set easy-hugo-basedir variable"))
(unless (executable-find "hugo")
(unless (executable-find easy-hugo-bin)
(error "'hugo' is not installed"))
(let ((default-directory easy-hugo-basedir))
,@body)))
Expand Down Expand Up @@ -573,7 +583,7 @@ Report an error if hugo is not installed, or if `easy-hugo-basedir' is unset."
(easy-hugo-with-env
(when (file-directory-p "public")
(delete-directory "public" t nil))
(let ((ret (call-process "hugo" nil "*hugo-publish*" t "--destination" "public")))
(let ((ret (call-process easy-hugo-bin nil "*hugo-publish*" t "--destination" "public")))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*hugo-publish*"))
(error "'hugo --destination public' command does not end normally")))
Expand Down Expand Up @@ -603,7 +613,7 @@ Report an error if hugo is not installed, or if `easy-hugo-basedir' is unset."
(interactive "nMinute:")
(unless easy-hugo-basedir
(error "Please set easy-hugo-basedir variable"))
(unless (executable-find "hugo")
(unless (executable-find easy-hugo-bin)
(error "'hugo' is not installed"))
(unless easy-hugo-sshdomain
(error "Please set easy-hugo-sshdomain variable"))
Expand Down Expand Up @@ -636,7 +646,7 @@ Report an error if hugo is not installed, or if `easy-hugo-basedir' is unset."
(let ((default-directory (easy-hugo-nth-eval-bloglist easy-hugo-basedir n)))
(when (file-directory-p "public")
(delete-directory "public" t nil))
(let ((ret (call-process "hugo" nil "*hugo-publish*" t "--destination" "public")))
(let ((ret (call-process easy-hugo-bin nil "*hugo-publish*" t "--destination" "public")))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*hugo-publish*"))
(setf (nth n easy-hugo--publish-timer-list) nil)
Expand Down Expand Up @@ -699,7 +709,7 @@ POST-FILE needs to have and extension '.md' or '.org' or '.ad' or '.rst' or '.mm
(error "%s already exists!" filename))
(if (and (null easy-hugo-org-header)
(<= 0.25 (easy-hugo--version)))
(call-process "hugo" nil "*hugo*" t "new"
(call-process easy-hugo-bin nil "*hugo*" t "new"
(file-relative-name filename
(expand-file-name "content" easy-hugo-basedir)))
(progn
Expand All @@ -708,7 +718,7 @@ POST-FILE needs to have and extension '.md' or '.org' or '.ad' or '.rst' or '.mm
(string-equal file-ext "rst")
(string-equal file-ext "mmark")
(string-equal file-ext easy-hugo-html-extension))
(call-process "hugo" nil "*hugo*" t "new"
(call-process easy-hugo-bin nil "*hugo*" t "new"
(file-relative-name filename
(expand-file-name "content" easy-hugo-basedir))))))
(when (get-buffer "*hugo*")
Expand All @@ -725,7 +735,7 @@ POST-FILE needs to have and extension '.md' or '.org' or '.ad' or '.rst' or '.mm
"Return the version of hugo."
(let ((source (split-string
(with-temp-buffer
(shell-command-to-string "hugo version"))
(shell-command-to-string (concat easy-hugo-bin " version")))
" ")))
(string-to-number (substring (nth 4 source) 1))))

Expand All @@ -740,9 +750,9 @@ POST-FILE needs to have and extension '.md' or '.org' or '.ad' or '.rst' or '.mm
(if (<= 0.25 (easy-hugo--version))
(setq easy-hugo--server-process
(start-process "hugo-server"
easy-hugo--preview-buffer "hugo" "server" "--navigateToChanged"))
easy-hugo--preview-buffer easy-hugo-bin "server" "--navigateToChanged"))
(setq easy-hugo--server-process
(start-process "hugo-server" easy-hugo--preview-buffer "hugo" "server")))
(start-process "hugo-server" easy-hugo--preview-buffer easy-hugo-bin "server")))
(while easy-hugo--preview-loop
(if (equal (easy-hugo--preview-status) "200")
(progn
Expand Down Expand Up @@ -945,7 +955,7 @@ to the server."
(interactive "nMinute:")
(unless easy-hugo-basedir
(error "Please set easy-hugo-basedir variable"))
(unless (executable-find "hugo")
(unless (executable-find easy-hugo-bin)
(error "'hugo' is not installed"))
(let ((deployscript (file-truename (expand-file-name
easy-hugo-github-deploy-script
Expand Down Expand Up @@ -1004,7 +1014,7 @@ to the server."
(error "Please set 'easy-hugo-amazon-s3-bucket-name' variable"))
(when (file-directory-p "public")
(delete-directory "public" t nil))
(let ((ret (call-process "hugo" nil "*hugo-amazon-s3-deploy*" t "--destination" "public")))
(let ((ret (call-process easy-hugo-bin nil "*hugo-amazon-s3-deploy*" t "--destination" "public")))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*hugo-amazon-s3-deploy*"))
(error "'hugo --destination public' command does not end normally")))
Expand All @@ -1022,7 +1032,7 @@ to the server."
(interactive "nMinute:")
(unless easy-hugo-basedir
(error "Please set easy-hugo-basedir variable"))
(unless (executable-find "hugo")
(unless (executable-find easy-hugo-bin)
(error "'hugo' is not installed"))
(unless (executable-find "aws")
(error "'aws' is not installed"))
Expand All @@ -1049,7 +1059,7 @@ to the server."
(defun easy-hugo-amazon-s3-deploy-on-timer (n)
"Deploy hugo source at Amazon S3 on timer at N."
(let* ((default-directory (easy-hugo-nth-eval-bloglist easy-hugo-basedir n))
(ret (call-process "hugo" nil "*hugo-amazon-s3-deploy*" t "--destination" "public"))
(ret (call-process easy-hugo-bin nil "*hugo-amazon-s3-deploy*" t "--destination" "public"))
(default-directory easy-hugo-basedir))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*hugo-amazon-s3-deploy*"))
Expand Down Expand Up @@ -1079,7 +1089,7 @@ to the server."
(when (file-directory-p "public")
(delete-directory "public" t nil))
(let ((ret (call-process
"hugo" nil "*hugo-google-cloud-storage-deploy*" t "--destination" "public")))
easy-hugo-bin nil "*hugo-google-cloud-storage-deploy*" t "--destination" "public")))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*hugo-google-cloud-storage-deploy*"))
(error "'hugo --destination public' command does not end normally")))
Expand All @@ -1098,7 +1108,7 @@ to the server."
(interactive "nMinute:")
(unless easy-hugo-basedir
(error "Please set easy-hugo-basedir variable"))
(unless (executable-find "hugo")
(unless (executable-find easy-hugo-bin)
(error "'hugo' is not installed"))
(unless (executable-find "gsutil")
(error "'Google Cloud SDK' is not installed"))
Expand Down Expand Up @@ -1126,7 +1136,7 @@ to the server."
"Deploy hugo source at Google Cloud Storage on timer at N."
(let* ((default-directory (easy-hugo-nth-eval-bloglist easy-hugo-basedir n))
(ret (call-process
"hugo" nil "*hugo-google-cloud-storage-deploy*" t "--destination" "public"))
easy-hugo-bin nil "*hugo-google-cloud-storage-deploy*" t "--destination" "public"))
(default-directory easy-hugo-basedir))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*hugo-google-cloud-storage-deploy*"))
Expand Down Expand Up @@ -1726,6 +1736,9 @@ Optional prefix ARG says how many lines to move; default is one line."
(easy-hugo-set-bloglist easy-hugo-sshdomain)
(easy-hugo-set-bloglist easy-hugo-amazon-s3-bucket-name)
(easy-hugo-set-bloglist easy-hugo-google-cloud-storage-bucket-name)
(if (easy-hugo-eval-bloglist easy-hugo-bin)
(easy-hugo-set-bloglist easy-hugo-bin)
(setq easy-hugo-bin easy-hugo--default-bin))
(if (easy-hugo-eval-bloglist easy-hugo-github-deploy-script)
(easy-hugo-set-bloglist easy-hugo-github-deploy-script)
(setq easy-hugo-github-deploy-script easy-hugo--default-github-deploy-script))
Expand Down Expand Up @@ -1779,6 +1792,9 @@ Optional prefix ARG says how many lines to move; default is one line."
(easy-hugo-set-bloglist easy-hugo-sshdomain)
(easy-hugo-set-bloglist easy-hugo-amazon-s3-bucket-name)
(easy-hugo-set-bloglist easy-hugo-google-cloud-storage-bucket-name)
(if (easy-hugo-eval-bloglist easy-hugo-bin)
(easy-hugo-set-bloglist easy-hugo-bin)
(setq easy-hugo-bin easy-hugo--default-bin))
(if (easy-hugo-eval-bloglist easy-hugo-github-deploy-script)
(easy-hugo-set-bloglist easy-hugo-github-deploy-script)
(setq easy-hugo-github-deploy-script easy-hugo--default-github-deploy-script))
Expand Down Expand Up @@ -1834,6 +1850,9 @@ Optional prefix ARG says how many lines to move; default is one line."
(easy-hugo-set-bloglist easy-hugo-sshdomain)
(easy-hugo-set-bloglist easy-hugo-amazon-s3-bucket-name)
(easy-hugo-set-bloglist easy-hugo-google-cloud-storage-bucket-name)
(if (easy-hugo-eval-bloglist easy-hugo-bin)
(easy-hugo-set-bloglist easy-hugo-bin)
(setq easy-hugo-bin easy-hugo--default-bin))
(if (easy-hugo-eval-bloglist easy-hugo-github-deploy-script)
(easy-hugo-set-bloglist easy-hugo-github-deploy-script)
(setq easy-hugo-github-deploy-script easy-hugo--default-github-deploy-script))
Expand Down Expand Up @@ -1988,7 +2007,7 @@ output directories whose names match REGEXP."
(error "'List draft' requires hugo 0.25 or higher"))
(let ((source (split-string
(with-temp-buffer
(let ((ret (call-process-shell-command "hugo list drafts" nil t)))
(let ((ret (call-process-shell-command (concat easy-hugo-bin " list drafts") nil t)))
(unless (zerop ret)
(error "'Hugo list drafts' command does not end normally"))
(buffer-string)))
Expand Down

0 comments on commit 3b0516c

Please sign in to comment.