172 lines
2.2 KiB
Go
172 lines
2.2 KiB
Go
package server
|
|
|
|
import (
|
|
"html/template"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func (s *Server) handleSemanticRoute(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
|
|
path := r.URL.Path
|
|
|
|
objectUUID, err :=
|
|
s.store.ResolvePath(path)
|
|
|
|
if err != nil {
|
|
|
|
http.NotFound(w, r)
|
|
|
|
return
|
|
}
|
|
|
|
latest, err :=
|
|
s.store.GetLatestRevision(
|
|
objectUUID,
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(
|
|
w,
|
|
err.Error(),
|
|
500,
|
|
)
|
|
|
|
return
|
|
}
|
|
|
|
bs := buildBreadcrumbs(path)
|
|
|
|
rendered :=
|
|
s.renderDiagramsInHTML(
|
|
s.expandMacros(
|
|
latest.Body,
|
|
path,
|
|
),
|
|
)
|
|
|
|
s.render(
|
|
w,
|
|
"page.gohtml",
|
|
map[string]any{
|
|
"Title": path,
|
|
"Path": path,
|
|
"Breadcrumbs": bs,
|
|
"ObjectUUID": objectUUID,
|
|
"NavItems": resolveNavItems(
|
|
s.getSystemNavItems(),
|
|
NavContext{
|
|
Path: path,
|
|
ObjectUUID: objectUUID,
|
|
ObjectURI: "uuid:" + objectUUID,
|
|
},
|
|
),
|
|
"RenderedHTML": template.HTML(
|
|
rendered,
|
|
),
|
|
},
|
|
)
|
|
}
|
|
|
|
func (s *Server) handleSemanticEditor(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
|
|
path := strings.TrimPrefix(
|
|
r.URL.Path,
|
|
"/e/-",
|
|
)
|
|
|
|
if path == "" {
|
|
path = "/"
|
|
}
|
|
|
|
objectUUID, err :=
|
|
s.store.ResolvePath(path)
|
|
|
|
if err != nil {
|
|
|
|
objectUUID, err =
|
|
s.store.CreateObject(path)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(
|
|
w,
|
|
err.Error(),
|
|
500,
|
|
)
|
|
|
|
return
|
|
}
|
|
}
|
|
|
|
latest, err :=
|
|
s.store.GetLatestRevision(
|
|
objectUUID,
|
|
)
|
|
|
|
body := ""
|
|
|
|
if err == nil {
|
|
body = latest.Body
|
|
}
|
|
|
|
editType :=
|
|
r.URL.Query().Get(
|
|
"edittype",
|
|
)
|
|
|
|
if editType == "" {
|
|
editType = "html"
|
|
}
|
|
|
|
if editType == "markdown" {
|
|
|
|
compiled, err :=
|
|
s.compileMarkdownFromPath(
|
|
path,
|
|
)
|
|
|
|
if err != nil {
|
|
http.Error(
|
|
w,
|
|
err.Error(),
|
|
500,
|
|
)
|
|
return
|
|
}
|
|
|
|
body = compiled
|
|
}
|
|
|
|
renderedBody :=
|
|
body
|
|
|
|
s.render(
|
|
w,
|
|
"editor.gohtml",
|
|
map[string]any{
|
|
"Title": path,
|
|
"Path": path,
|
|
"ObjectUUID": objectUUID,
|
|
"Body": body,
|
|
"RenderedHTML": template.HTML(
|
|
s.expandMacros(
|
|
renderedBody,
|
|
path,
|
|
),
|
|
),
|
|
"EditType": editType,
|
|
"EditorKeymap": s.getEditorKeymap(),
|
|
"EditorSyntax": s.getEditorSyntaxHighlight(),
|
|
"EditorAutocomplete": s.getEditorAutocomplete(),
|
|
},
|
|
)
|
|
}
|