diff --git a/web/html/html.go b/web/html/html.go index a884b27..8f10b3c 100644 --- a/web/html/html.go +++ b/web/html/html.go @@ -57,3 +57,14 @@ type FeedData struct { func Feed(writer io.Writer, data FeedData) error { return feed.Execute(writer, data) } + +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) +} diff --git a/web/html/item.html b/web/html/item.html index 0cf60b8..c09b77b 100644 --- a/web/html/item.html +++ b/web/html/item.html @@ -1,4 +1,4 @@ -{{ define "buttons" -}} +{{ define "item-buttons" -}} {{- if .Link }} @@ -12,38 +12,37 @@ {{ define "item" -}}
-{{/* The item title is a clickable if there is body content */}} +{{- /* The item title is a clickable if there is body content */ -}} {{ if .Body }}
- {{ template "buttons" . }} + {{ template "item-buttons" . }} {{ template "item-title" . }} {{ if .Body }}

{{ raw .Body }}

{{ end }}
-{{ template "buttons" . }} -{{ else }} -{{ template "buttons" . }} +{{ template "item-buttons" . }} +{{- else -}} +{{ template "item-buttons" . }} {{ template "item-title" . }}
{{ end }} -{{/* end if .Body */}} +{{- /* end if .Body */ -}} -{{/* author/time footer line */}} +{{- /* author/time footer line */ -}} {{ if or .Author .Time }} {{ .Author }} {{ .Time | tsToDate }}
-{{ end }} +{{ end -}} -{{/* source/id/created footer line */}} +{{- /* source/id/created footer line */ -}} -{{ .Source }}/{{ .Id }} +{{ .Source }}/{{ .Id }} {{ .Created | tsToDate }} -
-{{ end }} -{{/* end define "item" */}} +{{ end -}} +{{- /* end define "item" */ -}} diff --git a/web/html/itemPage.html b/web/html/itemPage.html new file mode 100644 index 0000000..7f28ac8 --- /dev/null +++ b/web/html/itemPage.html @@ -0,0 +1,5 @@ +{{ define "title" }}{{ if .Item.Title }}{{ .Item.Title }}{{ else }}{{ .Item.Source }}/{{ .Item.Id }}{{ end }} - Intake [{{ .Item.Source }}]{{ end }} + +{{ define "content" -}} +{{ template "item" .Item }} +{{- end }} diff --git a/web/item.go b/web/item.go new file mode 100644 index 0000000..57e6363 --- /dev/null +++ b/web/item.go @@ -0,0 +1,20 @@ +package web + +import ( + "net/http" + + "github.com/Jaculabilis/intake/core" + "github.com/Jaculabilis/intake/web/html" +) + +func (env *Env) getItem(writer http.ResponseWriter, req *http.Request) { + source := req.PathValue("source") + id := req.PathValue("id") + + item, err := core.GetItem(env.db, source, id) + if err != nil { + writer.Write([]byte(err.Error())) + return + } + html.Item(writer, html.ItemData{Item: item}) +} diff --git a/web/main.go b/web/main.go index c76225b..a957336 100644 --- a/web/main.go +++ b/web/main.go @@ -30,6 +30,7 @@ func RunServer(db *core.DB, addr string, port string) { handleFunc("GET /", env.getRoot) handleFunc("GET /style.css", env.getStyle) handleFunc("GET /source/{source}", env.getSource) + handleFunc("GET /item/{source}/{id}", env.getItem) log.Fatal(http.ListenAndServe(bind, nil)) }