hugoをインストール
goenvでgo 1.9.2がインストール済みだった。
https://gohugo.io/getting-started/installing/ をみながらインストールした。
% go get github.com/magefile/mage
% go get -d github.com/gohugoio/hugo
% cd .go/src/github.com/gohugoio/hugo
% mage vendor
% mage install
これでhugoが使えるようになった。
試しに新しいブログを作ってみる。練習用に。 https://gohugo.io/getting-started/quick-start/ を参考にした。
% hugo new site blog
new siteがコマンドで、blogがディレクトリ名。
% cd blog
% ls
archetypes config.toml content data layouts static themes
こんな感じでファイルができた。
次に、Themeを追加する。
git submoduleで追加するために、git initしているっぽい。
本番用のblogは、githubで管理しようと考えているから、ここの手順は変わりそうだ。
% pwd
blog
% git init
% git submodule add https://github.com/mismith0227/hugo_theme_pickles.git themes/pickles
% echo 'theme = "pickles"' >> config.toml
Themeは https://themes.gohugo.io/ で適当に見つけた。シンプルなのを選んでみた。
記事を書いてみる。
% hugo new posts/my-first-post.md
/home/teppchan/blog/content/posts/my-first-post.md created
newの引数が記事を書くためのファイル名。
実際運営するときは、posts/日付か年月/ファイル名.mdにするのがよいのか?他の人のを見てみたい。
% hugo server -D
| EN
+------------------+----+
Pages | 10
Paginator pages | 0
Non-page files | 0
Static files | 3
Processed images | 0
Aliases | 2
Sitemaps | 1
Cleaned | 0
Total in 97 ms
Watching for changes in /home/hoge/blog/{content,data,layouts,static,themes}
Watching for config changes in /home/hoge/blog/config.toml
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop
http://localhost:1313/ にアクセスしてみると、確かにできてた。
設定ファイルconfig.tomlを編集する。デフォルトはこんな感じだった。
% cat config.toml
baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "pickles"
上でインストールしたthemeにはサンプルのconfig.tomlが入っていて、themes/pickles/exampleSite/config.tomlにある。
これをコピーして使ってみる。
% mv config.toml config.toml.bak
% cp themes/pickles/exampleSite/config.toml config.toml
% vi config.toml
config.tomlはコピーしてそのままで使えなかったので、少し編集した。
最初の行のbaseurl = "Your site URL"となっているところを、baseurl = "http://example.org"にする。どうやらYour site URLのままだとそれをURLと勘違いしまうらしい。
% hugo server -D -t pickles
で起動する。 それっぽく動いた。
オプションの-Dは、contentsの下に置いてあるファイルのうち、draft: trueになっているのも使って公開用ファイルを生成するためのオプションらしい。
最初に作ったcontent/posts/my-first-post.mdのヘッダにはdraft: trueがついていて、
他に記事の無い現時点で-Dを外して起動すると、記事の無いページが出来上がる。