How I update this site
hugo git devopsIn my last post I described how the server was set up for this very site itself. In this post, I will be describing how I create new content for the site from client devices.
How I create/update content on this site from a desktop
Required software
- ssh-keygen
- git (download here)
- hugo (install docs)
Instructions
- Run ssh-keygen and copy the public key into your github account’s keys section. (tutorial here)
- In the directory on the client which you want the repo stored run:
$ git clone git@github.com:jamesdesmond/james-blog.git(replacing my git URL with yours) - In the cloned repository, run
hugo server -Dwhich will create a local webserver at localhost:1313. The -D flag enables drafts to be generated and shown. Which is useful. - In a new terminal window, in the cloned repository, run
hugo new posts/test-post.md - Make edits and save
test-post.md, hugo server should catch the new content and refresh the local server. Check to see that your changes made it there. - Once you are happy with the content and wish to publish it, make sure
draft: trueis changed tofalseand then git add, commit, and push to the master branch. GitHub Actions will automatically build the site and deploy it to the VPS via rsync — usually takes under 30 seconds.
This method is nice because the page is easily viewable through the localhost server, however it does require Hugo and git installed on the client. In the case that I am on a device which I cannot install git on, I will use the GitHub web client. By just adding a new .md file into the content/posts folder, I can update the site. GitHub has a viewer for Markdown files, which is not live, but is an alright alternative. I then commit and push from the web UI itself, and the CI/CD pipeline automatically builds and deploys the changes to the live site.