Fix hugo-compile so it works again

This commit is contained in:
MitchMarq42 2023-02-06 15:35:09 -09:00
parent 3d0ea8fedb
commit 6353891e14

View File

@ -671,25 +671,35 @@ See https://emacs.stackexchange.com/questions/2538/how-to-define-additional-mode
(defun hugo-dir-above (dir) (defun hugo-dir-above (dir)
"Return path of Hugo project root above or at DIR. "Return path of Hugo project root above or at DIR.
Return nil if DIR is not in a hugo project at all." Return nil if DIR is not in a hugo project at all."
(named-let hda-internal ((dir dir)) (require 'subr-x)
(if (eq dir nil) nil (let ((thisdir dir))
(if (file-exists-p (expand-file-name "config.toml" dir)) dir (let ((lexical-binding t))
(hda-internal (file-name-directory (string-trim-right dir "/"))))))) (if (eq thisdir nil) nil
(defun hugo-compile (dir) (if (file-exists-p (expand-file-name "config.toml" thisdir))
thisdir
(let ((updir (file-name-directory (string-trim-right thisdir "/"))))
(hugo-dir-above updir)))))))
;; (hugo-dir-above "~/.local/git/mitchmarq42.github.io/content-org/")
(defun hugo-compile (&optional dir)
(interactive)
(if (bound-and-true-p dir) nil
(setq dir default-directory))
(let ((hugo-dir (hugo-dir-above dir))) (let ((hugo-dir (hugo-dir-above dir)))
(if hugo-dir (if hugo-dir
(if (string-match-p default-directory "/content-org$") (progn
(org-hugo-export-wim-to-md-after-save) (if (string-match-p (rx bol (* any) "/content-org" (opt "/") eol)
default-directory)
(org-hugo-export-wim-to-md-after-save))
(let* ((default-directory hugo-dir) (let* ((default-directory hugo-dir)
(buffer (get-buffer-create "*hugo*"))) (buffer (get-buffer-create "*hugo*")))
(with-current-buffer buffer (with-current-buffer buffer
(compilation-mode) ;; (compilation-mode)
(if (zerop (let ((inhibit-read-only t)) (let* ((inhibit-read-only t)
(shell-command "hugo" buffer))) (status-code (call-process-shell-command "hugo" nil buffer)))
(if (zerop status-code)
(message "Hugo re-generated!") (message "Hugo re-generated!")
(error "Hugo Failed, better change something!")))))))) (error "Hugo exited %s, better change something!" status-code)))))))))
(add-hook 'after-save-hook (add-hook 'after-save-hook #'hugo-compile))
(lambda () (hugo-compile default-directory))))
;; fake indentation, other than the other fake indentation ;; fake indentation, other than the other fake indentation
;; (elpaca-use-package adaptive-wrap ;; (elpaca-use-package adaptive-wrap