From 682ec9cd1498f58151bef765e1247fed690ab252 Mon Sep 17 00:00:00 2001 From: Physcik Date: Fri, 26 Dec 2025 16:29:44 +0500 Subject: Render start --- src/Render/Render.go | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'src/Render/Render.go') diff --git a/src/Render/Render.go b/src/Render/Render.go index f9b702b..bdaa51e 100644 --- a/src/Render/Render.go +++ b/src/Render/Render.go @@ -9,10 +9,19 @@ import ( settings "physick.ru/Settings" ) -const indexTemplateName string = "index.html" +type IndexTemplateContents struct { + LastArticles []recentArticle + Content string +} + +type recentArticle struct { + Link string + DisplayName string +} func RegisterEndpoints() { // http.Handle("static/", http.FileServer(http.FS(os.DirFS(settings.Current.StaticLocation)))) + http.HandleFunc("/articles/{name}", test) http.HandleFunc("/", mux) } @@ -26,16 +35,27 @@ func mux(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, filePath) return } - render(w, r) + common(w, r) } -func render(w http.ResponseWriter, r *http.Request) { - var indexTempl, readErr = getTemplateString(indexTemplateName) - if readErr != nil { - slog.Warn("Failed to load template", slog.Any("Error", readErr)) +func common(w http.ResponseWriter, r *http.Request) { + var indexArticle, indexErr = getTemplate("index.html") + if indexErr != nil { + slog.Error("Failed to parse the template", slog.Any("Error", indexErr)) w.WriteHeader(http.StatusInternalServerError) return } - // slog.Info("Requested a template") - w.Write([]byte(indexTempl)) + executeIndexTemplate(IndexTemplateContents{ + LastArticles: []recentArticle { + recentArticle { + Link: "/", + DisplayName: "Index page", + }, + }, + Content: indexArticle, + }, w) +} + +func test(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, "xdx") } -- cgit v1.3