Jump to content

Issue running Hugo commands


Recommended Posts

So this is a bit of a self-inflicted issue.

 

I am building a workflow for Hugo. As part of that I am trying to run the Hugo server command. It runs a command line web server that has dynamic update so that the web pages update when you change the template etc

 

I can get the server to run by using the Run Script object

 

# Hugo needs to be run from the blog's root directory
cd "${hugoBlogPath}"

# Call Hugo to start the server
"${hugoCommandPath}" server

 

This will start the Hugo server and I can view the web pages.

 

The problem is that this appears to hang Alfred internally. I can't get Alfred to run any other actions in the workflow and the Alfred command line hangs there on screen. It appears to be waiting for Alfred to get back data from the Hugo server. Sometimes, not all of the time, the Debugger will actually get the return data that the Hugo server sends.

 

Start building sites …
hugo v0.111.2+extended darwin/arm64 BuildDate=unknown

                   | EN
-------------------+------
  Pages            | 238
  Paginator pages  |   4
  Non-page files   |   0
  Static files     |  94
  Processed images |   0
  Aliases          |   1
  Sitemaps         |   1
  Cleaned          |   0

Built in 65 ms
Watching for changes in /Users/Zac/projects/newblog/{archetypes,assets,content,data,layouts,static,themes}
Watching for config changes in /Users/Zac/projects/newblog/config.toml, /Users/Zac/projects/newblog/themes/wrongdog/config.toml
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)

 

This takes anywhere from 55 to 68ms each time (for it to run. It can take minutes to get returned to the Debugger) but it almost always stops Alfred from doing anything else after the server command.

 

Even if there is another line in the Run Script. I tried adding

 

open "http://localhost:1313"

 

to the Run Script but it doesn't get executed. 

 

The complicating factor is that the command either needs to be run from the blog's root directory or you need to provide the path as part of the command. 

 

If I try

 

hugo -s "/Users/Zac/projects/newblog/"

 

it will run but it again gets caught up and doesn't execute any further. I tried running it in a Terminal Command object but it doesn't run and I suspect that Alfred doesn't expand the variables in the Terminal Command object.

 

Anyone have any insight into what I can do to try to get this to run without causing Alfred to pause execution of the workflow?

Link to comment

That’s how your Terminal works too: one command runs after the other and the previous one needs to finish. Otherwise you’d bump into race conditions and stuff would fail all the time because something that isn’t ready would try to run. When you want a shell command to run in the background you add a & at the end.

 

Similarly, when you call Alfred multiple times and execution reaches the same path, by default it will wait for the previous one to finish so they don’t trample over each other. If you want them to run concurrently, change the default in the “running instances” at the top right of the Run Script options.

 

As for the Terminal Command, Alfred will open the Terminal and send the given text, so you have to expand the variables beforehand and send the text like that. There are a different approaches to do that, like using an Arg and Vars to set up everything, or echoing it from the preceding Run Script, or even saving what you need to a temporary script then sending its path to be executed.

Link to comment

I had assumed that the script that Alfred put into the Terminal preference would work. So once I fixed that issue I was able to get this resolved. I had an idea of echoing the command to the Terminal Command object but it was at 2am and I doubt my wife would have been happy with me getting up then to test it.

 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...