Added news sorting and image support
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
@ -28,18 +29,27 @@ func NewsRoute(c *fiber.Ctx) error {
|
||||
var con Content
|
||||
jsonc, err := os.ReadFile(path.Join(news_path, e.Name()))
|
||||
if err != nil {
|
||||
log.Errorf("Cannot news JSON: %s", err)
|
||||
log.Errorf("Cannot news JSON for %s: %s", e.Name(), err)
|
||||
return RenderError(c, 500)
|
||||
}
|
||||
err = json.Unmarshal(jsonc, &con)
|
||||
if err != nil {
|
||||
log.Errorf("Cannot parse news JSON: %s", err)
|
||||
log.Errorf("Cannot parse news JSON for %s: %s", e.Name(), err)
|
||||
return RenderError(c, 500)
|
||||
}
|
||||
|
||||
|
||||
con.Time, err = TimeFromString(con.Date)
|
||||
if err != nil {
|
||||
log.Errorf("Cannot parse time for '%s': %s", con.Name, err)
|
||||
}
|
||||
res = append(res, con)
|
||||
|
||||
}
|
||||
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
return res[i].Time.After(res[j].Time)
|
||||
})
|
||||
|
||||
return c.Render("news", fiber.Map{
|
||||
"news": res,
|
||||
})
|
||||
|
Reference in New Issue
Block a user