paginator 設定トラブル解決例

 Hugo 0.15   トラブル   paginator 

$paginator.Prev.URL が示す URL がおかしいことに気がついた(解決済み)


Paginator とは

Pagination( ページネーション ) に由来する設定および動作であり、ページネーションとは Hugo によって投稿された記事を設定された一定件数毎にリスト化しページ単位でまとめる機能の事。

一定件数以上の記事を投稿しないと「次ページ」が存在しないため、実験用に小さくサイトを作っている時は Pagination を意識せずに作業してる。投稿された記事の件数が増えてページも複数になった時、Paginator の挙動がおかしいことに気が付く。

最初 config.toml から設定するものかと思い

PaginatePath = “static/vim/page/”

こうしたが、これは間違い。これは pages を保存するディレクトリ位置を指定する設定だった。

paginator が BaseURL の設定を反映してくれないのが原因なので Hugo のバグかとも思ったが、フォーラムの過去ログで探したら、すでに同じ質問と解決策が提示されていた。


解決策

参考:https://discuss.gohugo.io/t/closed-baseurl-not-showing-in-pagination/1355

参考:https://github.com/spf13/hugo/commit/61d72f69274ec47b9cc123de4c019cf449910d5f

By setting canonifyurls to true, all relative URLs would instead +be canonicalized using baseurl. For example, assuming you have +baseurl = http://yoursite.example.com/ defined in the site-wide +config.toml, the relative URL /css/foo.css would be turned into +the absolute URL http://yoursite.example.com/css/foo.css.

config.toml に必要な設定を追記

canonifyurls = “true”

これで解決





次へ

前へ