diff --git a/web/html/html.go b/web/html/html.go index 967e777..539a8d3 100644 --- a/web/html/html.go +++ b/web/html/html.go @@ -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) } diff --git a/web/root.go b/web/root.go index b50ce6b..80da95f 100644 --- a/web/root.go +++ b/web/root.go @@ -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) } diff --git a/web/source.go b/web/source.go index 0d4f6a3..3d296f7 100644 --- a/web/source.go +++ b/web/source.go @@ -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) }