performance: thumbnails are now forced to be saved in jpeg format

This commit is contained in:
Tigor Hutasuhut 2024-05-05 23:28:29 +07:00
parent 3fcf291e6d
commit 42646c601d
4 changed files with 16 additions and 2 deletions

View file

@ -294,6 +294,9 @@ func (post *Post) GetThumbnailTargetPath(cfg *config.Config) string {
baseDownloadDir := cfg.String("download.directory")
p := path.Join(baseDownloadDir, "_thumbnails", post.GetSubreddit(), post.GetImageFilename())
abs, _ := filepath.Abs(p)
if before, found := strings.CutSuffix(abs, ".png"); found {
return before + ".jpeg"
}
return abs
}
@ -305,7 +308,11 @@ func (post *Post) GetThumbnailTargetDir(cfg *config.Config) string {
}
func (post *Post) GetThumbnailRelativePath() string {
return path.Join("_thumbnails", post.GetSubreddit(), post.GetImageFilename())
p := path.Join("_thumbnails", post.GetSubreddit(), post.GetImageFilename())
if before, found := strings.CutSuffix(p, ".png"); found {
return before + ".jpeg"
}
return p
}
func (post *Post) GetImageRelativePath(device *models.Device) string {

View file

@ -1,6 +1,7 @@
package routes
import (
"fmt"
"net/http"
"github.com/go-chi/chi/v5"
@ -32,6 +33,7 @@ func (routes *Routes) PageSubredditsDetails(rw http.ResponseWriter, r *http.Requ
code, message := errs.HTTPMessage(err)
rw.WriteHeader(code)
data.Error = message
fmt.Println(data)
if err := detailsview.Detailsview(c, data).Render(ctx, rw); err != nil {
log.New(ctx).Err(err).Error("failed to render subreddit details page")
}

View file

@ -27,6 +27,7 @@ templ ImageCard(data *models.Image, opts ImageCardOption) {
class="object-contain max-w-[16rem] max-h-[16rem]"
src={ fmt.Sprintf("/img/%s", data.ThumbnailRelativePath) }
alt={ data.PostTitle }
loading="lazy"
/>
</a>
</figure>

View file

@ -17,7 +17,11 @@ type Data struct {
templ Detailsview(c *views.Context, data Data) {
@components.Doctype() {
if data.Subreddit != nil {
@components.Head(c, components.HeadTitle(fmt.Sprintf("Subreddit - %s", data.Subreddit.Name)))
} else {
@components.Head(c, components.HeadTitle("Subreddit - 404 NOT FOUND"))
}
@components.Body(c) {
@DetailsContent(c, data)
@components.NotificationContainer()