From 418599259793ec46122ec911bda4d7071f1b2dac Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 5 Feb 2023 04:41:11 +0400 Subject: [PATCH] Wrote a sane Article handling. Added a mockup for mindflow. --- internal/http/handlers.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/internal/http/handlers.go b/internal/http/handlers.go index 9c4082c..b0a5b22 100644 --- a/internal/http/handlers.go +++ b/internal/http/handlers.go @@ -5,6 +5,7 @@ import ( "strings" "time" + "git.arav.top/Arav/dwelling-home/pkg/mindflow" "git.arav.top/Arav/dwelling-home/web" ) @@ -36,7 +37,10 @@ func (h *Handlers) Stuff(w http.ResponseWriter, r *http.Request) { } func (h *Handlers) Mindflow(w http.ResponseWriter, r *http.Request) { - web.Mindflow("/ Mindflow", nil, r, w) + posts := []mindflow.Post{ + {Category: "Kek", Date: time.Now(), Title: "LMAO", Body: "Testing!"}, + } + web.Mindflow("/ Mindflow", posts, r, w) } func (h *Handlers) About(w http.ResponseWriter, r *http.Request) { @@ -44,19 +48,14 @@ func (h *Handlers) About(w http.ResponseWriter, r *http.Request) { } func (h *Handlers) Article(w http.ResponseWriter, r *http.Request) { - if strings.HasSuffix(r.URL.Path, "hardening_mikrotik") { - web.ArticleHardeningMikrotik("/ Article / Hardening Mikrotik", w) - } else if strings.HasSuffix(r.URL.Path, "nginx_recipes_and_tips") { - web.ArticleNginxRecipesAndTips("/ Article / NGiNX's recipes & tips", w) - } else if strings.HasSuffix(r.URL.Path, "setting_up_a_mail_server") { - web.ArticleSettingUpAMailServer("/ Article / Setting up a mail server", w) - } else if strings.HasSuffix(r.URL.Path, "setting_up_a_tor_proxy_relay_hiddenserv") { - web.ArticleSettingUpATorProxyRelayHiddenserv("/ Article / Setting up a Tor proxy, relay and hidden service", w) - } else if strings.HasSuffix(r.URL.Path, "rpi_root_on_external_drive") { - web.ArticleSettingUpATorProxyRelayHiddenserv("/ Article / How to move a root partition from SD card off to external drive on Raspberry Pi", w) - } else { + name := r.URL.Path[strings.LastIndex(r.URL.Path, "/")+1:] + artcl, err := web.GetArticle(name) + if err != nil { + http.Error(w, err.Error(), http.StatusNotFound) return } + + web.Article(artcl.Title, artcl.Description, string(artcl.Body), artcl.Date, r.Host, name, r, w) } func (h *Handlers) RSS(w http.ResponseWriter, r *http.Request) {