update: general formatting and cleanup
This commit is contained in:
@ -1,69 +1,69 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sort"
|
||||
|
||||
"git.matterlinux.xyz/Matter/website/lib"
|
||||
"git.matterlinux.xyz/Matter/website/log"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func NewsRoute(c *fiber.Ctx) error {
|
||||
contents, err := lib.ListContent("news")
|
||||
if err != nil {
|
||||
log.Printf("ListContent failed: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
func GET_News(c *fiber.Ctx) error {
|
||||
contents, err := lib.ListContent("news")
|
||||
if err != nil {
|
||||
log.Error("ListContent failed: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
sort.Slice(contents, func(i, j int) bool {
|
||||
time1, err := lib.TimeFromString(contents[i].Date)
|
||||
if err != nil {
|
||||
log.Printf("Bad date while sorting: %s", err.Error())
|
||||
return false
|
||||
}
|
||||
sort.Slice(contents, func(i, j int) bool {
|
||||
time1, err := lib.TimeFromString(contents[i].Date)
|
||||
if err != nil {
|
||||
log.Error("Bad date while sorting: %s", err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
time2, err := lib.TimeFromString(contents[j].Date)
|
||||
if err != nil {
|
||||
log.Printf("Bad date while sorting: %s", err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
return time1.After(time2)
|
||||
})
|
||||
time2, err := lib.TimeFromString(contents[j].Date)
|
||||
if err != nil {
|
||||
log.Error("Bad date while sorting: %s", err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
return c.Render("news", fiber.Map{
|
||||
"news": contents,
|
||||
})
|
||||
return time1.After(time2)
|
||||
})
|
||||
|
||||
return c.Render("news", fiber.Map{
|
||||
"news": contents,
|
||||
})
|
||||
}
|
||||
|
||||
func PostRoute(c *fiber.Ctx) error {
|
||||
postid := c.Params("id")
|
||||
if len(postid) == 0 {
|
||||
return lib.RenderError(c, 404)
|
||||
}
|
||||
func GET_New(c *fiber.Ctx) error {
|
||||
postid := c.Params("id")
|
||||
if len(postid) == 0 {
|
||||
return lib.RenderError(c, 404)
|
||||
}
|
||||
|
||||
contents, err := lib.ListContent("news")
|
||||
if err != nil {
|
||||
log.Printf("ListContent failed: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
contents, err := lib.ListContent("news")
|
||||
if err != nil {
|
||||
log.Error("ListContent failed: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
for _, con := range contents {
|
||||
if(con.ID != postid) {
|
||||
continue
|
||||
}
|
||||
for _, con := range contents {
|
||||
if con.ID != postid {
|
||||
continue
|
||||
}
|
||||
|
||||
con, err = lib.GetContent(con.Dir, con.Name)
|
||||
if err != nil {
|
||||
log.Printf("ListContent failed: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
con, err = lib.GetContent(con.Dir, con.Name)
|
||||
if err != nil {
|
||||
log.Error("ListContent failed: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
return c.Render("post", fiber.Map{
|
||||
"title": con.Title,
|
||||
"post": con,
|
||||
})
|
||||
}
|
||||
return c.Render("post", fiber.Map{
|
||||
"title": con.Title,
|
||||
"post": con,
|
||||
})
|
||||
}
|
||||
|
||||
return lib.RenderError(c, 404)
|
||||
return lib.RenderError(c, 404)
|
||||
}
|
||||
|
Reference in New Issue
Block a user