ãã®èšäºã¯ Static Site Generator Advent Calendar 2020 10 æ¥ç®ã®èšäºã§ãã
ã¯ããã«
Zenn ã Qiita, note ãªã©æ§ã ãªãŠã§ããµãŒãã¹ã§èšäºãæžãã«ã€ããŠããµãšéå€ãªå 容ã§èªåã®å¥œãåæã«èšäºãæžããŠå ¬éã§ããèªåã®ããã°ã欲ãããªããŸãããããã§ãèªåã®ããã°ãäœãããšæã調æ»ãããšãããSSG ã§äœãã®ãæã£åãæ©ããã ã£ãã®ãšããã®äžã§ãäžçªã©ã¯ã«ãŠã§ããµã€ããæ§ç¯ã§ããã㪠Hugo ãæ¡çšããŸããã
ãŸãããããã€ã¯ç°¡åã«è¡ãããã£ãã®ã§ããããã€å ãšã㊠GitHub Pages ãæ¡çšããŸããã ç¬èªãã¡ã€ã³ã®å²ãåœãŠãã HTTPS 察å¿ãŸã§ç¡æã§ã§ãããã€ã䜿ãæ £ããŠãã GitHub ããããã€å ã«äœ¿ããããšã決ãæã§ããã
Hugo ã§èªåã®ããã°ãæ§ç¯ã㊠GitHub Pages ã§å ¬éã§ããããã«ãªã£ãã®ã§ãããããã°å 容ãæŽæ°ãããèšäºãæžããã³ã«ãã«ãããŠãããã€ãããã®ããæå€ãšé¢åãªããšã«æ°ã¥ããŸãããããã§ãGitHub Pages action ãçšããŠããã«ãããŠãããã€ãããšããäœæ¥ã¯èªååããŸããã
äžèšãŸã§ã®äœæ¥ãããããšã§ãèªåã®ããã°ãæžãããæŽæ°ããããšã ãã«éäžã§ããç°å¢ãæŽããããšãã§ããŸããããŠã§ããµã€ããäœããã以å€ã¯ãç°¡åãªããã€ãã®äœæ¥ãããã ã㧠Hugo ã§æºè¶³ã®ããèªåã®ããã°ãæžãç°å¢ãæŽããããã®ã§ããã®æé ã«ã€ããŠãŸãšããŠã¿ãŸããã
ã¡ãªã¿ã«æ¬èšäºã®æé ã§å®éã«äœæããç§ã®ããã°ã¯äžèšã§ãã
Hugo ã PC ã«ã€ã³ã¹ããŒã«ãã
ç§ã¯ Windows ã«ã¯ ChocolateyãMac ã§ã¯ Homebrew 㧠Hugo ãã€ã³ã¹ããŒã«ããŸãããChocolatey ã Homebrew ãå©çšããã€ã³ã¹ããŒã«æ¹æ³ã«ã€ããŠã¯ å ¬åŒãµã€ãã®æé ã§å ¬éãããŠããŸãã
# install-with-homebrew.sh
# Mac 㧠Homebrew ã䜿ã£ãŠ Hugo ãã€ã³ã¹ããŒã«ãã
brew install hugo
# install-with-chocolatey.ps1
# Windows 㧠Chocolatey ã䜿ã£ãŠ Hugo ãã€ã³ã¹ããŒã«ãã
choco install hugo -confirm
# Sass/SCSS ãçšããŠãŠã§ããµã€ãã®ãã¶ã€ã³æ¹ä¿®ãè¡ãããå Žåã¯
# äžèšã§ Chocolatey ã䜿ã£ãŠ Hugo ãã€ã³ã¹ããŒã«ãã
choco install hugo-extended -confirm
Hugo ã§èªåã®ãŠã§ããµã€ããæ§ç¯ãã
Hugo ãããžã§ã¯ããäœæãã
äžèšã³ãã³ã㧠Hugo ã®ãããžã§ã¯ããã©ã«ããçæã§ããŸãã
# create-new-site.sh
hugo new site <ãããžã§ã¯ããã©ã«ãã®ãã¹>
Hugo ã®ã³ã³ãã£ã°ãã¡ã€ã«ã®ããã©ã«ããã©ãŒããã㯠TOML 圢åŒãªã®ã§ãããhugo new site <ãããžã§ã¯ããã©ã«ããžã®ãã¹> -f json
ã®ããã« -f
ãªãã·ã§ã³ãä»äžããããšã§ JSON ãã©ãŒãããã§ãã³ã³ãã£ã°ãã¡ã€ã«ãçæå¯èœã§ãã
åŸè¿°ããŸãããäžéšã® Hugo ã®ããŒãã¯ã³ã³ãã£ã°ãã¡ã€ã«ã®ãµã³ãã«ã JSON ãã¡ã€ã«ã§æžãããŠããŸãããã®å Žåã¯ãæ°èŠã§èšå®ããã³ã³ãã£ã°ãã¡ã€ã«ã®ãã©ãŒãããã JSON ã§çµ±äžããŠãããšåçš®èšå®é ç®ã®èª¿æŽã楜ã«ãªãããã§ãã
ãããã¯ãã¡ãã®ãããªã³ã³ããŒã¿ãŒã䜿çšãããããã¡ãã®ãããªãŠã§ãã®ã³ã³ããŒã¿ãŒã䜿çšããŠãèšå®ãã¡ã€ã«ã JSON ãã TOML ãã©ãŒãããã«å€æŽããŠãè¯ãããã§ãã
ãŠã§ããµã€ãã®ããŒããæ¢ã
ããŒããšã¯ããŠã§ããµã€ãã®ãã¶ã€ã³ãã³ãã¬ãŒãã®ããšã§ããããŒã㯠Hugo Themes ã§å ¬éãããŠããã®ã§ããã®äžããèªåã®å¥œã¿ãéžã³ãŸããHugo ã§ã¯ããŒãã®å 容ãã«ã¹ã¿ãã€ãºãããå·®ãæ¿ããããšãã§ããã®ã§ãããšããäžéšãã¶ã€ã³ãèªå奜ã¿ã«ä¿®æ£ã§ããŸãã
Hugo Themes ã«ã¢ã¯ã»ã¹ããæã®ããŒãž
ãæ°ã«å
¥ãã®ããŒããèŠã€ãã£ãããDownload
ãã¿ã³ãã¯ãªãã¯ããŠããŒãã® GitHub URL ãæ§ããŠãããŸãã
Kiera ãšããããŒãã®ããŒãž
Hugo ãããžã§ã¯ãã«ããŒããé©çšãã
ããŒãã®é©çšæ¹æ³ã«ã€ããŠã¯ å
¬åŒãµã€ãã®æé ã§çŽ¹ä»ãããŠããŸãããHugo ã®ãããžã§ã¯ããã©ã«ãã®ã«ãŒãã§äžèšã³ãã³ããå®è¡ããŠãã³ã³ãã£ã°ãã¡ã€ã«ã« theme
ãè¿œèšããã ãã§ãã
# apply-template.sh
git clone <ããŒãã® GitHub URL> themes/<ããŒãå> --depth=1
echo 'theme = "<ããŒãå>"' >> config.toml
ã©ã®ããŒããåºæ¬çã«é©çšæ¹æ³ã¯åãã§ãäŸãã°ç§ãæ¡çšããããŒãã§ãã PaperMod ãé©çšããå Žåã¯äžèšã³ãã³ããå®è¡ããããšã«ãªããŸãã
# apply-papermod-template.sh
git clone https://github.com/adityatelange/hugo-PaperMod themes/hugo-PaperMod --depth=1
echo 'theme = "hugo-PaperMod"' >> config.toml
ããã§èªåã®ãŠã§ããµã€ããäœã蟌ãã§ããããã®æºåãæŽããŸããã
ãŠã§ããµã€ããäœã蟌ã
åããŒãã«ã¯ exampleSite
ãšãããŠã§ããµã€ãäœæã®åèã«ãªã Hugo ã®ãããžã§ã¯ããã©ã«ããååšããŸãã æå㯠exampleSite
ãã©ã«ãå
ã«ååšããåçš®ãã¡ã€ã«ãèªåã®ãããžã§ã¯ãã«ã³ããŒ&ããŒã¹ãããŠãæ¹å€ããªãããŠã§ããµã€ããäœã蟌ãã§ãããšã¹ã ãŒãºã«äœæ¥ãé²ããããŸãã
exampleSite
ãã©ã«ãã¯å€§æµ GitHub ãããžã§ã¯ãã®ã«ãŒãã«ååšããŠããã®ã§ãããGitHub ã®ãã©ã³ãã§ç®¡çããŠãããã®ããããŸãã ç§ã®æ¡çšãã PaperMod 㯠GitHub ã® exampleSite
ãã©ã³ãã§ç®¡çããŠããŸããã
äžèšã®ãããªè©³çŽ°ã¯ Hugo ã®ããŒãããŒãžã«èšèŒãããã¯ããªã®ã§ãäºåã« exampleSite
ãã©ã«ããé
眮ãããŠããå Žæãèšå®å¯èœãªé
ç®çããã§ãã¯ããŠããããšããªã¹ã¹ã¡ããŸããå®éã®ãŠã§ããµã€ãã®èŠãç®ã確èªããã«ã¯ãHugo ã®ãããžã§ã¯ããã©ã«ãã®ã«ãŒãã§äžèšã³ãã³ããå®è¡ããŸãã
hugo server
hugo server
å®è¡äžã«ããŠã§ããµã€ãã®èšå®ãå€æŽãããèšäºãè¿œå ãããšãèªåçã«ãã«ããå®è¡ãããã®ã§åžžã«ææ°ã®ãŠã§ããµã€ãã®èŠãç®ã確èªã§ããŸãããŸãããã®éã«ãšã©ãŒãã³ã³ãœãŒã«ã«åºåãããã®ã§ãé©å®ä¿®æ£ããªãããŠã§ããµã€ãã®äœæãé²ããŠããããšãå¯èœã§ãã
GitHub ã«ãããã€ç°å¢ãæŽãã
ãŠã§ããµã€ãã®æ§ç¯ãåºæ¥ãã°ããšã¯ãããã€ããã ãã§ããä»å㯠GitHub Actions ã§ãããã€ãããããæ®ãã®äœæ¥ã¯ GitHub äžã§é²ããŠãããŸããäžå¿ GitHub Actions ã䜿ããã«æåã§ãããã€ããæé ã«ã€ããŠã¯ãHugo ã® å ¬åŒãµã€ãã®æé ã«ãŠçŽ¹ä»ãããŠããŸãã
GitHub Actions ãçšããŠãããã€ã§ããããã«ããéã®å©ç¹ãšããŠã¯äžèšããããŸãã
- ãããã€æã«æ¯åæåã§è€æ°ã³ãã³ãå®è¡ããæéãçãã
- èªååããããšã§ãããã€æã®ã³ãã³ããã¹ãé²ãããšãå¯èœ
- åžžã«çµ±äžãã Hugo ã®ãã«ãç°å¢ãå©çšå¯èœ
æåã®ãã¡ã¯ç§ãå ¬åŒãµã€ãã®æé éãã« Mac ã§æåãããã€ããŠããŸãããããããWindows ç°å¢ã§ãããã€äœæ¥ããéãæ¬çªç°å¢ãããã€æã« SRI é¢é£ã®ãšã©ãŒãçºçããŠããŸãããŠã§ããµã€ãã« stylesheet ãé©çšãããªããã°ãçºçããŠããŸããŸããã
çµå±åå ã¯ããåãããªãã£ãã®ã§ãããGitHub Actions çµç±ã§ãããã€ããããã«ãããšããçŽããŸãããCI çµç±ã§ãããã€ã§ããããã«ãªããšããããã£ãå®è¡ç°å¢ã®éãã«ããæåãæ°ã«ããå¿ èŠãç¡ããªããŸãã
äžå¿ Windows ç°å¢ã§çºçãã SRI é¢é£ã®ãã°ã¯ Hugo ã§è©²åœãããã³ãã¬ãŒããã¡ã€ã«ã layouts
ãã©ã«ããå©çšããŠå·®ãæ¿ããŠãintegrity ã®èšå®å
容ã空ã«ããããšã§ãæ¬çªç°å¢ã§ã stylesheet ãé©çšã§ããããã«ãªã£ãããšã¯ç¢ºèªããŸããã詳现ã¯ãã¡ãã
èªåã®ãŠã§ããµã€ãããããã€ããããã®ãªããžããªãäœæãã
GitHub ã® å ¬åŒãµã€ãã®æé ã«åŸã£ãŠãèªèº«ã®ãŠã§ããµã€ãããããã€ããããã®ãªããžããªãäœæããŸãããŸãæ¬èšäºã§ã¯ãHugo ãããžã§ã¯ãã®ãªããžããªã¯ãããã€çšãªããžããªãšã¯å¥ã§æ±ããããHugo ãããžã§ã¯ãã®ãªããžããªãæ°ãã«äœæããŸãã
æ¬èšäºã§ã¯ Hugo ãããžã§ã¯ãã®ãªããžããªå㯠hugo-blog
ãšããååã«èšå®ããåæã§é²ããŠãããŸãããŸãäœæãããªã¢ãŒããªããžããªã®æ
å ±ã¯ãäžèšã³ãã³ã㧠Hugo ãããžã§ã¯ãã«ç»é²ããŠãããŸãã
# Hugo ãããžã§ã¯ããã©ã«ãã®ã«ãŒã㧠Git ãªããžããªãäœæãã
git init
# Hugo ãããžã§ã¯ãã®ãªããžããªæ
å ±ãç»é²ããŠãã (hugo-blog ã® GitHub URL)
git remote add origin <Hugo ãããžã§ã¯ãã®ãªããžããªã® URL>
GitHub Actions 㧠Hugo ã®ãã«ããããããã€ãŸã§ãèªååããããã®ç°å¢ãæŽãã
ä»å㯠hugo-blog
ãšãã Hugo ãããžã§ã¯ãã®ãªããžããªããããããã€çšãªããžããªãžãããã€ãããããããŸãã¯ãããã€çšãªããžããªã§ãããã€ããŒãç»é²ããŸããå
¬åŒãµã€ãã®æé ã«åŸããããã€ããŒãç»é²ããããç§å¯éµã hugo-blog
ãªããžããªã®ã·ãŒã¯ã¬ããã«ç»é²ããŸãã
ã·ãŒã¯ã¬ãã㯠å
¬åŒãµã€ãã®æé ã«åŸã£ãŠç»é²ããŸããä»åã¯ç§å¯éµãã·ãŒã¯ã¬ããã«ç»é²ããéã®ååã« ACTIONS_DEPLOY_KEY
ãèšå®ããåæã§é²ããŠãããŸãã
次㫠GitHub Pages action ãå°å ¥ã㊠Hugo ã®ãã«ãããå ¬éãŸã§ãèªååããç°å¢ãã»ããã¢ããããŸãã
hugo-blog
ãªããžããªã« GitHub Pages action ã® Getting started ãåèã«ã¯ãŒã¯ãããŒãã¡ã€ã«ãè¿œå ããŸãã- name: Deploy
ã®é
ç®ã®ã¿ãããã€çšãªããžããªãžãããã€ããããã«èšå®å
容ãå€æŽããŸãã
# .github/workflows/gh-pages.yml
name: github pages
on:
push:
branches:
- main # Set a branch name to trigger deployment
jobs:
deploy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "0.78.2"
- name: Build
run: hugo --minify
# - name: Deploy
# uses: peaceiris/actions-gh-pages@v3
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: ./public
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
external_repository: nikaera/nikaera.github.io
publish_branch: main
cname: nikaera.com
- name: Deploy
ã®é
ç®ã§èšå®ããåçš®ãã©ã¡ãŒã¿ã¯äžèšã«ãªããŸãã
ã㌠| 説æ |
---|---|
deploy_key | ãããã€æã«äœ¿çšããç§å¯éµ |
external_repository | ãããã€å ã®ãªã¢ãŒããªããžã㪠|
publish_branch | ãããã€å ã®ãªã¢ãŒããªããžããªã®ãã©ã³ã |
cname | èšå®ããã«ã¹ã¿ã ãã¡ã€ã³å |
deploy_key
ã«ã¯ã·ãŒã¯ã¬ããã«ç»é²ããç§å¯éµãèšå®ããŸããexternal_repository
ã«ã¯ Hugo ããã«ãããéã®ãããã€å
ãªããžããªã <ãŠãŒã¶å>/<ãªããžããªå>
ã®ãã©ãŒãããã§æå®ããŸããpublish_branch
ã¯ãããã€å
ãšããŠäœ¿çšãããã©ã³ãåã«ãªããŸããcname
ã«ã¯èªåãèšå®ããããã¡ã€ã³åãæå®ããŸããcname
㮠詳现 ã¯ãã¡ãããã確èªããã ããŸãã
ã«ã¹ã¿ã ãã¡ã€ã³ã§èšå®ããå 容㧠DNS èšå®ãæžãæãã
GitHub Pages ã«ã«ã¹ã¿ã ãã¡ã€ã³ãå©çšããéã¯ã該åœãããã¡ã€ã³ã® DNS ã¬ã³ãŒãã®èšå®ã§ CNAME ã¬ã³ãŒãããã㯠A ã¬ã³ãŒããèšå®ããå¿ èŠããããŸããå ¬åŒãµã€ãã®æé ã«åŸã£ãŠèšå®ããŸãã
ãŸããã«ã¹ã¿ã ãã¡ã€ã³ã®èšå®åŸã¯ç¹å¥ãªçç±ããªãéãã¯ããããã€çšãªããžããªã§ HTTPS 匷å¶ã®èšå® ãããŠããããšãªã¹ã¹ã¡ããŸãã
ã¡ãªã¿ã« GitHub Pages ã§å©çšããŠãã蚌ææžã¯ Let’s Encrypt ã®ãã®ã«ãªããŸãã
èšå®äœæ¥ã¯ããã§å®äºã§ããããšã¯å®éã« Hugo ãããžã§ã¯ããæŽæ°åŸãhugo-blog
ãªããžããªã« push ããããšã§ãã«ããããããã€ãŸã§ GitHub Actions ã§è¡ãããããã«ãªã£ããã確èªããŠãããŸãã
Hugo ãããžã§ã¯ãã®æŽæ°æã«èªåã§ãããã€ãè¡ãããã確èªãã
Hugo ãããžã§ã¯ãã«ã¯æ¢ã« hugo-blog
ãªããžããªã® GitHub URL ã origin
ãšããŠèšå®ãããŠããã¯ããªã®ã§ãäžèšã§å®éã« hugo-blog
ãªããžããªãž push ããŠã¿ãŸãã
# Hugo ãããžã§ã¯ãã hugo-blog ãªããžããªã« push ãã
git add -A
git commit -m "initial commit"
git push origin main
次ã¯å®éã« GitHub ãªããžããªã® Actions
ã¿ããããGitHub Pages action ã®ã¯ãŒã¯ãããŒãå®è¡ãããŠããã確èªããŸãã
GitHub Pages actions ã®å®è¡ã«æåããæ§å
ç¡äºã¯ãŒã¯ãããŒã®å®è¡ã«æåããããšã確èªãããããããã€çšãªããžããªã®æ§åã確èªããŸãã
ãããã€çšãªããžããªã« Hugo ã®ææ°ãã«ãã push ãããŠããããšã確èªãã
ææ°ã³ãããã®ã¡ãã»ãŒãžã« deploy: <ãŠãŒã¶å>/hugo-blog@<ã³ãããããã·ã¥>
ã®ã³ã¡ã³ãã衚瀺ãããŠããã¯ãã§ããã³ã¡ã³ãã®ãªã³ã¯ãã¯ãªãã¯ãããšãhugo-blog
ãªããžããªã®ææ°ã³ãããã®ç¢ºèªç»é¢ã«é·ç§»ããã¯ãã§ãã
ãããŸã§ç¢ºèªã§ããã°ãããšã¯ããŒã«ã«ã§ hugo server
ããŠç¢ºèªããŠãããŠã§ããµã€ããšåãããã«ãGitHub Pages äžã§ããŠã§ããµã€ããèŠãããå®éã«ç¢ºèªããŠã¿ãŸãã
ãããã€çšãªããžããªåã <ãŠãŒã¶å>/<ãŠãŒã¶å>.github.io
ã§ãã£ãå Žåãhttps://<ãŠãŒã¶å>.github.io
ã§ãŠã§ããµã€ãã«ã¢ã¯ã»ã¹ã§ããŸããç§ã®å Žå㯠https://nikaera.github.io
ã«ãªããŸãããã®éãã«ã¹ã¿ã ãã¡ã€ã³ã«ãªãã€ã¬ã¯ãããããšã確èªã§ããã°ãã«ã¹ã¿ã ãã¡ã€ã³ã®èšå®ãæ£åžžã«åæ ãããŠããŸãã
ããŒãžãæ£åžžã«è¡šç€ºãããŠããŠã«ã¹ã¿ã ãã¡ã€ã³ã§ã¢ã¯ã»ã¹ã§ããæ§å
ã¢ã¯ã»ã¹æã«æå³ããããŒãžã衚瀺ãããŠããããšã確èªã§ããã°å€§äžå€«ã§ããããã§èªåã®ãŠã§ããµã€ããæŽæ°ããã hugo-blog
ãªããžããªã« Hugo ãããžã§ã¯ãã push ããã ãã§èªåã®ãŠã§ããµã€ããèªåæŽæ°ã§ããããã«ãªããŸããã
ãããã«
ä»å㯠Hugo ãäŸã«ããŸããããæ¬èšäºå ã§çŽ¹ä»ãã GitHub Pages action 㯠æ§ã 㪠SSG ã«å¯Ÿå¿ããŠããŸãããã®ãã Hugo ã§ã¯ãŠã§ããµã€ãã®ã«ã¹ã¿ãã€ãºã«éçãæ¥ããªãšæããã Next.js ã Gatsby ã«ä¹ãæãããšãã£ãããšãå¯èœã§ãã
ãŸã Hugo ã§ã¯äœãèãããšããããŒã¯ããŠã³ã§èšäºãæžããŠãã«ããé«éãªã®ã§ãæã£åãæ©ãèªåã®ãŠã§ããµã€ããæ§ç¯ããŠã¿ãããšããçšéã«ã¯ããã¿ãªã ãšæããŸããã
é¢ä¿ãªãã§ãããHugo ã§ãŠã§ããµã€ãæ§ç¯ããéã®ç¥èŠãèšäºã«å«ããŠããŸã£ãããã§ãæç« éãæå³ããåè¿ãéã«ãªã£ãŠããŸããŸããããç°¡æœã§åãããããæç« ãæžããããã«ãªããªãããã
åèãªã³ã¯
- The worldâs fastest framework for building websites | Hugo
- Complete List | Hugo Themes
- GitHub Pages ã«ã€ã㊠- GitHub Docs
- GitHub Pages action
- Install Hugo | Hugo
- Quick Start | Hugo
- Host on GitHub | Hugo
- GitHub Pages | Websites for you and your projects, hosted directly from your GitHub repository. Just edit, push, and your changes are live.
- ãããã€ããŒã®ç®¡ç - GitHub Docs
- æå·åãããã·ãŒã¯ã¬ãã - GitHub Docs
- GitHub Pages ãµã€ãã®ã«ã¹ã¿ã ãã¡ã€ã³ã管çãã - GitHub Docs
- HTTPS 㧠GitHub Pages ãµã€ããä¿è·ãã - GitHub Docs