Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
113 lines
1.4 KiB
Go
113 lines
1.4 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
type MarkdownLine struct {
|
|
Number int
|
|
Text string
|
|
}
|
|
|
|
func splitMarkdownLines(
|
|
body string,
|
|
) []MarkdownLine {
|
|
|
|
body =
|
|
strings.ReplaceAll(
|
|
body,
|
|
"\r\n",
|
|
"\n",
|
|
)
|
|
|
|
lines :=
|
|
strings.Split(
|
|
body,
|
|
"\n",
|
|
)
|
|
|
|
out :=
|
|
make(
|
|
[]MarkdownLine,
|
|
0,
|
|
len(lines),
|
|
)
|
|
|
|
for i, line := range lines {
|
|
|
|
out = append(
|
|
out,
|
|
MarkdownLine{
|
|
Number: i + 1,
|
|
Text: line,
|
|
},
|
|
)
|
|
}
|
|
|
|
return out
|
|
}
|
|
|
|
func (s *Server) handleMarkdownView(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
|
|
path :=
|
|
strings.TrimPrefix(
|
|
r.URL.Path,
|
|
"/v/markdown",
|
|
)
|
|
|
|
if path == "" {
|
|
path = "/"
|
|
}
|
|
|
|
if !strings.HasPrefix(path, "/") {
|
|
path = "/" + path
|
|
}
|
|
|
|
objectUUID, err :=
|
|
s.store.ResolvePathInDomain(
|
|
s.domainUUIDForRequest(r),
|
|
path,
|
|
)
|
|
|
|
if err != nil {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
|
|
markdown, err :=
|
|
s.compileMarkdownFromPath(
|
|
r,
|
|
path,
|
|
)
|
|
|
|
if err != nil {
|
|
http.Error(w, err.Error(), 500)
|
|
return
|
|
}
|
|
|
|
s.renderWithContext(
|
|
w,
|
|
r,
|
|
"markdown_view.gohtml",
|
|
map[string]any{
|
|
"NavItems": resolveNavItems(
|
|
s.getSystemNavItems(s.domainUUIDForRequest(r)),
|
|
NavContext{
|
|
Path: path,
|
|
ObjectUUID: objectUUID,
|
|
ObjectURI: "uuid:" + objectUUID,
|
|
},
|
|
),
|
|
"Path": path,
|
|
"ObjectUUID": objectUUID,
|
|
"ObjectURI": "uuid:" + objectUUID,
|
|
"Lines": splitMarkdownLines(markdown),
|
|
"MarkdownRaw": markdown,
|
|
},
|
|
)
|
|
}
|