KumaROOT Logo
  • はじめに

プログラミングしたい

  • コマンドの使い方
  • Gitの使い方
  • ROOTの使い方
  • Geant4の使い方
  • Pythonの使い方
  • NumPyの使い方
  • Pandasの使い方
  • Polarsの使い方
  • Matplotlibの使い方
  • Altairの使い方
  • Plotlyの使い方
  • hvPlotの使い方
  • streamlitの使い方
  • Rustの使い方
  • Google Apps Script の使い方
  • HTML / CSSの使い方
  • Docker の使い方

文書作成したい

  • LaTeXの使い方
  • Sphinxの使い方
  • Hugoの使い方
    • セットアップしたい
      • セットアップしたい
      • 設定ファイルしたい(/config/)
        • 設定ファイル(hugo.toml)
        • 設定ファイルを分割したい(オススメ)
        • ビルド環境別に設定したい(オススメ)
        • 言語設定したい([languages] / languages.toml)
        • メニュー設定したい([menu] / menu.toml)
        • パーマリンク設定したい([permalinks] / permalinks.toml)
        • タクソノミー設定したい([taxonomies] / taxonomies.toml)
        • ページ割り設定したい([pagination] / pagination.toml)
        • Google Analytics設定したい(services.googleAnlytics / privacy.googleAnalytics)
        • 著作権表示したい(copyright)
        • 日付フォーマットしたい(params.date_format)
        • マークアップ設定したい([markup] / markup.toml)
        • 設定ファイルを変更したい(hugo --config)
        • リファレンス
      • コンテンツしたい(/content/)
      • テンプレートしたい(/layouts/)
      • カスタムデータしたい(/data/)
      • アセットしたい(/assets/)
      • 静的ファイルしたい(/static/)
      • テーマしたい(/themes/)
      • 多言語化したい(/i18n/)
    • 再編中
    • テンプレートしたい
    • デプロイしたい
    • リファレンス
  • MySTの使い方
  • Typstの使い方
  • VS Codeの使い方
  • Emacsの使い方

未分類

  • ライブ配信
  • ガジェットの使い方
  • DaVinci Resolveの使い方
  • Raspberry Piの使い方
  • Red Pitayaの使い方
  • Windowsの使い方

用語集

  • 用語集
KumaROOT
  • Hugoの使い方
  • 設定ファイルしたい(/config/)
  • パーマリンク設定したい([permalinks] / permalinks.toml)
  • View page source
Previous Next

パーマリンク設定したい([permalinks] / permalinks.toml)

1# config/_default/hugo.toml
2[permalinks]
3directory_name = "パーマリンクのフォーマット"

[permalinks]セクション、もしくはconfig/_default/permalinks.tomlで、ビルドした記事やページのパーマリンク(URLパターン)を設定できます。 デフォルト(=設定なし)はファイル名をベースとしたURLです。

ファイル名をベースにしたい

1[permalinks]
2post = "/blog/:filename"
3# ==> /blog/記事1/
4
5post = "/:section/:filename"
6# ==> /post/記事1/

ファイル名やパス、ページのタイトルを使ってパーマリンクを定義できます。

ページ(page kind)用のパーマリンク設定に適しています。

  • :section: セクション名

  • :sections: 階層をもったセクション名。スライス可能

  • :title: ページタイトル。front matterで設定

  • :slug: スラグ。front matterで設定

  • :filename: 拡張子を除外したファイル名

  • :slugorfilename: slug もしくは filename

公開日をベースにしたい

1[permalinks]
2post = "/:section/:year/:month/:day"
3# ==> /post/2023/10/23/
4
5post = "/:section/:year/:yearday"
6# ==> /post/2023/123

日付トークンを使って、公開日を挿入できます。 記事(post kind)用のパーマリンク設定に適しています。

  • :year: 年(4桁)

  • :month: 月(01 - 12)

  • :monthname : 月名

  • :day: 日(01 - 31)

  • :weekday: 曜日(0 - 6)

  • :weekdayname: 曜日名

  • :yearday: 日数(001 - 365)

個人的に:year/:yeardayを使うのが好きです。

セクションしたい

 1[permalinks]
 2[permalinks.page]
 3posts = "/articles/:year/:yearday"
 4tutorials = "/training/:slug"
 5# posts/記事/index.md ==> /articles/年/日数/index.html
 6# tutorials/記事/index.md ==> /training/スラグ/index.html
 7
 8[permalinks.section]
 9posts = "/articles/"
10tutorials = "/training/"
11# posts/index.md ==> /articles/index.html
12# tutorials/index.md ==> /training/index.html

セクションごとにパーマリンクを設定できます。

タクソノミーしたい

1[permalinks]
2[permalinks.term]
3tags = "/:slug/"
4# ==> /タグ名/

/tags/タグ名/を/タグ名/に変更できます。

多言語したい

パーマリンクは多言語サイトでも同じように設定できます。 実際に次のようなコンテンツ構造のサイトで動作確認しました。

content/
|-- _index.ja.md    --> public/ja/index.html
|-- _index.en.md    --> public/en/index.html
|-- about.ja.md     --> public/ja/about/index.html
|-- about.en.md     --> public/en/about/index.html
|-- post/
    |-- _index.ja.md   --> public/ja/blog/index.html
    |-- _index.en.md   --> public/en/blog/index.html
    |-- 記事1.ja.md     --> public/ja/blog/年/月/日/index.html
    |-- 記事1.en.md     --> public/en/blog/年/月/日/index.html

パーマリンク設計を考える

パーマリンク設定は、HugoだけでなくどのCMSでも構築時に検討が必要な項目です。 固定ページはファイル名をベースとしたパターンで問題ありませんが、 記事ページはファイル名やタイトル名に依存しないパターンが好ましいです。

また、記事ページは作成頻度が高く、また内容が更新される可能性があります。 そのため、記事タイトルに依存するようなパターンや、 URLが重複してりまうようなパターンは好ましくありません。

僕の中では、WordPressのようなデータベースを利用したCMSであれば、 記事ごと一意なページIDが割り振られるので、それを利用するのがパターンがベストだと思います。

Hugoの場合、ページIDは自動で割り振られないので、運用でカバーするしかありません。 同じ日にいくつも記事を作成しないのであれば、公開日ベースのパターンにするのがよいと思います。

リファレンス

  • URL Management

  • Permalinks

  • Tokens

Previous Next

© Copyright 2015 - 2025, Shota TAKAHASHI.

Built with Sphinx using a theme provided by Read the Docs.