Trending page (#128)

Fixes #46

Reviewed-on: https://codeberg.org/rimgo/rimgo/pulls/128
Co-authored-by: orangix <orangix@noreply.codeberg.org>
Co-committed-by: orangix <orangix@noreply.codeberg.org>
This commit is contained in:
orangix
2023-08-14 22:47:59 +00:00
committed by video-prize-ranch
parent d69d8dba0e
commit a8abb43f3a
6 changed files with 255 additions and 8 deletions

17
main.go
View File

@@ -24,7 +24,7 @@ func main() {
envPath := flag.String("c", ".env", "Path to env file")
godotenv.Load(*envPath)
utils.LoadConfig()
pages.InitializeApiClient()
views := http.FS(views.GetFiles())
@@ -32,7 +32,7 @@ func main() {
views = http.Dir("./views")
}
engine := handlebars.NewFileSystem(views, ".hbs")
engine.AddFunc("noteq", func(a interface{}, b interface{}, options *raymond.Options) interface{} {
if raymond.Str(a) != raymond.Str(b) {
return options.Fn()
@@ -69,11 +69,11 @@ func main() {
fmt.Println(e)
},
}))
if os.Getenv("ENV") == "dev" {
app.Use("/static", filesystem.New(filesystem.Config{
MaxAge: 2592000,
Root: http.Dir("./static"),
Root: http.Dir("./static"),
}))
app.Get("/errors/429", func(c *fiber.Ctx) error {
return c.Render("errors/429", nil)
@@ -91,11 +91,11 @@ func main() {
Root: http.FS(static.GetFiles()),
}))
app.Use(cache.New(cache.Config{
Expiration: 30 * time.Minute,
MaxBytes: 25000000,
Expiration: 30 * time.Minute,
MaxBytes: 25000000,
KeyGenerator: func(c *fiber.Ctx) string {
return c.OriginalURL()
},
return c.OriginalURL()
},
CacheControl: true,
StoreResponseHeaders: true,
}))
@@ -116,6 +116,7 @@ func main() {
app.Get("/about", pages.HandleAbout)
app.Get("/privacy", pages.HandlePrivacy)
app.Get("/search", pages.HandleSearch)
app.Get("/trending", pages.HandleTrending)
app.Get("/a/:postID", pages.HandlePost)
app.Get("/a/:postID/embed", pages.HandleEmbed)
app.Get("/t/:tag", pages.HandleTag)