Move template input types to html module

This commit is contained in:
Tim Van Baak 2025-01-24 21:41:46 -08:00
parent ab58837b5d
commit c18cc73496
3 changed files with 25 additions and 18 deletions

View File

@ -5,6 +5,8 @@ import (
"html/template"
"io"
"time"
"github.com/Jaculabilis/intake/core"
)
func rawHtml(str string) template.HTML {
@ -33,12 +35,24 @@ func load(file string) *template.Template {
var home = load("home.html")
func Home(writer io.Writer, data any) error {
type SourceData struct {
Name string
}
type HomeData struct {
Sources []SourceData
}
func Home(writer io.Writer, data HomeData) error {
return home.Execute(writer, data)
}
var feed = load("feed.html")
func Feed(writer io.Writer, data any) error {
type FeedData struct {
Items []core.Item
}
func Feed(writer io.Writer, data FeedData) error {
return feed.Execute(writer, data)
}

View File

@ -7,25 +7,19 @@ import (
"github.com/Jaculabilis/intake/web/html"
)
type SourceData struct {
Name string
}
type HomeData struct {
Sources []SourceData
}
func (env *Env) rootHandler(writer http.ResponseWriter, req *http.Request) {
names, err := core.GetSources(env.db)
if err != nil {
writer.Write([]byte(err.Error()))
}
var sources []SourceData
var sources []html.SourceData
for _, name := range names {
sources = append(sources, SourceData{name})
sources = append(sources, html.SourceData{Name: name})
}
data := html.HomeData{
Sources: sources,
}
data := HomeData{sources}
html.Home(writer, data)
}

View File

@ -7,10 +7,6 @@ import (
"github.com/Jaculabilis/intake/web/html"
)
type FeedData struct {
Items []core.Item
}
func (env *Env) sourceHandler(writer http.ResponseWriter, req *http.Request) {
source := req.URL.Path[len("/source/"):]
// TODO this needs to properly error if the source doesn't exist instead of just returning []
@ -19,5 +15,8 @@ func (env *Env) sourceHandler(writer http.ResponseWriter, req *http.Request) {
http.NotFound(writer, req)
return
}
html.Feed(writer, FeedData{items})
data := html.FeedData{
Items: items,
}
html.Feed(writer, data)
}