aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/main.go b/main.go
index 55f866e..3d6411d 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "bytes"
"context"
"encoding/json"
"flag"
@@ -10,6 +11,10 @@ import (
"os/signal"
"time"
+ "github.com/alecthomas/chroma/v2/formatters/html"
+ "github.com/alecthomas/chroma/v2/lexers"
+ "github.com/alecthomas/chroma/v2/styles"
+
"git.gabrielgio.me/cerrado/pkg/config"
"git.gabrielgio.me/cerrado/pkg/worker"
"git.gabrielgio.me/cerrado/templates"
@@ -33,6 +38,7 @@ func run(ctx context.Context) error {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
+ slog.Info("Handling index")
f, err := os.Open(*configPath)
if err != nil {
@@ -52,8 +58,26 @@ func run(ctx context.Context) error {
return
}
+ lexer := lexers.Get("json")
+ style := styles.Get("monokailight")
+ formatter := html.New(
+ html.WithLineNumbers(true),
+ )
+ iterator, err := lexer.Tokenise(nil, string(b))
+ if err != nil {
+ slog.Error("Error tokenise", "error", err)
+ return
+ }
+
+ var code bytes.Buffer
+ err = formatter.Format(&code, style, iterator)
+ if err != nil {
+ slog.Error("Error format", "error", err)
+ return
+ }
+
hello := &templates.HelloPage{
- Body: string(b),
+ Body: code.String(),
}
templates.WritePageTemplate(w, hello)