Browse Source

Hugo server helper + rewrote goto-draft

Hugo's `list drafts` was turned into a list. Rewrote the fetcher
function to clean the output and keep only the filename.
Florian Dormont 2 years ago
parent
commit
8611111f6e
1 changed files with 16 additions and 5 deletions
  1. 16 5
      config.org

+ 16 - 5
config.org

@@ -613,6 +613,13 @@ into markdown files.
 Now I'll just enjoy the blog writing from a [[https://gohugo.io][Hugo]]-powered blog git repo. The v4
 Now I'll just enjoy the blog writing from a [[https://gohugo.io][Hugo]]-powered blog git repo. The v4
 is out for a few weeks now and I feel content with the workflow I'm having with
 is out for a few weeks now and I feel content with the workflow I'm having with
 it right now. But /we can do better/.
 it right now. But /we can do better/.
+** Run Hugo in current project
+#+begin_src emacs-lisp
+(defun chicken/run-hugo-in-project ()
+  (interactive)
+  (let ((default-directory (projectile-project-root)))
+    (start-process "Hugo" "+hugo+" "hugo" "serve" "-D")))
+#+end_src
 ** Draft jump list
 ** Draft jump list
 Hugo has a few utilities, notably listing draft posts. I wrote a while ago a
 Hugo has a few utilities, notably listing draft posts. I wrote a while ago a
 function to list drafts and feed them to helm. Doom Emacs seems to use ivy as
 function to list drafts and feed them to helm. Doom Emacs seems to use ivy as
@@ -624,11 +631,15 @@ project's directory.
 (defun chicken/list-hugo-drafts ()
 (defun chicken/list-hugo-drafts ()
   "Fetches the current drafts in a hugo project when available.
   "Fetches the current drafts in a hugo project when available.
 Assumes the current project is a Hugo one."
 Assumes the current project is a Hugo one."
-  (let
-      ((root (projectile-project-root)))
-    (counsel--split-string
-     (counsel--call
-      (list "hugo" "-s" root "list" "drafts")))))
+(let* ((root (projectile-project-root))
+       (stdout
+        (with-temp-buffer
+          (call-process "hugo" nil t nil "-s" root "list" "drafts")
+          (buffer-string)))
+       (lines (string-lines stdout))
+       (entries (cdr lines)) ; Remove Hugo's table header
+       (filenames (mapcar  #'(lambda (str) (car (string-split str ","))) entries)))
+  filenames))
 #+END_SRC
 #+END_SRC
 
 
 Then I have an interactive function I can call that will process the list given
 Then I have an interactive function I can call that will process the list given