masasam / emacs-easy-hugo

Emacs major mode for managing hugo
https://gohugo.io/tools/editors/#emacs
GNU General Public License v3.0
362 stars 26 forks source link

Implement support for the newest configuration files basename convention #79

Closed ttybitnik closed 9 months ago

ttybitnik commented 9 months ago

From v0.109.0 on, Hugo started using hugo as basename for its configuration files (https://gohugo.io/getting-started/configuration/#configuration-file).

I've updated the easy-hugo-open-config function to support this new naming convention along with the old one.

Tested locally with both basenames and worked fine.

masasam commented 9 months ago

Hi @ttybitnik ! Thank you for PR! I didn't know about this, so I've merged immediately.

ttybitnik commented 9 months ago

Hehe, fine. Actually, I think we will have to change it a bit.

I didn't see a void symbol warning for the return. Checking it now.

masasam commented 9 months ago

An error is displayed even if the file exists.

let: No Hugo config file found in ~/src/github.com/masasam/solistblog/
let: No Hugo config file found in ~/src/github.com/masasam/solist/
let: No Hugo config file found in ~/src/github.com/masasam/PPAP/
ttybitnik commented 9 months ago

Yes, breaking the dolist was just wrong. I had an eglot warning that did'nt let me see these warnings.

Seems like this should do the trick.

(defun easy-hugo-open-config ()
  "Open Hugo's config file."
  (interactive)
  (easy-hugo-with-env
   (let ((config-files '("config.toml" "config.yaml" "config.json"
                         "hugo.toml" "hugo.yaml" "hugo.json")))
     (catch 'found-config
       (dolist (file config-files)
         (let ((full-path (expand-file-name file easy-hugo-basedir)))
           (when (file-exists-p full-path)
             (find-file full-path)
             (throw 'found-config t))))
       (error "No Hugo config file found in %s" easy-hugo-basedir)))))

Otherwise, we can just go back to the cond and add new lists for the new basename.

masasam commented 9 months ago

It's perfect because there are no more errors. Would you like to pull request additionally? Or should I commit this?

ttybitnik commented 9 months ago

Nice then. Please go ahead.

And sorry for not seeing this before the PR. My eglot warning got me in this one hehe

masasam commented 9 months ago

I got it. I'll commit it here. Thank you for always helping me here.