commit 84ebf0972de11d77187b90ac4866016638088bbe
parent 096c39b25bc16399798718a1bea50ac4b7f434e8
Author: vx-clutch <[email protected]>
Date: Sat, 13 Dec 2025 18:54:48 -0500
Merge branch 'main' of https://git.vxserver.dev/fsd/fes
Diffstat:
3 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/examples/markdown/Fes.toml b/examples/markdown/Fes.toml
@@ -0,0 +1,5 @@
+[app]
+
+name = "markdown"
+version = "0.0.1"
+authors = ["vx-clutch"]
+\ No newline at end of file
diff --git a/examples/markdown/www/index.md b/examples/markdown/www/index.md
@@ -0,0 +1 @@
+# Hello, World!
diff --git a/src/server/server.go b/src/server/server.go
@@ -50,6 +50,14 @@ func handleDir(entries []os.DirEntry, dir string, routes map[string]string, base
continue
}
route = joinBase(base, name)
+ } else if !isStatic && strings.HasSuffix(entry.Name(), ".md") {
+ name := strings.TrimSuffix(entry.Name(), ".md")
+ if name == "index" {
+ routes[basePath(base)] = path
+ routes[route] = path
+ continue
+ }
+ route = joinBase(base, name)
}
routes[route] = path
}
@@ -64,7 +72,7 @@ func joinBase(base, name string) string {
}
func basePath(base string) string {
- if base == "" {
+ if base == "" || base == "." {
return "/"
}
return base
@@ -401,7 +409,8 @@ func Start(dir string) error {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
- lp, ok := routes[path]
+ p, ok := routes[path]
+ fmt.Printf("> %s ", basePath(filepath.Base(p)))
if !ok && strings.HasPrefix(path, "/archive") {
fsPath := "." + path
@@ -417,7 +426,6 @@ func Start(dir string) error {
if !ok {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(notFoundData))
- fmt.Printf("> %s ", path)
color.Yellow("not found")
return
}
@@ -434,17 +442,18 @@ func Start(dir string) error {
params: params,
}
- fmt.Printf("> %s ", filepath.Base(lp))
-
var data []byte
var err error
- if strings.HasSuffix(lp, ".lua") {
+ if strings.HasSuffix(p, ".lua") {
var b string
- b, err = loadLua(dir, lp, &cfg, req)
+ b, err = loadLua(dir, p, &cfg, req)
data = []byte(b)
+ } else if strings.HasSuffix(p, ".md") {
+ data, err = os.ReadFile(p)
+ data = []byte(markdownToHTML(string(data)))
} else {
- data, err = os.ReadFile(lp)
+ data, err = os.ReadFile(p)
}
if err != nil {
@@ -453,8 +462,8 @@ func Start(dir string) error {
return
}
- color.Green("ok")
w.Write(data)
+ color.Green("ok")
})
fmt.Printf("Server is running on http://localhost:%d\n", *config.Port)