Back

How to Use Hugo with Yunohost

How to Use Hugo with Yunohost

I recently switched from the Writefreely self-hosted blogging platform, to Hugo. I switched because I wanted more customizability and control of the look & feel of my blog. I also like learning new systems. Another bonus for me, is having all my content separated from the theme of my blog. My whole blog is literally a bunch of *.md files.

What is Hugo?

  • “Hugo is a static HTML and CSS website generator written in Go.”
  • you create ‘pages’ or ‘posts’ in markdown, that is converted to regular HTML

Why I Changed to Hugo vs. WriteFreely

Hugo

  • so many themes!
  • my content is in simple markdown files that are easy to edit and backup
  • lots more control over tags, categories, and more!

WriteFreely

  • integrates with ActivityPub which is great if you are using Mastodon or something like that - I am not, but I used to…

If you are moving from WriteFreely to Hugo, feel free to use my script to get you started.

How to use Hugo?

Before we get started, you have to understand that Hugo is very different from most “blogging platforms”. You don’t login to Hugo to post on your blog. You don’t have to have Hugo installed on the server that hosts your website.

I suggest you look through the quickstart guide to see how it works before going any further. Look at the Overview below to get a general idea of what we are going to do in this tutorial.

Overview of How Hugo will Work on Yunohost

  • create a post using markdown on your computer, hugo new post/my-first-page.md
  • edit the post in the terminal or with a text editor (basic example below)
---
#this is called frontmatter
title: "My first page"
date: 2021-11-30T13:38:10+08:00
tags: ["tag1","tag2"]
----
#your content goes here.
Hello world!
  • run hugo to create your pages on your computer, or hugo server to explore your site locally (localhost:1313)
  • upload the /public folder of your Hugo project from your computer to your Yunohost server’s /var/www/ folder

Setup Hugo and your Website!

Install Hugo on your computer, not on Yunohost! This is where you will be editing your website.

Upload your Website to Yunohost

Extra detail for last step above.

Note: There is no correct or single way to do this - you can use a USB drive, SFTP, rsync or even GitHub!

  • My blog is installed in ~/Documents/arkadicloud on my computer
  • ~/Documents is synced to my Yunohost Nextcloud
  • After making changes to my content, I run hugo on my computer in the /arkadicloud directory
  • I have a cron job that runs at 23:59 every night. It makes a tar backup of current pages, and copies the latest changes to the web server:
#!/bin/bash
now=$(date +"%F")
filename=arkadicloud_$now

echo "* ARKADI-CLOUD BLOG *"
echo "** DELETE BACKUP **"
find /home/yunohost.backup/archives/ -type f -iname 'arkadicloud_*' -mtime +7 -delete
#sudo rm /home/admin/arkadicloud-backup.tar
echo "*** MAKE BACKUP ***"
sudo tar -cf /home/yunohost.backup/archives/$filename.tar /var/www/my_webapp/www/
#sudo tar -cf /home/admin/arkadicloud-backup.tar /var/www/my_webapp/www/
echo "**** SYNC PAGES TO ARKADI-ONE WEB SERVER ****"
sudo rsync -ah --delete /home/yunohost.app/nextcloud/data/elias/files/Documents/arkadicloud/public/ /var/www/my_webapp/www/
echo "** FINISHED! **"

Final Thoughts

Hugo is easy to setup, but difficult to master all the little details. Don’t be discouraged. Figure out what you want to accomplish, and figure it out.

I’m still figuring out the most efficient way to tag things, create archetypes for posts, and master markdown!

I hope the above infromation is enough to help get you started.

Built with Hugo
Theme Stack designed by Jimmy