Skip to content

Commit

Permalink
fix: embed template correclty
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBigRoomXXL committed Sep 12, 2023
1 parent 0f4f218 commit eb9f3fd
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"embed"
_ "embed"
"fmt"
"log"
"net/url"
Expand All @@ -14,8 +14,8 @@ import (
"github.com/spf13/cobra"
)

//lint:ignore U1000 go:embed built-in.html
var htmlTemplate embed.FS
//go:embed built-in
var builtInTemplate string

// flags
var limit int
Expand Down Expand Up @@ -59,8 +59,8 @@ func init() {
&templatePath,
"template",
"t",
"built-in",
"Path to a custom html+go template file.",
"",
"Path to a custom HTML+Go template file.",
)
}

Expand Down Expand Up @@ -127,9 +127,18 @@ func domain(item *gofeed.Item) string {
}

func printHTML(feeds []*gofeed.Feed, items []*gofeed.Item) error {
ts, err := template.New(templatePath).
Funcs(template.FuncMap{"Preview": preview, "Domain": domain}).
ParseFiles(templatePath)
var err error
var ts *template.Template

if templatePath == "" {
ts, err = template.New("built-in").
Funcs(template.FuncMap{"preview": preview, "domain": domain}).
Parse(builtInTemplate)
} else {
ts, err = template.New(templatePath).
Funcs(template.FuncMap{"preview": preview, "domain": domain}).
ParseFiles(templatePath)
}
if err != nil {
return fmt.Errorf("error loading html template: %s", err)
}
Expand Down

0 comments on commit eb9f3fd

Please sign in to comment.