- commit
- eb7176f
- parent
- ee1b0c7
- author
- Eric Bower
- date
- 2024-03-19 15:34:21 +0000 UTC
fix(prose): use image mimetype if file ext provided Closes: #104
2 files changed,
+5,
-4
+3,
-2
1@@ -201,17 +201,18 @@ func ImgRequest(w http.ResponseWriter, r *http.Request) {
2 return
3 }
4
5+
6 // set default quality for web optimization
7 if opts.Quality == 0 {
8 opts.Quality = 80
9 }
10
11+ ext := filepath.Ext(slug)
12 // set default format to be webp
13- if opts.Ext == "" {
14+ if opts.Ext == "" && ext == "" {
15 opts.Ext = "webp"
16 }
17
18- ext := filepath.Ext(slug)
19 // Files can contain periods. `filepath.Ext` is greedy and will clip the last period in the slug
20 // and call that a file extension so we want to be explicit about what
21 // file extensions we clip here
+2,
-2
1@@ -856,7 +856,7 @@ func createMainRoutes(staticRoutes []shared.Route) []shared.Route {
2 shared.NewRoute("GET", "/([^/]+)/_styles.css", blogStyleHandler),
3 shared.NewRoute("GET", "/raw/([^/]+)/(.+)", postRawHandler),
4 shared.NewRoute("GET", "/([^/]+)/(.+)/(.+)", imgs.ImgRequest),
5- shared.NewRoute("GET", "/([^/]+)/(.+).(?:jpg|jpeg|png|gif|webp|svg)$", imgs.ImgRequest),
6+ shared.NewRoute("GET", "/([^/]+)/(.+.(?:jpg|jpeg|png|gif|webp|svg))$", imgs.ImgRequest),
7 shared.NewRoute("GET", "/([^/]+)/i", imgs.ImgsListHandler),
8 shared.NewRoute("GET", "/([^/]+)/(.+)", postHandler),
9 )
10@@ -885,7 +885,7 @@ func createSubdomainRoutes(staticRoutes []shared.Route) []shared.Route {
11 routes,
12 shared.NewRoute("GET", "/raw/(.+)", postRawHandler),
13 shared.NewRoute("GET", "/([^/]+)/(.+)", imgs.ImgRequest),
14- shared.NewRoute("GET", "/(.+).(?:jpg|jpeg|png|gif|webp|svg)$", imgs.ImgRequest),
15+ shared.NewRoute("GET", "/(.+.(?:jpg|jpeg|png|gif|webp|svg))$", imgs.ImgRequest),
16 shared.NewRoute("GET", "/i", imgs.ImgsListHandler),
17 shared.NewRoute("GET", "/(.+)", postHandler),
18 )