Creating blog posts with GitHub Issues
Creating blog posts with Hugo and GitHub issues.
I just read Garrit's blog post about publishing posts for blog with GitHub action and issues. I was thinking about making the publishing process easier, but still in intention with creating API, but I like this idea and I think it's worth trying. So I decided to write my own action and this blog post.
My blog runs on Hugo and I also manage a couple of sites for our clients in work on Hugo . It was easier for me to write a template for Hugo than to use Wordpress. And I don't have to worry about backing up the database or updating it. However, there are drawbacks, static pages are not as easy to manage - you have to manage files in git and use the command line.
This is easy for me but not everyone I know is friend with commandline and issues on github partly solve this problem and I think it is easier to explain people how to create an issue than how to install Hugo and on our keyboard[1] is harder to write #
for headings or *
...
The workflow
- You or someone else creates GitHub issue with post content (I don't accept strangers posting on my blog)
- You add labels
tag:tag name
type:type-name
[2]
- Add the
action:publish
label when you are finished with the reviews and you want to publish the post - Bot creates new pull request with post.
- Merge pull requests to publish changes to production.
Action
Thanks to GitHub actions, I'm able to reuse code[3] in my other projects as easily as this.
name: CI
on:
issues:
types: [labeled]
jobs:
build:
if: github.event.label.name == 'action:publish'
runs-on: ubuntu-latest
steps:
- name: Run martinkukolos/action-hugo-publish@main
uses: martinkukolos/action-hugo-publish@main
with:
git-commiter-name: "Hugo Bot"
git-commiter-email: ${{ secrets.BotCommiterEmail }}
The code above just creates new content from issues, you still need more configuration to create a pull request. I wrote about it here in the readme of my project. Or you can check out the configuration of this blog.
The repository of my action is here MartinKukolos/action-hugo-publish [4]
Slovak keyboard
Alt Gr + X
orAlt + Shift +3
↩︎I added this to be able to create content other than just posts. (e.g. pages, projects and more) ↩︎
No need to copy functions to other projects or configure anything special on them. ↩︎
I created it primarily for creating posts for Hugo, but it may work with other static site generators, let me know if it does. ↩︎