Updated some settings in pages
This commit is contained in:
parent
ef038172ac
commit
5badce0d16
|
|
@ -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",
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
{{ end }}
|
||||
{{ if or .PrevURL .NextURL }}
|
||||
<nav class="pagination">
|
||||
{{ if .PrevURL }}<a href="{{ .PrevURL }}">← Newer posts</a>{{ end }}
|
||||
{{ if .NextURL }}<a href="{{ .NextURL }}">Older posts →</a>{{ end }}
|
||||
{{ if .PrevURL }}<a href="{{ url_abs .PrevURL }}">← Newer posts</a>{{ end }}
|
||||
{{ if .NextURL }}<a href="{{ url_abs .NextURL }}">Older posts →</a>{{ end }}
|
||||
</nav>
|
||||
{{ end }}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
{{ end }}
|
||||
{{ if or .PrevURL .NextURL }}
|
||||
<nav class="pagination">
|
||||
{{ if .PrevURL }}<a href="{{ .PrevURL }}">← Newer posts</a>{{ end }}
|
||||
{{ if .NextURL }}<a href="{{ .NextURL }}">Older posts →</a>{{ end }}
|
||||
{{ if .PrevURL }}<a href="{{ url_abs .PrevURL }}">← Newer posts</a>{{ end }}
|
||||
{{ if .NextURL }}<a href="{{ url_abs .NextURL }}">Older posts →</a>{{ end }}
|
||||
</nav>
|
||||
{{ end }}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ const (
|
|||
|
||||
type Options struct {
|
||||
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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ func (p *Publisher) publishSite(ctx context.Context, pubSite pubmodel.Site, targ
|
|||
|
||||
sb, err := sitebuilder.New(pubSite, sitebuilder.Options{
|
||||
BasePosts: "/posts",
|
||||
BasePostList: "/pages",
|
||||
BaseUploads: "/uploads",
|
||||
BaseStatic: "/static",
|
||||
TemplatesFS: templateFS,
|
||||
|
|
|
|||
|
|
@ -10,15 +10,15 @@
|
|||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/posts">Posts</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/categories">Categories</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/pages">Pages</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/uploads">Uploads</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/categories">Categories</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/settings">Settings</a>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<main class="container py-2">
|
||||
<main class="flex-grow-1 position-relative">
|
||||
{{ if .isNew }}
|
||||
<form method="post" action="/sites/{{ .site.ID }}/pages">
|
||||
<form method="post" class="container-fluid post-form py-2" action="/sites/{{ .site.ID }}/pages">
|
||||
{{ else }}
|
||||
<form method="post" action="/sites/{{ .site.ID }}/pages/{{ .page.ID }}">
|
||||
<form method="post" class="container-fluid post-form py-2" action="/sites/{{ .site.ID }}/pages/{{ .page.ID }}">
|
||||
{{ end }}
|
||||
<input type="hidden" name="guid" value="{{ .page.GUID }}">
|
||||
<div class="row">
|
||||
|
|
@ -10,10 +10,8 @@
|
|||
<div class="mb-2">
|
||||
<input type="text" name="title" class="form-control" placeholder="Title" value="{{ .page.Title }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<textarea name="body" class="form-control" rows="20">{{ .page.Body }}</textarea>
|
||||
</div>
|
||||
<div>
|
||||
<textarea name="body" class="form-control flex-grow-1" rows="20">{{ .page.Body }}</textarea>
|
||||
<div class="mt-2">
|
||||
<button type="submit" class="btn btn-primary">{{ if .isNew }}Create{{ else }}Save{{ end }}</button>
|
||||
{{ if not .isNew }}
|
||||
<button type="button" class="btn btn-outline-danger ms-2"
|
||||
|
|
@ -23,18 +21,11 @@
|
|||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">Page Settings</div>
|
||||
<div class="card-header">Navigation</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label for="pageSlug" class="form-label">Slug</label>
|
||||
<input type="text" class="form-control" id="pageSlug" name="slug" value="{{ .page.Slug }}">
|
||||
<div class="form-text">Auto-generated from title if left blank.</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="pageType" class="form-label">Page Type</label>
|
||||
<select class="form-select" id="pageType" name="page_type">
|
||||
<option value="0" {{ if eq .page.PageType 0 }}selected{{ end }}>Normal</option>
|
||||
</select>
|
||||
<input type="text" class="form-control" id="pageSlug" name="slug" value="{{ .page.Slug }}" placeholder="Leave blank to generate">
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="show_in_nav" value="true" id="showInNav"
|
||||
|
|
@ -43,6 +34,17 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">Page Settings</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label for="pageType" class="form-label">Page Type</label>
|
||||
<select class="form-select" id="pageType" name="page_type">
|
||||
<option value="0" {{ if eq .page.PageType 0 }}selected{{ end }}>Normal</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@
|
|||
<input type="text" name="title" class="form-control" placeholder="Title" value="{{ .post.Title }}">
|
||||
</div>
|
||||
<textarea data-postedit-target="bodyTextEdit" name="body" class="form-control flex-grow-1" rows="3">{{.post.Body}}</textarea>
|
||||
<div>
|
||||
<div class="mt-2">
|
||||
{{ if $isPublished }}
|
||||
<input type="submit" name="action" class="btn btn-primary mt-2" value="Update">
|
||||
<input type="submit" name="action" class="btn btn-primary" value="Update">
|
||||
{{ else }}
|
||||
<input type="submit" name="action" class="btn btn-primary mt-2" value="Publish">
|
||||
<input type="submit" name="action" class="btn btn-secondary mt-2" value="Save Draft">
|
||||
<input type="submit" name="action" class="btn btn-primary" value="Publish">
|
||||
<input type="submit" name="action" class="btn btn-secondary" value="Save Draft">
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue