Hugo recompile on save

This commit is contained in:
MitchMarq42 2022-11-23 11:08:29 -09:00
parent 3c91283f03
commit 102c4d447f

View File

@ -657,11 +657,19 @@ Return nil if DIR is not in a hugo project at all."
(if (eq dir nil) nil (if (eq dir nil) nil
(if (file-exists-p (expand-file-name "config.toml" dir)) dir (if (file-exists-p (expand-file-name "config.toml" dir)) dir
(hugo-dir-above (file-name-directory (string-trim-right dir "/")))))) (hugo-dir-above (file-name-directory (string-trim-right dir "/"))))))
(add-hook 'after-save-hook (defun hugo-compile (dir)
(lambda () (let ((hugo-dir (hugo-dir-above default-directory))) (let ((hugo-dir (hugo-dir-above dir)))
(if hugo-dir (if hugo-dir
(let ((default-directory hugo-dir)) (let* ((default-directory hugo-dir)
(shell-command "hugo"))))))) (buffer (get-buffer-create "*hugo*")))
(pop-to-buffer buffer)
(compilation-mode)
(if (zerop (let ((inhibit-read-only t))
(call-process "sh" nil buffer t "-c" "hugo")))
(message "Hugo re-generated!")
(error "Hugo Failed, better change something!"))))))
(add-hook 'after-save-hook
(lambda () (hugo-compile default-directory))))
;; fake indentation, other than the other fake indentation ;; fake indentation, other than the other fake indentation
(use-package adaptive-wrap (use-package adaptive-wrap