Add link to item page
This will be useful later for editing items
This commit is contained in:
parent
565522535f
commit
af77322755
@ -57,3 +57,14 @@ type FeedData struct {
|
|||||||
func Feed(writer io.Writer, data FeedData) error {
|
func Feed(writer io.Writer, data FeedData) error {
|
||||||
return feed.Execute(writer, data)
|
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)
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{{ define "buttons" -}}
|
{{ define "item-buttons" -}}
|
||||||
<button class="item-button" title="Deactivate {{ .Source }}/{{ .Id }}">✕</button>
|
<button class="item-button" title="Deactivate {{ .Source }}/{{ .Id }}">✕</button>
|
||||||
<button class="item-button" title="Punt {{ .Source }}/{{ .Id }}">↷</button>
|
<button class="item-button" title="Punt {{ .Source }}/{{ .Id }}">↷</button>
|
||||||
{{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">⇗</a>
|
{{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">⇗</a>
|
||||||
@ -12,38 +12,37 @@
|
|||||||
{{ define "item" -}}
|
{{ define "item" -}}
|
||||||
<article id="{{ .Source }}-{{ .Id }}">
|
<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 }}
|
{{ if .Body }}
|
||||||
<details>
|
<details>
|
||||||
<summary>
|
<summary>
|
||||||
{{ template "buttons" . }}
|
{{ template "item-buttons" . }}
|
||||||
{{ template "item-title" . }}
|
{{ template "item-title" . }}
|
||||||
</summary>
|
</summary>
|
||||||
{{ if .Body }}
|
{{ if .Body }}
|
||||||
<p>{{ raw .Body }}</p>
|
<p>{{ raw .Body }}</p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</details>
|
</details>
|
||||||
{{ template "buttons" . }}
|
{{ template "item-buttons" . }}
|
||||||
{{ else }}
|
{{- else -}}
|
||||||
{{ template "buttons" . }}
|
{{ template "item-buttons" . }}
|
||||||
{{ template "item-title" . }}<br>
|
{{ template "item-title" . }}<br>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{/* end if .Body */}}
|
{{- /* end if .Body */ -}}
|
||||||
|
|
||||||
{{/* author/time footer line */}}
|
{{- /* author/time footer line */ -}}
|
||||||
{{ if or .Author .Time }}
|
{{ if or .Author .Time }}
|
||||||
<span class="item-info">
|
<span class="item-info">
|
||||||
{{ .Author }}
|
{{ .Author }}
|
||||||
{{ .Time | tsToDate }}
|
{{ .Time | tsToDate }}
|
||||||
</span><br>
|
</span><br>
|
||||||
{{ end }}
|
{{ end -}}
|
||||||
|
|
||||||
{{/* source/id/created footer line */}}
|
{{- /* source/id/created footer line */ -}}
|
||||||
<span class="item-info">
|
<span class="item-info">
|
||||||
{{ .Source }}/{{ .Id }}
|
<a href="/item/{{ .Source }}/{{ .Id }}">{{ .Source }}/{{ .Id }}</a>
|
||||||
{{ .Created | tsToDate }}
|
{{ .Created | tsToDate }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
</article>
|
</article>
|
||||||
{{ end }}
|
{{ end -}}
|
||||||
{{/* end define "item" */}}
|
{{- /* end define "item" */ -}}
|
||||||
|
5
web/html/itemPage.html
Normal file
5
web/html/itemPage.html
Normal 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
20
web/item.go
Normal 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})
|
||||||
|
}
|
@ -30,6 +30,7 @@ func RunServer(db *core.DB, addr string, port string) {
|
|||||||
handleFunc("GET /", env.getRoot)
|
handleFunc("GET /", env.getRoot)
|
||||||
handleFunc("GET /style.css", env.getStyle)
|
handleFunc("GET /style.css", env.getStyle)
|
||||||
handleFunc("GET /source/{source}", env.getSource)
|
handleFunc("GET /source/{source}", env.getSource)
|
||||||
|
handleFunc("GET /item/{source}/{id}", env.getItem)
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(bind, nil))
|
log.Fatal(http.ListenAndServe(bind, nil))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user