86 lines
1.0 KiB
Go
86 lines
1.0 KiB
Go
package server
|
|
|
|
import (
|
|
"html/template"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func (s *Server) handlePreview(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
|
|
path :=
|
|
strings.TrimPrefix(
|
|
r.URL.Path,
|
|
"/v/preview",
|
|
)
|
|
|
|
if path == "" {
|
|
path = "/"
|
|
}
|
|
|
|
if !strings.HasPrefix(path, "/") {
|
|
path = "/" + path
|
|
}
|
|
|
|
objectUUID, err :=
|
|
s.store.ResolvePath(
|
|
path,
|
|
)
|
|
|
|
if err == nil {
|
|
|
|
latest, err :=
|
|
s.store.GetLatestRevision(
|
|
objectUUID,
|
|
)
|
|
|
|
if err == nil &&
|
|
strings.TrimSpace(latest.Body) != "" {
|
|
|
|
rendered :=
|
|
s.renderDiagramsInHTML(
|
|
s.expandMacros(
|
|
latest.Body,
|
|
path,
|
|
),
|
|
)
|
|
|
|
s.render(
|
|
w,
|
|
"preview.gohtml",
|
|
map[string]any{
|
|
"Path": path,
|
|
"RenderedHTML": template.HTML(
|
|
rendered,
|
|
),
|
|
},
|
|
)
|
|
|
|
return
|
|
}
|
|
}
|
|
|
|
entries, err :=
|
|
s.store.ListBrowserEntries(
|
|
path,
|
|
)
|
|
|
|
if err != nil {
|
|
http.Error(w, err.Error(), 500)
|
|
return
|
|
}
|
|
|
|
s.render(
|
|
w,
|
|
"preview.gohtml",
|
|
map[string]any{
|
|
"Path": path,
|
|
"IsListing": true,
|
|
"Entries": entries,
|
|
},
|
|
)
|
|
}
|