<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Netlify | エンジニアのひきだし</title><link>https://blog.nattokinxxxx.net/tags/netlify/</link><atom:link href="https://blog.nattokinxxxx.net/tags/netlify/index.xml" rel="self" type="application/rss+xml"/><description>Netlify</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>ja</language><copyright>© 2020 nattokinxxxx All Rights Reserved.</copyright><lastBuildDate>Wed, 01 Apr 2020 22:00:10 +0900</lastBuildDate><image><url>img/map[gravatar:%!s(bool=false) shape:circle]</url><title>Netlify</title><link>https://blog.nattokinxxxx.net/tags/netlify/</link></image><item><title>Hugo(Academic) + Netlifyで無料のブログ構築</title><link>https://blog.nattokinxxxx.net/post/hugo-netlify/</link><pubDate>Wed, 01 Apr 2020 22:00:10 +0900</pubDate><guid>https://blog.nattokinxxxx.net/post/hugo-netlify/</guid><description>&lt;p>HugoとNetlifyでブログ構築したので備忘録。&lt;/p>
&lt;h2 id="なぜhugoとnetlifyなのか">なぜHugoとNetlifyなのか？&lt;/h2>
&lt;ul>
&lt;li>無料でできる（大事）&lt;/li>
&lt;li>ブログの執筆は書き慣れたMarkdownで気軽に行いたい&lt;/li>
&lt;li>いい感じのテンプレートがあった（Academic）&lt;/li>
&lt;li>NetlifyはCIがついていてデフォルトでHugoに対応している&lt;/li>
&lt;li>GitHubのプライベートリポジトリでも無料で使える&lt;/li>
&lt;/ul>
&lt;p>静的サイトジェネレータには他にもGatsbyとかHexoとかJekyllとかありますが、Go製だったのでHugoにしました。
HugoはGoの &lt;code>html/template&lt;/code> と &lt;code>text/template&lt;/code> をベースに作られてるらしいのでカスタムしやすそうだと思ったのも理由の一つです。&lt;/p>
&lt;h2 id="hugoのインストール">Hugoのインストール&lt;/h2>
&lt;p>まずは前準備&lt;/p>
&lt;pre>&lt;code class="language-bash">$ brew install hugo
&lt;/code>&lt;/pre>
&lt;h2 id="テンプレートのインストール">テンプレートのインストール&lt;/h2>
&lt;p>
&lt;a href="https://sourcethemes.com/academic/docs/install/#install-with-git" target="_blank" rel="noopener">こちら&lt;/a>を参考に。&lt;/p>
&lt;pre>&lt;code class="language-bash">$ git clone https://github.com/sourcethemes/academic-kickstart.git My_Website
# サブモジュールの更新
$ cd My_Website
$ git submodule update --init --recursive
&lt;/code>&lt;/pre>
&lt;p>ローカルで確認してみる&lt;/p>
&lt;pre>&lt;code class="language-bash">$ hugo server
| EN
-------------------+-----
Pages | 36
Paginator pages | 0
Non-page files | 1
Static files | 5
Processed images | 11
Aliases | 5
Sitemaps | 1
Cleaned | 0
Built in 468 ms
Watching for changes in /Users/jun/project/My_Website/{assets,content,data,static,themes}
Watching for config changes in /Users/jun/project/My_Website/config.toml, /Users/jun/project/My_Website/config/_default
Environment: &amp;quot;development&amp;quot;
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at //localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop
&lt;/code>&lt;/pre>
&lt;p>
&lt;a href="http://localhost:1313" target="_blank" rel="noopener">http://localhost:1313&lt;/a> で確認&lt;/p>
&lt;p>&lt;img src="academic_demo.png" alt="デモ画面">&lt;/p>
&lt;h2 id="githubにpush">GitHubにpush&lt;/h2>
&lt;p>リポジトリはプライベートでもパブリックでもいいです。&lt;/p>
&lt;pre>&lt;code class="language-sh">$ rm -rf .git
$ git init
# hubコマンドを利用する場合（パブリックの場合は -p なし）
$ hub create -p
$ git remote -v
origin git@github.com:xxx/My_Website.git (fetch)
origin git@github.com:xxx/My_Website.git (push)
# 手動でリポジトリを作成する場合
$ git remote add origin git@github.com:nattokin/My_Website.git
$ git remote -v
origin git@github.com:xxx/My_Website.git (fetch)
origin git@github.com:xxx/My_Website.git (push)
$ git add .
$ git commit -m &amp;quot;first commit&amp;quot;
$ git push origin master
&lt;/code>&lt;/pre>
&lt;h2 id="netlify登録デプロイ">Netlify登録&amp;amp;デプロイ&lt;/h2>
&lt;h3 id="ログイン">ログイン&lt;/h3>
&lt;p>
&lt;a href="https://app.netlify.com/" target="_blank" rel="noopener">こちら&lt;/a>からGitHubアカウントでログイン&lt;/p>
&lt;h3 id="リポジトリの選択">リポジトリの選択&lt;/h3>
&lt;p>&lt;code>New Site from Git&lt;/code> から対象のGitHub&amp;gt;リポジトリを選択します。&lt;/p>
&lt;p>&lt;img src="new_site_from_git.png" alt="Netlifyリポジトリ登録画面">&lt;/p>
&lt;h3 id="デプロイ">デプロイ&lt;/h3>
&lt;p>デフォルトのままでok。
設定ファイル &lt;code>netlify.toml&lt;/code> の内容が優先されるので無視されます。&lt;/p>
&lt;ul>
&lt;li>&lt;code>Branch to deploy&lt;/code> : &lt;code>master&lt;/code>&lt;/li>
&lt;li>&lt;code>Build command&lt;/code> : &lt;code>hugo&lt;/code>&lt;/li>
&lt;li>&lt;code>Publish directory&lt;/code> : &lt;code>public&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>&lt;code>Deploy site&lt;/code> を押す。&lt;/p>
&lt;p>&lt;img src="deploy_site.png" alt="Netlifyデプロイ画面">&lt;/p>
&lt;p>デプロイ完了。リンク先で確認。&lt;/p>
&lt;p>&lt;img src="deploy_finished.png" alt="デプロイ完了画面">&lt;/p>
&lt;h2 id="academicの設定">Academicの設定&lt;/h2>
&lt;p>基本設定の変更はこんな感じ&lt;/p>
&lt;pre>&lt;code class="language-toml"># config/_default/config.toml
# 最下部のコピーライトに表示されるやつ
- copyright = &amp;quot;&amp;quot;
+ copyright = &amp;quot;&amp;amp;copy; 2020 nattokinxxxx All Rights Reserved.&amp;quot;
# 言語設定
- defaultContentLanguage = &amp;quot;en&amp;quot;
- hasCJKLanguage = false # Set `true` for Chinese/Japanese/Korean languages.
+ defaultContentLanguage = &amp;quot;ja&amp;quot;
+ hasCJKLanguage = true # Set `true` for Chinese/Japanese/Korean languages.
# 記事のフィルタなどに使用するようだが自分しか投稿しないので不要
[taxonomies]
tag = &amp;quot;tags&amp;quot;
category = &amp;quot;categories&amp;quot;
publication_type = &amp;quot;publication_types&amp;quot;
- author = &amp;quot;authors&amp;quot;
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-toml"># config/_default/languages.toml
- [en]
- languageCode = &amp;quot;en-us&amp;quot;
+　[ja]
+ languageCode = &amp;quot;ja&amp;quot;
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-toml"># config/_default/params.toml
# サイトの文字サイズ
- font_size = &amp;quot;L&amp;quot;
+ font_size = &amp;quot;M&amp;quot;
# ヘッダーのdescription
- description = &amp;quot;&amp;quot;
+ description = &amp;quot;エンジニアのブログ&amp;quot;
&lt;/code>&lt;/pre>
&lt;h2 id="まとめ">まとめ&lt;/h2>
&lt;ul>
&lt;li>Netlifyへのデプロイ周りはすごく簡単&lt;/li>
&lt;li>テンプレートのカスタマイズについては
&lt;a href="../customize-academic/">こちら&lt;/a>&lt;/li>
&lt;/ul></description></item></channel></rss>