From 0af0710a8ead03e3933c40a67d152211b5635365 Mon Sep 17 00:00:00 2001 From: Ashish Bhatia Date: Sat, 27 Jul 2024 23:50:19 -0700 Subject: [PATCH] fix: handle empty tag names --- src/wp2hugo/internal/wpparser/wp_parser_setup.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wp2hugo/internal/wpparser/wp_parser_setup.go b/src/wp2hugo/internal/wpparser/wp_parser_setup.go index e296a79..54089ce 100644 --- a/src/wp2hugo/internal/wpparser/wp_parser_setup.go +++ b/src/wp2hugo/internal/wpparser/wp_parser_setup.go @@ -470,10 +470,20 @@ func getCategories(inputs []ext.Extension) []CategoryInfo { func getTags(inputs []ext.Extension) []TagInfo { categories := make([]TagInfo, 0, len(inputs)) for _, input := range inputs { + var tagName string + if len(input.Children["tag_name"]) == 0 { + // Fallback + tagName = input.Children["tag_slug"][0].Value + log.Warn(). + Any("input", input). + Msg("tag_name is missing") + } else { + tagName = input.Children["tag_name"][0].Value + } tag := TagInfo{ // ID is usually int but for safety let's assume string ID: input.Children["term_id"][0].Value, - Name: NormalizeCategoryName(input.Children["tag_name"][0].Value), + Name: NormalizeCategoryName(tagName), Slug: input.Children["tag_slug"][0].Value, } log.Trace().Msgf("tag: %+v", tag)