2025-01-24 00:18:41 +00:00
|
|
|
package html
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"html/template"
|
|
|
|
"io"
|
2025-01-25 05:27:26 +00:00
|
|
|
"time"
|
2025-01-25 05:41:46 +00:00
|
|
|
|
|
|
|
"github.com/Jaculabilis/intake/core"
|
2025-01-24 00:18:41 +00:00
|
|
|
)
|
|
|
|
|
2025-01-25 05:27:26 +00:00
|
|
|
func rawHtml(str string) template.HTML {
|
|
|
|
return template.HTML(str)
|
|
|
|
}
|
|
|
|
|
|
|
|
func tsToDate(t int) string {
|
|
|
|
tm := time.Unix(int64(t), 0).UTC()
|
|
|
|
return tm.Format(time.DateTime)
|
|
|
|
}
|
|
|
|
|
|
|
|
var funcs = template.FuncMap{
|
|
|
|
"raw": rawHtml,
|
|
|
|
"tsToDate": tsToDate,
|
|
|
|
}
|
|
|
|
|
2025-01-24 15:15:54 +00:00
|
|
|
//go:embed intake.css
|
|
|
|
var Stylesheet []byte
|
|
|
|
|
2025-01-24 00:18:41 +00:00
|
|
|
//go:embed *.html
|
|
|
|
var templates embed.FS
|
|
|
|
|
2025-01-28 03:35:13 +00:00
|
|
|
func load(files ...string) *template.Template {
|
|
|
|
files = append([]string{"layout.html"}, files...)
|
|
|
|
return template.Must(template.New("layout.html").Funcs(funcs).ParseFS(templates, files...))
|
2025-01-24 00:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var home = load("home.html")
|
|
|
|
|
2025-01-25 05:41:46 +00:00
|
|
|
type SourceData struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
type HomeData struct {
|
|
|
|
Sources []SourceData
|
|
|
|
}
|
|
|
|
|
|
|
|
func Home(writer io.Writer, data HomeData) error {
|
2025-01-24 00:18:41 +00:00
|
|
|
return home.Execute(writer, data)
|
|
|
|
}
|
2025-01-25 05:27:26 +00:00
|
|
|
|
2025-01-28 03:35:13 +00:00
|
|
|
var feed = load("feed.html", "item.html")
|
2025-01-25 05:27:26 +00:00
|
|
|
|
2025-01-25 05:41:46 +00:00
|
|
|
type FeedData struct {
|
|
|
|
Items []core.Item
|
|
|
|
}
|
|
|
|
|
|
|
|
func Feed(writer io.Writer, data FeedData) error {
|
2025-01-25 05:27:26 +00:00
|
|
|
return feed.Execute(writer, data)
|
|
|
|
}
|
2025-01-28 04:19:08 +00:00
|
|
|
|
|
|
|
var item = load("itemPage.html", "item.html")
|
|
|
|
|
|
|
|
type ItemData struct {
|
|
|
|
Item core.Item
|
|
|
|
Open bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func Item(writer io.Writer, data ItemData) error {
|
|
|
|
return item.Execute(writer, data)
|
|
|
|
}
|