githubにcommitしたら自動で記事が公開されるようにする.こうすることで完璧主義のために結局アウトプットできない問題を解決できないか考えた.
なるべく楽に,とりあえず公開,問題があったら後から修正すればいい.まずはアウトプットの経験
ローカルでHugoブログ作る
brew install hugo
# 作業ディレクトリで新規サイト作る
hugo new site output_blog
cd output_blog
# git設定
git init
# PaperMod テーマ
git submodule add https://github.com/adityatelange/hugo-PaperMod themes/PaperMod
その後hugo.tomlを記述
baseURL = "https://[site url]/"
title = "dottle log"
theme = "PaperMod"
languageCode = "ja-jp"
defaultContentLanguage = "ja"
hasCJKLanguage = true
# GitHub Pages で /blog などサブパス運用するなら必要に応じて:
# canonifyURLs = true
[params]
homeInfoParams = false # トップの大きなプロフィールカードを消して一覧寄せに
mainSections = ["posts"] # トップに出すセクションを posts に限定
次に新規記事を作る
hugo new posts/first.md
code content/posts/first.md
ファイル内の設定で,draft: falseと設定
ローカルサーバー起動して確認
hugo server -D
ここまでで書いたものをプレビューできる状態の完成
githubとの連携
githubでリポジトリを作り,
git remode add origin <リポジトリURL>
git add .
git commit -m 'init hugo blog'
git push -u origin main
github の該当リポジトリでSettingsからPagesに移動.Build and deploymentのSourceをGithub Actionsに変更.これでこのリポジトリが,ActionからデプロイされるPagesサイトになる
ルートディレクトリに.github/workflows/deploy.yamlを作る
# Sample workflow for building and deploying a Hugo site to GitHub Pages
name: Deploy Hugo site to Pages
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
env:
HUGO_VERSION: 0.147.2
HUGO_ENVIRONMENT: production
TZ: Asia/Tokyo
steps:
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Build with Hugo
run: |
hugo \
--gc \
--minify \
--baseURL "${{ steps.pages.outputs.base_url }}/"
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
このファイルをcommit & pushすると自動でActionが回るようになる
毎回記事を書いて公開するときの手順
これであとは,以下のワークフローで新規記事作成,公開ができるようになる.
hugo new posts/xxx.mdで新規記事作成draft: falseにして本文を書くgit add . && git commit -m 'add post' && git push