Hugo
Recently I was looking for an alternative to the boring, feature-bloat and slooooow wordpress. Hosting wordpress is a nightmare nowadays, and using it has become a true pita. I don’t need all of those features. I hate, that it requires so many plugins to work correctly. And I hate, that I have no or less control about what it is doing in the background. And I really hate, that every update brings even more complexity and features I really don’t need. I just wanted to blog or create static, fast sites.
So I was playing around with:
- typemill (not really designed for blogging, but still quite cool)
- next.js (too complex for a guy with less time)
- zola (maybe cool, but couldn’t get it working on first and second try)
After all I ended up using hugo.
I’m new to the jamstack and I’m also still learning how to use Hugo, but it is well documented and it brings you fast to a reasonable result. And the themes available are.. okay. (No offense!)
And it is written in the recent hype-language go
. In my job, where I design and manage digital products, I have a team of great deveolpers I can rely on. But here I need to figure things out on my own. So I love well documented, easy and fast frameworks, where I can spend more time creating contend and infrastructure than learning just another tool.
Another thing that’s new to me is writing in Markdown, as I’m more used to the Dokuwiki Syntax, of which I’m quite a heavy user at work.
Getting up and running
To start developing and writing, you just need to install it according to the docs mentioned above and start a development server.
Executing these commands gets you up and running:
hugo new site sitename
cd sitename
hugo server -D # -D option to show drafts
Another cool and time-saving feature for noobs like me is the new
command to add new posts:
hugo new posts/hello-there.md
For versioning, git is recommended, of course.
The command
git init
makes it into a git.
Basically I have no Idea how to use git and completely messed up my repo so far. I’m still learning.
Deploy
And finally you might deploy that whole stuff somewhen. If you use a dockerized, dead-simple nginx webserver like me, things are very easy. Building happens using hugos builtin deploy mechanism. To sync to a folder on my server, I thought of using rsync. Turns out, hugo already has a builtin way to use rsync for publishing. Nice!
So I just created a sh file called deploy
and put the following contents in it:
#!/bin/sh
USER=my-user
HOST=my-server.com
DIR=my/directory/to/site/ # the directory where your web site files should go
hugo && rsync -avz --delete public/ ${USER}@${HOST}:~/${DIR} # this will delete everything on the server that's not in the local public folder
exit 0
Made it executable using chmod +x deploy
and executed it via ./deploy
. Make sure to put your ssh key to the remote server before executing the script as it runs without password authentication. Miraculously the files showed up on my server and the website was.. totally broken.
After digging a bit I found out permissions were messed up, but manually fixing them didn’t do the trick. Rsync always chowns the files to the user uploading it. So after the rsync I just executed a chown 1000:1000 ./files -R
and everything works as expected. The full script is then:
#!/bin/sh
USER=my-user
HOST=my-server.com
DIR=my/directory/to/site/ # the directory where your web site files should go
hugo && rsync -avz --delete public/ ${USER}@${HOST}:~/${DIR} # this will delete everything on the server that's not in the local public folder
ssh ${USER}@${HOST} 'chown 1000:1000 /html -R' # fix permissions
exit 0
Yay! I have a Blog now!