diff --git a/handlers/pages.go b/handlers/pages.go index 2bdb04f..abefb41 100644 --- a/handlers/pages.go +++ b/handlers/pages.go @@ -31,7 +31,7 @@ func (ph PagesHandler) New(c fiber.Ctx) error { return c.Render("pages/edit", fiber.Map{ "page": page, "isNew": true, - "bodyClass": "page-edit-page", + "bodyClass": "post-edit-page", }) } @@ -49,7 +49,7 @@ func (ph PagesHandler) Edit(c fiber.Ctx) error { return c.Render("pages/edit", fiber.Map{ "page": page, "isNew": false, - "bodyClass": "page-edit-page", + "bodyClass": "post-edit-page", }) } diff --git a/layouts/simplecss/templates/categories_single.html b/layouts/simplecss/templates/categories_single.html index e9e7116..133ad8d 100644 --- a/layouts/simplecss/templates/categories_single.html +++ b/layouts/simplecss/templates/categories_single.html @@ -11,7 +11,7 @@ {{ end }} {{ if or .PrevURL .NextURL }} {{ end }} diff --git a/layouts/simplecss/templates/posts_list.html b/layouts/simplecss/templates/posts_list.html index 6a2eca6..6a71533 100644 --- a/layouts/simplecss/templates/posts_list.html +++ b/layouts/simplecss/templates/posts_list.html @@ -8,7 +8,7 @@ {{ end }} {{ if or .PrevURL .NextURL }} {{ end }} diff --git a/providers/sitebuilder/builder.go b/providers/sitebuilder/builder.go index 93d787e..71ce926 100644 --- a/providers/sitebuilder/builder.go +++ b/providers/sitebuilder/builder.go @@ -166,14 +166,10 @@ func (b *Builder) renderPostListWithCategories(bctx buildContext, ctx context.Co var prevURL, nextURL string if page > 1 { - if page == 2 { - prevURL = "/posts/" - } else { - prevURL = fmt.Sprintf("/posts/%d/", page-1) - } + prevURL = fmt.Sprintf("%v/%d", b.opts.BasePostList, page-1) } if page < totalPages { - nextURL = fmt.Sprintf("/posts/%d/", page+1) + nextURL = fmt.Sprintf("%v/%d", b.opts.BasePostList, page+1) } pl := postListData{ @@ -187,9 +183,9 @@ func (b *Builder) renderPostListWithCategories(bctx buildContext, ctx context.Co // Page 1 renders at both root and /posts/ var paths []string if page == 1 { - paths = []string{"", "/posts"} + paths = []string{"", fmt.Sprintf("%v/1", b.opts.BasePostList)} } else { - paths = []string{fmt.Sprintf("/posts/%d", page)} + paths = []string{fmt.Sprintf("%v/%d", b.opts.BasePostList, page)} } for _, path := range paths { diff --git a/providers/sitebuilder/tmpls.go b/providers/sitebuilder/tmpls.go index a0c8e34..029cab0 100644 --- a/providers/sitebuilder/tmpls.go +++ b/providers/sitebuilder/tmpls.go @@ -32,9 +32,10 @@ const ( ) type Options struct { - BasePosts string // BasePosts is the base path for posts. - BaseUploads string // BaseUploads is the base path for uploads. - BaseStatic string // BaseStatic is the base path for static assets. + BasePosts string // BasePosts is the base path for posts. + BasePostList string // BasePostList is the base path for post lists. + BaseUploads string // BaseUploads is the base path for uploads. + BaseStatic string // BaseStatic is the base path for static assets. // TemplatesFS provides the raw templates for rendering the site. TemplatesFS fs.FS diff --git a/services/pages/service.go b/services/pages/service.go index 37c4144..8a82bc0 100644 --- a/services/pages/service.go +++ b/services/pages/service.go @@ -2,6 +2,7 @@ package pages import ( "context" + "strings" "time" "lmika.dev/lmika/weiro/models" @@ -63,6 +64,10 @@ func (s *Service) CreatePage(ctx context.Context, params CreatePageParams) (*mod slug = models.GeneratePageSlug(params.Title) } + if !strings.HasPrefix(slug, "/") { + slug = "/" + slug + } + // Check slug collision if _, err := s.db.SelectPageBySlugAndSite(ctx, site.ID, slug); err == nil { return nil, models.SlugConflictError @@ -120,6 +125,10 @@ func (s *Service) UpdatePage(ctx context.Context, id int64, params CreatePagePar slug = models.GeneratePageSlug(params.Title) } + if !strings.HasPrefix(slug, "/") { + slug = "/" + slug + } + // Check slug collision (exclude self) if existing, err := s.db.SelectPageBySlugAndSite(ctx, site.ID, slug); err == nil && existing.ID != page.ID { return nil, models.SlugConflictError diff --git a/services/publisher/service.go b/services/publisher/service.go index e6ccde3..adfcdd7 100644 --- a/services/publisher/service.go +++ b/services/publisher/service.go @@ -121,13 +121,14 @@ func (p *Publisher) publishSite(ctx context.Context, pubSite pubmodel.Site, targ } sb, err := sitebuilder.New(pubSite, sitebuilder.Options{ - BasePosts: "/posts", - BaseUploads: "/uploads", - BaseStatic: "/static", - TemplatesFS: templateFS, - StaticFS: staticFS, - FeedItems: 30, - RenderTZ: renderTZ, + BasePosts: "/posts", + BasePostList: "/pages", + BaseUploads: "/uploads", + BaseStatic: "/static", + TemplatesFS: templateFS, + StaticFS: staticFS, + FeedItems: 30, + RenderTZ: renderTZ, }) if err != nil { return err diff --git a/views/_common/nav.html b/views/_common/nav.html index ed7a1a9..e9c0de7 100644 --- a/views/_common/nav.html +++ b/views/_common/nav.html @@ -10,15 +10,15 @@