HugoでQuick Start (2022年9月版)

September 05, 2022

確認環境

$ hugo version
hugo v0.101.0+extended darwin/amd64 BuildDate=unknown

サイト生成

$ hugo new site site-learning-history

テーマ追加

ここでは使いたい Hugo テンプレートの情報に書き換えてください。

$ git submodule add https://github.com/someone/hugo-template.git themes/hugo-template
$ echo theme = \"hugo-template\" >> config.toml

サーバー起動

$ hugo server -D

サイトの設定を更新

config.toml

# TODO: 本番公開する時に更新してください
baseURL = 'http://example.org/'
languageCode = 'ja'
title = 'My Site Name'
theme = "hugo-template"

[permalinks]
posts = "/:year/:month/:day/:slug"

記事のマークダウンが下記のように設定されているとすると、パスが /2022/08/28/1/ となります。

---
title: "My First Post"
date: 2022-08-28T21:55:43+09:00
draft: true
slug: 1
---

外部リンクの場合、別タブで開く

layouts/_default/_markup/render-link.html

<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>

参考


SHARE

Profile picture

Written by tamesuu