diff --git a/internal/theme/common/detail.go b/internal/theme/common/detail.go index 0c0df21..777f713 100644 --- a/internal/theme/common/detail.go +++ b/internal/theme/common/detail.go @@ -4,7 +4,6 @@ import ( "fmt" str "github.com/fthvgb1/wp-go/helper/strings" "github.com/fthvgb1/wp-go/internal/pkg/cache" - "github.com/fthvgb1/wp-go/internal/pkg/constraints" "github.com/fthvgb1/wp-go/internal/pkg/logs" "github.com/fthvgb1/wp-go/internal/pkg/models" "github.com/fthvgb1/wp-go/internal/plugins" @@ -26,7 +25,6 @@ func (d *DetailHandle) BuildDetailData() (err error) { d.GinH["title"] = wpconfig.Options.Value("blogname") err = d.CheckAndGetPost() if err != nil { - d.Scene = constraints.Error404 return } d.WidgetAreaData() @@ -41,12 +39,10 @@ func (d *DetailHandle) CheckAndGetPost() (err error) { maxId, err := cache.GetMaxPostId(d.C) logs.ErrPrintln(err, "get max post id") if id > maxId || id <= 0 || err != nil { - d.Stats = constraints.Error404 return } post, err := cache.GetPostById(d.C, id) if post.Id == 0 || err != nil || post.PostStatus != "publish" { - d.Stats = constraints.Error404 return } diff --git a/internal/theme/common/index.go b/internal/theme/common/index.go index 2cdeb8c..c2f7992 100644 --- a/internal/theme/common/index.go +++ b/internal/theme/common/index.go @@ -11,7 +11,6 @@ import ( "github.com/fthvgb1/wp-go/internal/pkg/models" "github.com/fthvgb1/wp-go/model" "github.com/fthvgb1/wp-go/plugin/pagination" - "net/http" ) func (i *IndexHandle) ParseIndex(parm *IndexParams) (err error) { @@ -76,14 +75,10 @@ func (i *IndexHandle) Pagination() { func (i *IndexHandle) BuildIndexData(parm *IndexParams) (err error) { err = i.ParseIndex(parm) if err != nil { - i.Stats = constraints.ParamError - i.Code = http.StatusNotFound return } posts, totalRows, err := i.GetIndexData() if err != nil && err != sql.ErrNoRows { - i.Scene = constraints.InternalErr - i.Code = http.StatusInternalServerError return } i.GinH["posts"] = posts diff --git a/internal/theme/twentyfifteen/twentyfifteen.go b/internal/theme/twentyfifteen/twentyfifteen.go index 4eabddb..00fa1f0 100644 --- a/internal/theme/twentyfifteen/twentyfifteen.go +++ b/internal/theme/twentyfifteen/twentyfifteen.go @@ -4,6 +4,7 @@ import ( "github.com/fthvgb1/wp-go/internal/pkg/constraints" "github.com/fthvgb1/wp-go/internal/plugins" "github.com/fthvgb1/wp-go/internal/theme/common" + "net/http" ) const ThemeName = "twentyfifteen" @@ -39,6 +40,8 @@ func (i *indexHandle) Index() { err := i.BuildIndexData(common.NewIndexParams(i.C)) if err != nil { + i.Stats = constraints.Error404 + i.Code = http.StatusNotFound i.C.HTML(i.Code, i.Templ, i.GinH) return } @@ -54,6 +57,7 @@ func (d *detailHandle) Detail() { err := d.BuildDetailData() if err != nil { d.Stats = constraints.Error404 + d.Code = http.StatusNotFound d.C.HTML(d.Code, d.Templ, d.GinH) return } diff --git a/internal/theme/twentyseventeen/twentyseventeen.go b/internal/theme/twentyseventeen/twentyseventeen.go index 7f11740..291b229 100644 --- a/internal/theme/twentyseventeen/twentyseventeen.go +++ b/internal/theme/twentyseventeen/twentyseventeen.go @@ -73,27 +73,31 @@ var pluginFns = func() map[string]common.Plugin[models.Posts] { func (i *indexHandle) Index() { i.Templ = "twentyseventeen/posts/index.gohtml" - p := common.NewIndexParams(i.C) - err := i.BuildIndexData(p) - i.GinH["bodyClass"] = i.h.bodyClass() + err := i.BuildIndexData(common.NewIndexParams(i.C)) if err != nil { + i.Stats = constraints.Error404 + i.Code = http.StatusNotFound + i.GinH["bodyClass"] = i.h.bodyClass() i.C.HTML(i.Code, i.Templ, i.GinH) return } i.PageEle = paginate i.ExecListPagePlugin(pluginFns) i.Pagination() + i.GinH["bodyClass"] = i.h.bodyClass() i.C.HTML(i.Code, i.Templ, i.GinH) } func (d *detailHandle) Detail() { err := d.BuildDetailData() - d.GinH["bodyClass"] = d.h.bodyClass() if err != nil { d.Code = http.StatusNotFound + d.Stats = constraints.Error404 + d.GinH["bodyClass"] = d.h.bodyClass() d.C.HTML(d.Code, d.Templ, d.GinH) return } + d.GinH["bodyClass"] = d.h.bodyClass() img := plugins.Thumbnail(d.Post.Thumbnail.OriginAttachmentData, "thumbnail", "", "thumbnail", "post-thumbnail") img.Width = img.OriginAttachmentData.Width img.Height = img.OriginAttachmentData.Height