From 99ddb5227c0dec7f7ae1b5948281e34a342506df Mon Sep 17 00:00:00 2001 From: Artemis Date: Sat, 19 Nov 2022 15:42:51 +0100 Subject: [PATCH] clean: removed duplication of templates map between html and rss --- handler.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/handler.go b/handler.go index b80f983..19c14a4 100644 --- a/handler.go +++ b/handler.go @@ -163,20 +163,17 @@ func (f *FsBuilder) HandleFeed(feed *domain.Feed) error { // 1. Custom selector handling if feed.PageSelectionPattern != "" { - template, err := template.New(feed.Path).Funcs(template.FuncMap{ + funcs := template.FuncMap{ "collect": func(pages []*domain.Page) int { includedPages = pages return len(includedPages) }, - // must be duplicated because golang is too stupid to spread a map - "get_root_section": GetRootSection, - "get_subsection": GetSubsection, - "all_pages": GetAllPages, - "by_date": ByDate, - "by_name": ByName, - "published": OnlyPublished, - "unpublished": OnlyUnpublished, - }).Parse(feed.PageSelectionPattern) + } + for k, v := range templateFuncs { + funcs[k] = v + } + + template, err := template.New(feed.Path).Funcs(funcs).Parse(feed.PageSelectionPattern) if err != nil { return err } -- 2.45.2