impl. Kroki, compile path, and code-editor feature

This commit is contained in:
Anya Tokugawa committed 2026-06-18 00:06:16 +09:00
1 parent c1bc8f0c03
commit 94d56f9a8f
49 files changed
+40652 -389

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
package server
import (
"net/http"
"strings"
"pageswiki/internal/compiler"
)
func (s *Server) compileMarkdownFromPath(
path string,
) (string, error) {
objectUUID, err :=
s.store.ResolvePath(
path,
)
if err != nil {
return "", err
}
latest, err :=
s.store.GetLatestRevision(
objectUUID,
)
if err != nil {
return "", err
}
html :=
s.expandMacros(
latest.Body,
path,
)
return compiler.HTMLToMarkdown(
html,
)
}
func (s *Server) handleCompileMarkdown(
w http.ResponseWriter,
r *http.Request,
) {
path :=
strings.TrimPrefix(
r.URL.Path,
"/:/compile/markdown",
)
if path == "" {
path = "/"
}
if !strings.HasPrefix(path, "/") {
path = "/" + path
}
out, err :=
s.compileMarkdownFromPath(
path,
)
if err != nil {
http.NotFound(w, r)
return
}
w.Header().Set(
"Content-Type",
"text/markdown; charset=utf-8",
)
_, _ = w.Write(
[]byte(out),
)
}