From 0687b4e2f20a0a238bab8e28960b7790e19987c4 Mon Sep 17 00:00:00 2001 From: gutmet Date: Wed, 25 Nov 2020 14:49:49 +0100 Subject: [PATCH] make strings.ReplaceAll available in templates * replace newline with br in rss template --- drivel.go | 2 +- rss.template | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivel.go b/drivel.go index 7a8ba45..1d410db 100644 --- a/drivel.go +++ b/drivel.go @@ -583,7 +583,7 @@ func wrapCommandFl(cmd func() (goutil.CommandFlagsInit, goutil.CommandFunc)) fun flagsInit(s) }, func(args []string) error { if f.templateFile != "" { - formatTemplate = template.Must(template.ParseFiles(f.templateFile)) + formatTemplate = template.Must(template.New(filepath.Base(f.templateFile)).Funcs(template.FuncMap{"replaceAll": strings.ReplaceAll}).ParseFiles(f.templateFile)) } return commandFunc(args) } diff --git a/rss.template b/rss.template index d7a392e..5662a0d 100644 --- a/rss.template +++ b/rss.template @@ -16,7 +16,8 @@ {{end}} {{$user := $status.User.Screen_name}} -@{{$user}} ({{$status.Id_str}}){{if $status.In_reply_to_status_id_str}} in reply to {{$status.In_reply_to_screen_name}} ({{$status.In_reply_to_status_id_str}}){{end}}:

{{$status.Text}} +@{{$user}} ({{$status.Id_str}}){{if $status.In_reply_to_status_id_str}} in reply to {{$status.In_reply_to_screen_name}} ({{$status.In_reply_to_status_id_str}}){{end}}:

+{{replaceAll $status.Text "\n" "
"}} {{range $idxMedia, $media := $status.Extended_entities.Media}}
{{end}}