kanta's spike

検索インデックスの元データに含めるページを選択したい。

以下でページ一覧を作成すると全ページが含まれるためフィルタリングしたい。

{
    "results": [
    {{- range $index, $page := .Site.RegularPages }}
        {{- if $index -}},{{- end }}
    {
        "href": {{ .Permalink | jsonify }},
        "title": {{ .Title | jsonify }}
    }
    {{- end }}
    ]
}

解決策

where関数でページをフィルタリングする。

以下の例では、タイトル(Title)が “SearchIndexData” のページを除外している。

{
    "results": [
    {{- range $index, $page := where .Site.RegularPages "Title" "!=" "SearchIndexData" }}
        {{- if $index -}},{{- end }}
    {
        "href": {{ .Permalink | jsonify }},
        "title": {{ .Title | jsonify }}
    }
    {{- end }}
    ]
}

参考

作成日: 2022/08/29