WordpressからHUGOに移行したのでその記録です。

インストール方法

Macなら特に何も面倒くさいことをせずに

brew update
brew install hugo

でOKです。

無事インストールできたか確認ついでにバージョンも表示。

 % hugo version
Hugo Static Site Generator v0.55.5/extended darwin/amd64 BuildDate: unknown

初期設定と動作確認

まずこのサイトの置き場所のためにディレクトリを~/www/hack.ironsand.netを作って、そこにcdで移動。

% hugo new site .
Congratulations! Your new Hugo site is created in /Users/ironsand/www/hack.ironsand.net.

Just a few more steps and you're ready to go:

1. Download a theme into the same-named folder.
   Choose a theme from https://themes.gohugo.io/, or
   create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
   with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".

Visit https://gohugo.io/ for quickstart guide and full documentation.

「テーマを https://themes.gohugo.io/ から探してくるか自分で作ってね。」と言われたので

Lithium を使うことにしました。

% cd themes
git clone https://github.com/jrutheiser/hugo-lithium-theme

そして、設定ファイルのconfig.tomlhttps://github.com/jrutheiser/hugo-lithium-theme/blob/master/exampleSite/config.toml を見ながら修正。


baseurl = "http://hack.ironsand.net"
languageCode = "ja-JP"
title = "答えを知りたい"
theme = "hugo-lithium-theme"
googleAnalytics = ""
disqusShortname = ""

[permalinks]
    post = "/:year/:month/:day/:title/"
    page = "/:title/"

[[menu.main]]
    name = "About"
    url = "/about/"
[[menu.main]]
    name = "GitHub"
    url = "https://ironsand.github.com"
[[menu.main]]
    name = "Twitter"
    url = "https://twitter.com/ironsand"

[params]
    description = "答えを知りたい"

    [params.logo]
    url = "logo.png"
    width = 50
    height = 50
    alt = "Logo"

ようこそページを作成

 % hugo new post/welcome.md
/Users/ironsand/www/hack.ironsand.net/content/post/welcome.md created

そしてできたページを適当に編集します。

+++
date = "2017-03-24T22:06:35+08:00"
title = "welcome"

+++

Welcome!

draft= trueという記述があるので削除しましょう。これがあると下書き扱いなので表示されません。

サーバーを動かす

あとはサーバーを立ててlocalhost:1313にアクセスして無事に画面が表示されれば初期設定は完了です。

 % hugo server -w

Wordpress のデータをHugoに移行

Wordpress はさくらのレンタルサーバに置いてるので、ssh でサーバーに繋いで

cd ~/www/programing.ironsand.net/wp-content/plugins
wget https://github.com/SchumacherFM/wordpress-to-hugo-exporter/archive/master.zip
unzip master.zip

とするとWordpressの管理画面のプラグインWordPress to Hugo Exporterができてるので有効化します。

syntax error, unexpected '[' in エラーが出る。

古いバージョンのphpでは配列の[]記法がサポートされてないようなのでこんなエラーが出ました。

Parse error: syntax error, unexpected '[' in /home/ironsand/www/hack.ironsand.net/wp-content/plugins/wordpress-to-hugo-exporter-master/hugo-export.php on line 133

さくらのサーバコントロールパネル にログインしてPHPのバージョン選択からPHPのバージョンを5系最新の5.6に上げれば正常に有効化できました。

zipファイルでダウンロード

拡張が正常に有効化できたらツールExport to Hugoというメニューができてるので実行します。私の環境では5秒ほどでダウンロードダイアログが出てきたのでzipファイルをダウンロードしましょう。

ファイルの移行

zipファイルを展開するとpostフォルダの中にMarkdown形式の記事が入ってますので全てHugoのcontents/posts/ディレクトリの中に入れてしまえば移行は完了です。ただ使っているプラグインによっては多少の変更は必要になります。

サーバーにアップロード

サーバーは静的サイトなのでSFTPさえ使えればよいかと思ったのですが非常に遅いのでrsyncを使って転送するためにVPSを借りることにしました。とりあえず最低限でよいので月額2ドルで使えるIONOSを借りました。

NGINXなどでサーバーを設定してファイルをアップロードしましょう。