impl. Kroki, compile path, and code-editor feature
This commit is contained in:
1 parent
c1bc8f0c03
commit
94d56f9a8f
49 files changed
+40652
-389
No files matched your search
@@ -0,0 +1,85 @@
|
||||
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,
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user