diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/router/handlers/root.go | 4 | ||||
| -rw-r--r-- | internal/router/router.go | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/internal/router/handlers/root.go b/internal/router/handlers/root.go index f188a61..cd01fcd 100644 --- a/internal/router/handlers/root.go +++ b/internal/router/handlers/root.go @@ -37,14 +37,14 @@ func (r *RootHandler) CacheDuration() time.Duration { } func (r *RootHandler) SitemapInfo(_ *router.Supplements) []router.SitemapInfo { - return []router.SitemapInfo{{Loc: "", Priority: 0.7}} + return []router.SitemapInfo{{Loc: "/", Priority: 0.7}} } func (r *RootHandler) AddMeta(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (meta []router.MetaField, err error) { return []router.MetaField{ {Property: "og:title", Content: "Saya Blog"}, {Property: "og:description", Content: "The blog of a 25 years old, travelling God knows where, proud to be not mainstream // Личный блог 25-летки, странствующего по ебеням, зато не мейнстрим"}, - {Property: "og:url", Content: fmt.Sprint(templateMap["CanonicalEndpoint"])}, + {Property: "og:url", Content: fmt.Sprint(templateMap["CanonicalEndpoint"]) + "/"}, {Property: "og:type", Content: "website"}, }, nil } diff --git a/internal/router/router.go b/internal/router/router.go index 1b490d8..3ce7e3b 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -21,7 +21,9 @@ import ( "github.com/SayaAndy/saya-today-web/locale" "github.com/dgraph-io/ristretto/v2" "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/compress" "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2/middleware/etag" "github.com/golang-migrate/migrate/v4" "github.com/golang-migrate/migrate/v4/database/sqlite3" "github.com/yuin/goldmark" @@ -226,6 +228,20 @@ func NewRouter(cfg *config.Config) (*Router, error) { AllowHeaders: "Origin, Content-Type, Accept", })) + app.Use(compress.New(compress.Config{ + Level: compress.LevelBestSpeed, + })) + + app.Use(etag.New()) + + app.Use(func(c *fiber.Ctx) error { + path := c.Path() + if len(path) > 1 && path[len(path)-1] == '/' { + return c.Redirect(strings.TrimRight(path, "/"), fiber.StatusMovedPermanently) + } + return c.Next() + }) + templatedRoutes := make(map[string]map[string]Route) templatedPathMatcher := NewPathMatcher() |