Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ftp publishing? #65

Closed
c-alpha opened this issue Jun 3, 2022 · 6 comments
Closed

ftp publishing? #65

c-alpha opened this issue Jun 3, 2022 · 6 comments
Labels

Comments

@c-alpha
Copy link

c-alpha commented Jun 3, 2022

First of all: many thanks for making easy-hugo! Just what I needed.

I have a question on how publishing works. The documentation is extremely terse, to be frank.

My site is on a shared web hosting, and I need to upload it via ftp. Thus, after generating the pages with Hugo, I would need a shell script to be called, which does the ftp upload.

From what I understood, I should probably be using easy-hugo-github-deploy and craft my own deploy.sh for this scenario?

@masasam
Copy link
Owner

masasam commented Jun 3, 2022

Hi @c-alpha !
Thank you for comment.
Yes. As you say, you should be using easy-hugo-github-deploy and craft your own deploy.sh.

@c-alpha
Copy link
Author

c-alpha commented Jun 4, 2022

Thanks for you swift response, and conformation.

Will I see the shell script's output anywhere in Emacs?

@masasam
Copy link
Owner

masasam commented Jun 4, 2022

deploy.sh

#!/bin/sh
print 'TEST'

chmod a+x deploy.sh

If you execute such a deploy.sh file with easy-hugo-github-deploy, an error will occur and the display will look like below image.

Screenshot from 2022-06-05 00-16-00

You can see shell script's output only when there is an error.

@c-alpha
Copy link
Author

c-alpha commented Jun 4, 2022

Ah, that clarifies. Thanks! I'll have to resort to some log file then.

What would you think about feeding the shell script output to a new buffer (for instance *easy-hugo-publish-log*)? This would allow users to see when the process is finished.

Many thanks again!

@c-alpha c-alpha closed this as completed Jun 4, 2022
@masasam
Copy link
Owner

masasam commented Jun 4, 2022

I think it's best to do it as your own customization.
Please write your own function in your init.el referring to the following.

emacs-easy-hugo/easy-hugo.el

Lines 1135 to 1152 in baead14

(defun easy-hugo-github-deploy ()
"Execute `easy-hugo-github-deploy-script' script locate at `easy-hugo-basedir'."
(interactive)
(easy-hugo-with-env
(let ((deployscript (file-truename (expand-file-name
easy-hugo-github-deploy-script
easy-hugo-basedir))))
(unless (executable-find deployscript)
(error "%s do not execute" deployscript))
(let ((ret (call-process deployscript nil "*hugo-github-deploy*" t)))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*hugo-github-deploy*"))
(error "%s command does not end normally" deployscript)))
(when (get-buffer "*hugo-github-deploy*")
(kill-buffer "*hugo-github-deploy*"))
(message "Blog deployed")
(when easy-hugo-url
(browse-url easy-hugo-url)))))

@c-alpha
Copy link
Author

c-alpha commented Jun 4, 2022

I ended up with this:

(defconst easy-hugo--github-deploy-buffer "*hugo-github-deploy*")
(defun easy-hugo-github-deploy (&optional show-output)
  "Execute `easy-hugo-github-deploy-script' script locate at `easy-hugo-basedir'.

When the optional SHOW-OUTPUT argument is non-nil, the output
from `easy-hugo-github-deploy-script' will be shown in a buffer.
When SHOW-OUTPUT is nil, the buffer will only be shown when
`easy-hugo-github-deploy-script' fails, that is, when it returns
a non-zero exit status."
  (interactive "P")
  (easy-hugo-with-env
   (let ((deployscript (file-truename (expand-file-name
                                       easy-hugo-github-deploy-script
                                       easy-hugo-basedir))))
     (unless (executable-find deployscript)
       (error "%s do not execute" deployscript))
     (let ((progress-buffer (get-buffer-create
                             easy-hugo--github-deploy-buffer))
           ret
           deploy-success)
       (when show-output
         (switch-to-buffer progress-buffer)
         (erase-buffer)
         (insert (format "Deploying from \"%s\"\n" easy-hugo-basedir)))
       (setq ret (call-process
                  deployscript nil easy-hugo--github-deploy-buffer t)
             deploy-success (zerop ret))
       (when (and show-output deploy-success)
         (insert "Blog deployed"))
       (unless deploy-success
         (switch-to-buffer easy-hugo--github-deploy-buffer)
         (error "%s command does not end normally" deployscript)))
     (when (and (not show-output)
                (get-buffer easy-hugo--github-deploy-buffer))
       (kill-buffer easy-hugo--github-deploy-buffer))
     (message "Blog deployed")
     (when easy-hugo-url
       (browse-url easy-hugo-url)))))

If you wanted to use this scheme across all the deploy functions, you would have to collect any prefix argument to the publish commands (i.e. (defun ... &optional show-output), and make it (interactive "P)), and pass show-output down to all deploy functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants