Add link to item page

This will be useful later for editing items
This commit is contained in:
Tim Van Baak 2025-01-27 20:19:08 -08:00
parent 565522535f
commit af77322755
5 changed files with 50 additions and 14 deletions

View File

@ -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)
}

View File

@ -1,4 +1,4 @@
{{ define "buttons" -}}
{{ define "item-buttons" -}}
<button class="item-button" title="Deactivate {{ .Source }}/{{ .Id }}">&#10005;</button>
<button class="item-button" title="Punt {{ .Source }}/{{ .Id }}">&#8631;</button>
{{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">&#8663;</a>
@ -12,38 +12,37 @@
{{ define "item" -}}
<article id="{{ .Source }}-{{ .Id }}">
{{/* The item title is a clickable <summary> if there is body content */}}
{{- /* The item title is a clickable <summary> if there is body content */ -}}
{{ if .Body }}
<details>
<summary>
{{ template "buttons" . }}
{{ template "item-buttons" . }}
{{ template "item-title" . }}
</summary>
{{ if .Body }}
<p>{{ raw .Body }}</p>
{{ end }}
</details>
{{ template "buttons" . }}
{{ else }}
{{ template "buttons" . }}
{{ template "item-buttons" . }}
{{- else -}}
{{ template "item-buttons" . }}
{{ template "item-title" . }}<br>
{{ end }}
{{/* end if .Body */}}
{{- /* end if .Body */ -}}
{{/* author/time footer line */}}
{{- /* author/time footer line */ -}}
{{ if or .Author .Time }}
<span class="item-info">
{{ .Author }}
{{ .Time | tsToDate }}
</span><br>
{{ end }}
{{ end -}}
{{/* source/id/created footer line */}}
{{- /* source/id/created footer line */ -}}
<span class="item-info">
{{ .Source }}/{{ .Id }}
<a href="/item/{{ .Source }}/{{ .Id }}">{{ .Source }}/{{ .Id }}</a>
{{ .Created | tsToDate }}
</span>
</article>
{{ end }}
{{/* end define "item" */}}
{{ end -}}
{{- /* end define "item" */ -}}

5
web/html/itemPage.html Normal file
View File

@ -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 }}

20
web/item.go Normal file
View File

@ -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})
}

View File

@ -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))
}