From 016bf56b078b8c0f539eff6c220844bcbb6ee0c5 Mon Sep 17 00:00:00 2001 From: Tsung-Ju Lii Date: Thu, 27 Feb 2025 18:30:38 +0800 Subject: [PATCH 1/3] feat: action to deploy when new file is added Signed-off-by: Tsung-Ju Lii --- .github/workflows/deploy.yaml | 40 +++++++++++++++++ .../2025-02-27-restructured-and-automated.md | 43 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 .github/workflows/deploy.yaml create mode 100644 posts/2025-02-27-restructured-and-automated.md diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..e92c539 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,40 @@ +name: Deploy personal website + +on: + workflow_dispatch: + push: # If there's anything new in `posts`, run this action to trigger the deployment. + paths: + - 'posts/**' + +jobs: + build: + runs-on: ubuntu-latest + environment: deployment + steps: + - uses: actions/checkout@v4 + + - uses: haskell-actions/setup@v2.7.9 + with: + ghc-version: 9.8.4 + enable-stack: true + stack-setup-ghc: true + + - run: | + stack build + stack exec site build + + - run: | + if [[ $(git status --porcelain docs/) ]]; then + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git add docs/ + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + git commit -m "Update site at $(date)" + else + new_post=$(git diff --name-only HEAD^ | grep 'posts/') + git commit -m "Add new post: ${new_post}" + fi + git push origin main + else + echo "No changes in docs/ directory" + fi \ No newline at end of file diff --git a/posts/2025-02-27-restructured-and-automated.md b/posts/2025-02-27-restructured-and-automated.md new file mode 100644 index 0000000..a318dbb --- /dev/null +++ b/posts/2025-02-27-restructured-and-automated.md @@ -0,0 +1,43 @@ +--- +title: Restructured and Added Some Automation for This Blog +layout: post +comments: false +tags: about this blog +--- + +I have been avoiding changing things up in this blog even though I really should have done this a long time ago. There were several things I did not like so much about it: + +### Having to Have a Working Haskell Environment + +To actually generate the site, I needed to do the following: + +- `stack build` - this builds the executable called `site` that consumes content in `posts/` and churns out HTML files. +- `stack exec site build` - this runs the `site` executable and builds the HTML files, which are stored in `_site/`. + +Since everything is built offline, a working Haskell environment was necessary. + +### Lots of Manual Steps + +As stated above, since the generated HTML files are in `_site/`, I needed to find a way to get GH pages to host them. The way I did it was to have [another separate repo](https://github.com/usefulalgorithm/old-website), make sure `_site/` is pointing to that repo, then run `stack exec site build`, check that things are generated correctly in `_site`, and finally push to both this repo and the actual GH pages repo. + +--- + +Now that I'm not employed and have some free time, I decided it was finally time to make it more usable and generally encourage myself to post more often. Here's what I did: + +### Deprecate the Old GH Pages Repo and Just Use This One + +This should be quite obvious - there's a [tutorial](https://jaspervdj.be/hakyll/tutorials/github-pages-tutorial.html) that tells you how to change your executable's target directory from `_site/` to `docs/`. I can just ditch the old repo, rename the Haskell repo to `usefulalgorithm.github.io`, and have its page deployed from `docs/` in the main branch. I'm pretty sure the directory has to be called `docs/` and not anything else though. + +### Build & Deploy from GH Actions + +I've done a bunch of GH actions in my previous job and found them to be a huge time saver. So what I wanted to do is just update Markdown files in `posts/`, and then trigger the Haskell commands from within the action runner. + +## What Will Be Done (Hopefully in the Near Future) + +### Post via PRs + +Writing Markdown files is still a little annoying, especially when I'm on my phone and just want to post something to my blog. I want to find a way to create posts through pull requests, but I need to think about where to put things like tags and how to format the pull request message into a proper Markdown file. + +### Repost to Threads (and Possibly Other Platforms) + +More often than not, I would repost the published post to my socials. I know social media is like the worst thing that's happened in 20 years, but I still want people to read what I have to say. From 62b07d4f928ef27949d04bf14315ae3b522a3b95 Mon Sep 17 00:00:00 2001 From: Tsung-Ju Lii Date: Thu, 27 Feb 2025 18:32:32 +0800 Subject: [PATCH 2/3] rephrase stuff --- posts/2025-02-27-restructured-and-automated.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/posts/2025-02-27-restructured-and-automated.md b/posts/2025-02-27-restructured-and-automated.md index a318dbb..a00f5dc 100644 --- a/posts/2025-02-27-restructured-and-automated.md +++ b/posts/2025-02-27-restructured-and-automated.md @@ -32,7 +32,9 @@ This should be quite obvious - there's a [tutorial](https://jaspervdj.be/hakyll/ I've done a bunch of GH actions in my previous job and found them to be a huge time saver. So what I wanted to do is just update Markdown files in `posts/`, and then trigger the Haskell commands from within the action runner. -## What Will Be Done (Hopefully in the Near Future) +--- + +Some things I hope to do in the near future. These aren't hard in themselves but probably require a little bit more consideration. ### Post via PRs From f6efcc68b925a2ec68afcc752e84a09c1cc206d9 Mon Sep 17 00:00:00 2001 From: Tsung-Ju Lii Date: Thu, 27 Feb 2025 18:35:09 +0800 Subject: [PATCH 3/3] only deploy when new post is added to main branch Signed-off-by: Tsung-Ju Lii --- .github/workflows/deploy.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index e92c539..192fc17 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -2,7 +2,9 @@ name: Deploy personal website on: workflow_dispatch: - push: # If there's anything new in `posts`, run this action to trigger the deployment. + push: + branches: + - main paths: - 'posts/**'