Move template input types to html module
This commit is contained in:
parent
ab58837b5d
commit
c18cc73496
@ -5,6 +5,8 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Jaculabilis/intake/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
func rawHtml(str string) template.HTML {
|
func rawHtml(str string) template.HTML {
|
||||||
@ -33,12 +35,24 @@ func load(file string) *template.Template {
|
|||||||
|
|
||||||
var home = load("home.html")
|
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)
|
return home.Execute(writer, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
var feed = load("feed.html")
|
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)
|
return feed.Execute(writer, data)
|
||||||
}
|
}
|
||||||
|
16
web/root.go
16
web/root.go
@ -7,25 +7,19 @@ import (
|
|||||||
"github.com/Jaculabilis/intake/web/html"
|
"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) {
|
func (env *Env) rootHandler(writer http.ResponseWriter, req *http.Request) {
|
||||||
names, err := core.GetSources(env.db)
|
names, err := core.GetSources(env.db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writer.Write([]byte(err.Error()))
|
writer.Write([]byte(err.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
var sources []SourceData
|
var sources []html.SourceData
|
||||||
for _, name := range names {
|
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)
|
html.Home(writer, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,10 +7,6 @@ import (
|
|||||||
"github.com/Jaculabilis/intake/web/html"
|
"github.com/Jaculabilis/intake/web/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FeedData struct {
|
|
||||||
Items []core.Item
|
|
||||||
}
|
|
||||||
|
|
||||||
func (env *Env) sourceHandler(writer http.ResponseWriter, req *http.Request) {
|
func (env *Env) sourceHandler(writer http.ResponseWriter, req *http.Request) {
|
||||||
source := req.URL.Path[len("/source/"):]
|
source := req.URL.Path[len("/source/"):]
|
||||||
// TODO this needs to properly error if the source doesn't exist instead of just returning []
|
// 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)
|
http.NotFound(writer, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
html.Feed(writer, FeedData{items})
|
data := html.FeedData{
|
||||||
|
Items: items,
|
||||||
|
}
|
||||||
|
html.Feed(writer, data)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user