diff --git a/cmd/warehost-web/handler.go b/cmd/warehost-web/handler.go index 80795b1..3503592 100644 --- a/cmd/warehost-web/handler.go +++ b/cmd/warehost-web/handler.go @@ -8,6 +8,8 @@ import ( "strings" "text/template" + "github.com/jinzhu/gorm" + liblog "dev.sum7.eu/sum7/warehost/lib/log" web "dev.sum7.eu/sum7/warehost/modul/web" ) @@ -106,9 +108,11 @@ func handlerfunc(w http.ResponseWriter, r *http.Request) { if !dbconnection.Where(page).First(&page).RecordNotFound() { page.URL = urlObj } else { - if !dbconnection.Where(blog).Preload("Posts").First(&blog).RecordNotFound() { + if !dbconnection.Where(blog).Preload("Posts", func(db *gorm.DB) *gorm.DB { + return db.Order("createat DESC") + }).First(&blog).RecordNotFound() { blogpost.BlogID = blog.ID - if urlObj.Path != blogpost.Title && ((blog.PostURL == 0 && len(urlParts) > 1) || (blog.PostURL == 1 && len(urlParts) > 2)) { + if (blog.PostURL == 0 && len(urlParts) > 1) || (blog.PostURL == 1 && len(urlParts) > 2) { db := dbconnection.Where(blogpost).Where("LOWER(title) = LOWER(?)", urlParts[len(urlParts)-1]) if blog.PostURL == 1 { db = db.Where("to_char(createat,'YYYY-MM') = ?", strings.Join(urlParts[len(urlParts)-3:len(urlParts)-1], "-"))