Adds recipe

This commit is contained in:
Miguel de la Cruz 2024-05-29 11:24:13 +02:00
parent 8d7decd3f7
commit c898be82de
3 changed files with 101 additions and 1 deletions

17
templates/recipe.tmpl Normal file
View file

@ -0,0 +1,17 @@
{{- define "recipe" }}
#!/usr/bin/env python
from calibre.web.feeds.news import BasicNewsRecipe
class AdvancedUserRecipe1709396452(BasicNewsRecipe):
title = '{{ .Title }}'
oldest_article = {{ .OldestArticle }}
max_articles_per_feed = {{ .MaxArticlesPerFeed }}
auto_cleanup = True
remove_empty_feeds = True
feeds = [
{{- range $index, $feed := .Feeds }}
("{{ $feed.Title }}", "{{ $feed.FeedURL }}"),
{{- end }}
]
{{- end }}

34
templates/templates.go Normal file
View file

@ -0,0 +1,34 @@
package templates
import (
"bytes"
"embed"
"fmt"
"text/template"
)
//go:embed *.tmpl
var templates embed.FS
func GetTemplates() (*template.Template, error) {
tmpl, err := template.New("").ParseFS(templates, "*.tmpl")
if err != nil {
return nil, fmt.Errorf("cannot parse templates: %w", err)
}
return tmpl, nil
}
func Execute(data any) ([]byte, error) {
buffer := bytes.NewBufferString("")
tmpl, err := GetTemplates()
if err != nil {
return nil, fmt.Errorf("cannot get templates: %w", err)
}
if err := tmpl.ExecuteTemplate(buffer, "recipe", data); err != nil {
return nil, fmt.Errorf("cannot execute template: %w", err)
}
return buffer.Bytes(), nil
}