Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 42 |
1 files changed, 14 insertions, 28 deletions
@@ -11,21 +11,18 @@ import ( "github.com/SayaAndy/saya-today-web/config" "github.com/SayaAndy/saya-today-web/internal/b2" - "github.com/SayaAndy/saya-today-web/internal/factgiver" - "github.com/SayaAndy/saya-today-web/internal/glightbox" + "github.com/SayaAndy/saya-today-web/internal/lightgallery" "github.com/SayaAndy/saya-today-web/internal/router" "github.com/SayaAndy/saya-today-web/internal/tailwind" "github.com/SayaAndy/saya-today-web/locale" "github.com/dgraph-io/ristretto/v2" "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2/middleware/redirect" "github.com/golang-migrate/migrate/v4" "github.com/golang-migrate/migrate/v4/database/sqlite3" "github.com/yuin/goldmark" "github.com/yuin/goldmark/parser" - "github.com/yuin/goldmark/renderer" - "github.com/yuin/goldmark/renderer/html" - "github.com/yuin/goldmark/util" + gmhtml "github.com/yuin/goldmark/renderer/html" _ "github.com/golang-migrate/migrate/v4/source/file" _ "github.com/mattn/go-sqlite3" @@ -34,20 +31,14 @@ import ( var ( md = goldmark.New( goldmark.WithExtensions( - glightbox.NewGLightboxExtension(), + lightgallery.NewLightGalleryExtension(), tailwind.NewTailwindExtension(), ), goldmark.WithParserOptions( parser.WithAutoHeadingID(), - parser.WithAttribute(), ), - goldmark.WithRenderer( - renderer.NewRenderer( - renderer.WithNodeRenderers( - util.Prioritized(tailwind.NewCustomLinkRenderer(html.WithUnsafe(), html.WithXHTML()), 50), - util.Prioritized(html.NewRenderer(html.WithXHTML()), 100), - ), - ), + goldmark.WithRendererOptions( + gmhtml.WithXHTML(), ), ) b2Client *b2.B2Client @@ -116,10 +107,12 @@ func main() { ProxyHeader: "X-Forwarded-For", }) - app.Use(cors.New(cors.Config{ - AllowOrigins: "https://f003.backblazeb2.com", - AllowMethods: "GET,POST,OPTIONS", - AllowHeaders: "Origin, Content-Type, Accept", + app.Use(redirect.New(redirect.Config{ + Rules: map[string]string{ + "/ru": "/", + "/en": "/", + }, + StatusCode: 301, })) router.CCache, err = router.NewClientCache(db, []byte(cfg.Auth.Salt)) @@ -138,17 +131,10 @@ func main() { os.Exit(1) } - router.FactGiver, err = factgiver.NewFactGiver(&cfg.FactGiver, availableLanguages) - if err != nil { - slog.Error("fail to initialize fact giver", slog.String("error", err.Error())) - os.Exit(1) - } - app.Get("/", router.Root(cfg.AvailableLanguages)) - app.Get("/:lang<len(2)>", router.Api_V1_GeneralPage(localization, availableLanguages)) app.Get("/:lang/map", router.Lang_Map(localization, availableLanguages, b2Client)) - app.Get("/:lang/blog", router.Api_V1_GeneralPage(localization, availableLanguages)) - app.Get("/:lang/blog/:title", router.Api_V1_GeneralPage(localization, availableLanguages)) + app.Get("/:lang/blog", router.Lang_Blog(localization, availableLanguages, b2Client)) + app.Get("/:lang/blog/:title", router.Lang_Blog_Title(localization, availableLanguages, b2Client, md)) app.Get("/api/v1/tz", router.Api_V1_TZ()) app.Get("/api/v1/blog-search", router.Api_V1_BlogSearch(localization, availableLanguages, b2Client)) |