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{
|
return c.Render("pages/edit", fiber.Map{
|
||||||
"page": page,
|
"page": page,
|
||||||
"isNew": true,
|
"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{
|
return c.Render("pages/edit", fiber.Map{
|
||||||
"page": page,
|
"page": page,
|
||||||
"isNew": false,
|
"isNew": false,
|
||||||
"bodyClass": "page-edit-page",
|
"bodyClass": "post-edit-page",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if or .PrevURL .NextURL }}
|
{{ if or .PrevURL .NextURL }}
|
||||||
<nav class="pagination">
|
<nav class="pagination">
|
||||||
{{ if .PrevURL }}<a href="{{ .PrevURL }}">← Newer posts</a>{{ end }}
|
{{ if .PrevURL }}<a href="{{ url_abs .PrevURL }}">← Newer posts</a>{{ end }}
|
||||||
{{ if .NextURL }}<a href="{{ .NextURL }}">Older posts →</a>{{ end }}
|
{{ if .NextURL }}<a href="{{ url_abs .NextURL }}">Older posts →</a>{{ end }}
|
||||||
</nav>
|
</nav>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if or .PrevURL .NextURL }}
|
{{ if or .PrevURL .NextURL }}
|
||||||
<nav class="pagination">
|
<nav class="pagination">
|
||||||
{{ if .PrevURL }}<a href="{{ .PrevURL }}">← Newer posts</a>{{ end }}
|
{{ if .PrevURL }}<a href="{{ url_abs .PrevURL }}">← Newer posts</a>{{ end }}
|
||||||
{{ if .NextURL }}<a href="{{ .NextURL }}">Older posts →</a>{{ end }}
|
{{ if .NextURL }}<a href="{{ url_abs .NextURL }}">Older posts →</a>{{ end }}
|
||||||
</nav>
|
</nav>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
||||||
|
|
@ -166,14 +166,10 @@ func (b *Builder) renderPostListWithCategories(bctx buildContext, ctx context.Co
|
||||||
|
|
||||||
var prevURL, nextURL string
|
var prevURL, nextURL string
|
||||||
if page > 1 {
|
if page > 1 {
|
||||||
if page == 2 {
|
prevURL = fmt.Sprintf("%v/%d", b.opts.BasePostList, page-1)
|
||||||
prevURL = "/posts/"
|
|
||||||
} else {
|
|
||||||
prevURL = fmt.Sprintf("/posts/%d/", page-1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if page < totalPages {
|
if page < totalPages {
|
||||||
nextURL = fmt.Sprintf("/posts/%d/", page+1)
|
nextURL = fmt.Sprintf("%v/%d", b.opts.BasePostList, page+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pl := postListData{
|
pl := postListData{
|
||||||
|
|
@ -187,9 +183,9 @@ func (b *Builder) renderPostListWithCategories(bctx buildContext, ctx context.Co
|
||||||
// Page 1 renders at both root and /posts/
|
// Page 1 renders at both root and /posts/
|
||||||
var paths []string
|
var paths []string
|
||||||
if page == 1 {
|
if page == 1 {
|
||||||
paths = []string{"", "/posts"}
|
paths = []string{"", fmt.Sprintf("%v/1", b.opts.BasePostList)}
|
||||||
} else {
|
} else {
|
||||||
paths = []string{fmt.Sprintf("/posts/%d", page)}
|
paths = []string{fmt.Sprintf("%v/%d", b.opts.BasePostList, page)}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,10 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
BasePosts string // BasePosts is the base path for posts.
|
BasePosts string // BasePosts is the base path for posts.
|
||||||
BaseUploads string // BaseUploads is the base path for uploads.
|
BasePostList string // BasePostList is the base path for post lists.
|
||||||
BaseStatic string // BaseStatic is the base path for static assets.
|
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 provides the raw templates for rendering the site.
|
||||||
TemplatesFS fs.FS
|
TemplatesFS fs.FS
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package pages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"lmika.dev/lmika/weiro/models"
|
"lmika.dev/lmika/weiro/models"
|
||||||
|
|
@ -63,6 +64,10 @@ func (s *Service) CreatePage(ctx context.Context, params CreatePageParams) (*mod
|
||||||
slug = models.GeneratePageSlug(params.Title)
|
slug = models.GeneratePageSlug(params.Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(slug, "/") {
|
||||||
|
slug = "/" + slug
|
||||||
|
}
|
||||||
|
|
||||||
// Check slug collision
|
// Check slug collision
|
||||||
if _, err := s.db.SelectPageBySlugAndSite(ctx, site.ID, slug); err == nil {
|
if _, err := s.db.SelectPageBySlugAndSite(ctx, site.ID, slug); err == nil {
|
||||||
return nil, models.SlugConflictError
|
return nil, models.SlugConflictError
|
||||||
|
|
@ -120,6 +125,10 @@ func (s *Service) UpdatePage(ctx context.Context, id int64, params CreatePagePar
|
||||||
slug = models.GeneratePageSlug(params.Title)
|
slug = models.GeneratePageSlug(params.Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(slug, "/") {
|
||||||
|
slug = "/" + slug
|
||||||
|
}
|
||||||
|
|
||||||
// Check slug collision (exclude self)
|
// Check slug collision (exclude self)
|
||||||
if existing, err := s.db.SelectPageBySlugAndSite(ctx, site.ID, slug); err == nil && existing.ID != page.ID {
|
if existing, err := s.db.SelectPageBySlugAndSite(ctx, site.ID, slug); err == nil && existing.ID != page.ID {
|
||||||
return nil, models.SlugConflictError
|
return nil, models.SlugConflictError
|
||||||
|
|
|
||||||
|
|
@ -121,13 +121,14 @@ func (p *Publisher) publishSite(ctx context.Context, pubSite pubmodel.Site, targ
|
||||||
}
|
}
|
||||||
|
|
||||||
sb, err := sitebuilder.New(pubSite, sitebuilder.Options{
|
sb, err := sitebuilder.New(pubSite, sitebuilder.Options{
|
||||||
BasePosts: "/posts",
|
BasePosts: "/posts",
|
||||||
BaseUploads: "/uploads",
|
BasePostList: "/pages",
|
||||||
BaseStatic: "/static",
|
BaseUploads: "/uploads",
|
||||||
TemplatesFS: templateFS,
|
BaseStatic: "/static",
|
||||||
StaticFS: staticFS,
|
TemplatesFS: templateFS,
|
||||||
FeedItems: 30,
|
StaticFS: staticFS,
|
||||||
RenderTZ: renderTZ,
|
FeedItems: 30,
|
||||||
|
RenderTZ: renderTZ,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,15 @@
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/posts">Posts</a>
|
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/posts">Posts</a>
|
||||||
</li>
|
</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">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/pages">Pages</a>
|
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/pages">Pages</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/uploads">Uploads</a>
|
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/uploads">Uploads</a>
|
||||||
</li>
|
</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">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/settings">Settings</a>
|
<a class="nav-link active" aria-current="page" href="/sites/{{.site.ID}}/settings">Settings</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
<main class="container py-2">
|
<main class="flex-grow-1 position-relative">
|
||||||
{{ if .isNew }}
|
{{ 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 }}
|
{{ 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 }}
|
{{ end }}
|
||||||
<input type="hidden" name="guid" value="{{ .page.GUID }}">
|
<input type="hidden" name="guid" value="{{ .page.GUID }}">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -10,10 +10,8 @@
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<input type="text" name="title" class="form-control" placeholder="Title" value="{{ .page.Title }}">
|
<input type="text" name="title" class="form-control" placeholder="Title" value="{{ .page.Title }}">
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<textarea name="body" class="form-control flex-grow-1" rows="20">{{ .page.Body }}</textarea>
|
||||||
<textarea name="body" class="form-control" rows="20">{{ .page.Body }}</textarea>
|
<div class="mt-2">
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<button type="submit" class="btn btn-primary">{{ if .isNew }}Create{{ else }}Save{{ end }}</button>
|
<button type="submit" class="btn btn-primary">{{ if .isNew }}Create{{ else }}Save{{ end }}</button>
|
||||||
{{ if not .isNew }}
|
{{ if not .isNew }}
|
||||||
<button type="button" class="btn btn-outline-danger ms-2"
|
<button type="button" class="btn btn-outline-danger ms-2"
|
||||||
|
|
@ -23,18 +21,11 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="card mb-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="card-body">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="pageSlug" class="form-label">Slug</label>
|
<label for="pageSlug" class="form-label">Slug</label>
|
||||||
<input type="text" class="form-control" id="pageSlug" name="slug" value="{{ .page.Slug }}">
|
<input type="text" class="form-control" id="pageSlug" name="slug" value="{{ .page.Slug }}" placeholder="Leave blank to generate">
|
||||||
<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>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input class="form-check-input" type="checkbox" name="show_in_nav" value="true" id="showInNav"
|
<input class="form-check-input" type="checkbox" name="show_in_nav" value="true" id="showInNav"
|
||||||
|
|
@ -43,6 +34,17 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@
|
||||||
<input type="text" name="title" class="form-control" placeholder="Title" value="{{ .post.Title }}">
|
<input type="text" name="title" class="form-control" placeholder="Title" value="{{ .post.Title }}">
|
||||||
</div>
|
</div>
|
||||||
<textarea data-postedit-target="bodyTextEdit" name="body" class="form-control flex-grow-1" rows="3">{{.post.Body}}</textarea>
|
<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 }}
|
{{ 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 }}
|
{{ else }}
|
||||||
<input type="submit" name="action" class="btn btn-primary mt-2" value="Publish">
|
<input type="submit" name="action" class="btn btn-primary" value="Publish">
|
||||||
<input type="submit" name="action" class="btn btn-secondary mt-2" value="Save Draft">
|
<input type="submit" name="action" class="btn btn-secondary" value="Save Draft">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue