From d2277b1f9b17e61456cd312ef54542e1cfa81a40 Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Wed, 27 Oct 2021 18:18:06 -0300 Subject: restructuring, part 1 of many --- routes/index.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'routes/index.go') diff --git a/routes/index.go b/routes/index.go index ccd398b..df10d9f 100644 --- a/routes/index.go +++ b/routes/index.go @@ -1,7 +1,51 @@ package routes -import "github.com/gofiber/fiber/v2" +import ( + "github.com/FChannel0/FChannel-Server/config" + "github.com/FChannel0/FChannel-Server/db" + "github.com/gofiber/fiber/v2" +) func Index(c *fiber.Ctx) error { - return c.SendString("index") + actor, err := db.GetActor(config.Domain) + if err != nil { + return err + } + + var data PageData + data.Title = "Welcome to " + actor.PreferredUsername + data.PreferredUsername = actor.PreferredUsername + data.Boards = Boards + data.Board.Name = "" + data.Key = *Key + data.Board.Domain = config.Domain + data.Board.ModCred, _ = GetPasswordFromCtx(c) + data.Board.Actor = actor + data.Board.Post.Actor = actor.Id + data.Board.Restricted = actor.Restricted + //almost certainly there is a better algorithm for this but the old one was wrong + //and I suck at math. This works at least. + data.BoardRemainer = make([]int, 3-(len(data.Boards)%3)) + if len(data.BoardRemainer) == 3 { + data.BoardRemainer = make([]int, 0) + } + + col := GetCollectionFromReq("https://fchan.xyz/followers") + + if len(col.Items) > 0 { + data.InstanceIndex = col.Items + } + + data.NewsItems, err = db.GetNewsFromDB(3) + if err != nil { + return err + } + + data.Themes = &Themes + + data.ThemeCookie = getThemeCookie(c) + + return c.Render("index", fiber.Map{ + "page": data, + }, "layouts/main") } -- cgit v1.2.3