From fb2adbb65087252c0fd0392c8fa8f0218bffa22b Mon Sep 17 00:00:00 2001 From: Physcik Date: Fri, 26 Dec 2025 20:08:28 +0500 Subject: Articles idnexing --- src/Render/Render.go | 54 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) (limited to 'src/Render/Render.go') diff --git a/src/Render/Render.go b/src/Render/Render.go index bdaa51e..130789c 100644 --- a/src/Render/Render.go +++ b/src/Render/Render.go @@ -6,17 +6,14 @@ import ( "net/http" "strings" + index "physick.ru/Index" settings "physick.ru/Settings" ) type IndexTemplateContents struct { - LastArticles []recentArticle + LastArticles []index.Article Content string -} - -type recentArticle struct { - Link string - DisplayName string + Tags []index.Tag } func RegisterEndpoints() { @@ -45,17 +42,48 @@ func common(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) return } + var recentArticles, dbErr = index.GetAllArticles() + if dbErr != nil { + slog.Error("Failed to get recent articles from database", slog.Any("Error", dbErr)) + w.WriteHeader(http.StatusInternalServerError) + return + } executeIndexTemplate(IndexTemplateContents{ - LastArticles: []recentArticle { - recentArticle { - Link: "/", - DisplayName: "Index page", - }, - }, + LastArticles: recentArticles, Content: indexArticle, }, w) } func test(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, "xdx") + var requestedName = r.PathValue("name") + if len(requestedName) < 1 { + w.WriteHeader(http.StatusNotFound) + return + } + var article, dbErr = index.GetArticleByName(requestedName) + if dbErr != nil { + slog.Error("Failed to get an article from db", slog.Any("Error", dbErr)) + w.WriteHeader(http.StatusInternalServerError) + return + } + if len(article.DisplayName) < 1 { + w.WriteHeader(http.StatusNotFound) + return + } + var contents, fileErr = getTemplate(article.FileName) + if fileErr != nil { + w.WriteHeader(http.StatusNotFound) + return + } + var recentArticles, err = index.GetAllArticles() + if err != nil { + slog.Error("Failed to get recent articles from database", slog.Any("Error", err)) + w.WriteHeader(http.StatusInternalServerError) + return + } + executeIndexTemplate(IndexTemplateContents{ + LastArticles: recentArticles, + Content: contents, + Tags: article.Tags, + }, w) } -- cgit v1.3