From 5e13298a65d8c97acfdb5e07e41402c6bae04b37 Mon Sep 17 00:00:00 2001 From: geekifan Date: Fri, 23 May 2025 11:47:39 +0800 Subject: [PATCH] fix(taxonomy): ensure category existence check before accessing parameters Updated the category terms layout to check for the existence of the "categories" parameter before attempting to access its length, preventing potential errors. --- layouts/taxonomy/category.terms.html | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/layouts/taxonomy/category.terms.html b/layouts/taxonomy/category.terms.html index 546bc19..d7869ca 100644 --- a/layouts/taxonomy/category.terms.html +++ b/layouts/taxonomy/category.terms.html @@ -9,8 +9,10 @@ {{ $parentCategories := slice }} {{ range $allPages }} - {{ if gt (len .Params.categories) 0 }} - {{ $parentCategories = $parentCategories | append (index .Params.categories 0) }} + {{ if isset .Params "categories" }} + {{ if gt (len .Params.categories) 0 }} + {{ $parentCategories = $parentCategories | append (index .Params.categories 0) }} + {{ end }} {{ end }} {{ end }} {{ $parentCategories = $parentCategories | uniq | sort }} @@ -23,11 +25,13 @@ {{ range $allPages }} - {{ if gt (len .Params.categories) 0 }} - {{ if eq (index .Params.categories 0) $parentName }} - {{ $parentPages = $parentPages | append . }} - {{ if gt (len .Params.categories) 1 }} - {{ $subcategories = $subcategories | append (index .Params.categories 1) }} + {{ if isset .Params "categories" }} + {{ if gt (len .Params.categories) 0 }} + {{ if eq (index .Params.categories 0) $parentName }} + {{ $parentPages = $parentPages | append . }} + {{ if gt (len .Params.categories) 1 }} + {{ $subcategories = $subcategories | append (index .Params.categories 1) }} + {{ end }} {{ end }} {{ end }} {{ end }}