全体的な設定とはじめての記事
サイトのタイトルと言語を設定する
サイトディレクトリに直下にある設定ファイル(config.toml)は、サイト全体に影響する設定を記述します。基準となる URL やサイトのタイトル、言語などの設定を行っていきます。
baseURL = "https://example.org/"
languageCode = "jp"
title = "My New Hugo Site"
theme = "hugo-paper"
記事を作成する
ここでは、はじめての記事(ページ)を作成してみます。 記事ファイルは、次の hugo new コマンドを使用することで content ディレクトリの配下に作成されます。
※コマンドは、サイトプロジェクトのフォルダーで実行します。
c:\hugo> cd hoge_site
c:\hugo> hugo new post/init.md
このコマンドにより content/post/ に init.md ファイルが、次のような内容で作成されます。
---
title: "Init"
date: 2018-05-14T13:05:54+09:00
draft: true
---
作成されたファイルの最終行から記事を追加していきます。
---
title: "Init"
date: 2018-05-14T13:05:54+09:00
draft: true
---
記事文章を追記
ヘッダ部分に、draft: true という行があると、ページが出力されなくなってしまうので、その行は削除してください(参考: Hugo でドラフトページを作成する)。
Web サーバーを起動して確認する
サイトの設定や記事の作成が終わったら、 hugo server コマンドを実行して Web サーバを起動します。このサーバには、 LiveReload という機能が実装されているため実際の作業はサーバを起動したまま行う方が便利かもしれません。
$ hugo server --watch
[K25lBuilding sites … [?25h
| EN
+------------------+----+
Pages | 10
Paginator pages | 0
Non-page files | 0
Static files | 3
Processed images | 0
Aliases | 4
Sitemaps | 1
Cleaned | 0
Total in 66 ms
Watching for changes in C:\hugo\Sites\hoge_site\{content,data,layouts,static,themes}
Watching for config changes in C:\hugo\Sites\hoge_site\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/ へアクセスすることでサイトのトップページが表示されます。
あとは、hugo new コマンドを使って記事を追加していきサイトを成長させていきます。