mirror of
https://github.com/wahyd4/golink.git
synced 2026-08-08 21:01:05 +10:00
golink: add .all page to display all existing links
Signed-off-by: Gabriel Wong <gabriel@bifrost.ai>
This commit is contained in:
committed by
Will Norris
parent
789e2a8a67
commit
340adb143b
@@ -133,6 +133,7 @@ func Run() error {
|
||||
http.HandleFunc("/.export", serveExport)
|
||||
http.HandleFunc("/.help", serveHelp)
|
||||
http.HandleFunc("/.opensearch", serveOpenSearch)
|
||||
http.HandleFunc("/.all", serveAll)
|
||||
http.Handle("/.static/", http.StripPrefix("/.", http.FileServer(http.FS(embeddedFS))))
|
||||
|
||||
if *dev != "" {
|
||||
@@ -193,6 +194,9 @@ var (
|
||||
// helpTmpl is the template used by the http://go/.help page
|
||||
helpTmpl *template.Template
|
||||
|
||||
// allTmpl is the template used by the http://go/.all page
|
||||
allTmpl *template.Template
|
||||
|
||||
// opensearchTmpl is the template used by the http://go/.opensearch page
|
||||
opensearchTmpl *template.Template
|
||||
)
|
||||
@@ -213,6 +217,7 @@ func init() {
|
||||
detailTmpl = template.Must(template.ParseFS(embeddedFS, "tmpl/base.html", "tmpl/detail.html"))
|
||||
successTmpl = template.Must(template.ParseFS(embeddedFS, "tmpl/base.html", "tmpl/success.html"))
|
||||
helpTmpl = template.Must(template.ParseFS(embeddedFS, "tmpl/base.html", "tmpl/help.html"))
|
||||
allTmpl = template.Must(template.ParseFS(embeddedFS, "tmpl/base.html", "tmpl/all.html"))
|
||||
opensearchTmpl = template.Must(template.ParseFS(embeddedFS, "tmpl/opensearch.xml"))
|
||||
}
|
||||
|
||||
@@ -282,6 +287,24 @@ func serveHome(w http.ResponseWriter, short string) {
|
||||
})
|
||||
}
|
||||
|
||||
func serveAll(w http.ResponseWriter, _ *http.Request) {
|
||||
if err := flushStats(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
links, err := db.LoadAll()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
sort.Slice(links, func(i, j int) bool {
|
||||
return links[i].Short < links[j].Short
|
||||
})
|
||||
|
||||
allTmpl.Execute(w, links)
|
||||
}
|
||||
|
||||
func serveHelp(w http.ResponseWriter, _ *http.Request) {
|
||||
helpTmpl.Execute(w, nil)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
{{ define "main" }}
|
||||
<h2 class="text-xl font-bold pt-6 pb-2">All Links</h2>
|
||||
<table class="table-auto ">
|
||||
<thead class="border-b border-gray-200 uppercase text-xs text-gray-500 text-left">
|
||||
<tr>
|
||||
<th class="p-2">Link</th>
|
||||
<th class="p-2">Long</th>
|
||||
<th class="p-2">Owner</th>
|
||||
<th class="p-2">Created</th>
|
||||
<th class="p-2">Last Edit</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range . }}
|
||||
<tr class="hover:bg-gray-100 group border-b border-gray-200">
|
||||
<td class="flex">
|
||||
<a class="block flex-1 p-2 pr-4 hover:text-blue-500 hover:underline" href="/{{ .Short }}">go/{{ .Short }}</a>
|
||||
<a class="flex items-center px-2 invisible group-hover:visible" title="Link Details" href="/.detail/{{ .Short }}">
|
||||
<svg class="hover:fill-blue-500" xmlns="http://www.w3.org/2000/svg" height="1.3em" viewBox="0 0 24 24" width="1.3em" fill="#000000" stroke-width="2"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/></svg>
|
||||
</a>
|
||||
</td>
|
||||
<td class="p-2">{{ .Long }}</td>
|
||||
<td class="p-2">{{ .Owner }}</td>
|
||||
<td class="p-2">{{ .Created }}</td>
|
||||
<td class="p-2">{{ .LastEdit }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user