diff options
Diffstat (limited to 'src/Render')
| -rw-r--r-- | src/Render/Render.go | 54 |
1 files changed, 41 insertions, 13 deletions
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) } |
