feat: SSR 站点单页 /page/:slug 与 Admin CRUD
EOF Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
<a href="/admin/boards"{{if eq .NavActive "boards"}} class="is-active"{{end}}>板块</a>
|
||||
<a href="/admin/moderation"{{if eq .NavActive "moderation"}} class="is-active"{{end}}>审核</a>
|
||||
<a href="/admin/friend-links"{{if eq .NavActive "friend-links"}} class="is-active"{{end}}>友链</a>
|
||||
<a href="/admin/pages"{{if eq .NavActive "pages"}} class="is-active"{{end}}>单页</a>
|
||||
<a href="/admin/settings"{{if eq .NavActive "settings"}} class="is-active"{{end}}>设置</a>
|
||||
<a href="/">返回前台</a>
|
||||
</nav>
|
||||
|
||||
72
templates/admin/pages.tmpl
Normal file
72
templates/admin/pages.tmpl
Normal file
@@ -0,0 +1,72 @@
|
||||
{{define "admin/pages"}}
|
||||
{{template "base/head" .}}
|
||||
{{template "base/navbar" .}}
|
||||
<main class="j13-main j13-admin">
|
||||
<h1>站点单页</h1>
|
||||
{{template "admin/nav" .}}
|
||||
{{template "base/alert" .}}
|
||||
|
||||
<section>
|
||||
<h2>{{if .Form.IsEdit}}编辑:{{.Form.Title}}{{else}}新建单页{{end}}</h2>
|
||||
<form method="post" action="{{if .Form.IsEdit}}/admin/pages/{{.Form.ID}}{{else}}/admin/pages{{end}}" class="j13-form j13-admin-form">
|
||||
<input type="hidden" name="_csrf" value="{{.CSRF}}"/>
|
||||
<label>标题 <input name="title" required value="{{.Form.Title}}"/></label>
|
||||
<label>Slug <input name="slug" required pattern="[a-z0-9-]{2,64}" value="{{.Form.Slug}}" placeholder="about"/></label>
|
||||
<label>排序 <input name="sort_order" type="number" value="{{.Form.SortOrder}}"/></label>
|
||||
<label class="j13-check"><input type="checkbox" name="published" value="1"{{if .Form.Published}} checked{{end}}/> 已发布</label>
|
||||
<label class="j13-check"><input type="checkbox" name="show_in_nav" value="1"{{if .Form.ShowInNav}} checked{{end}}/> 导航显示</label>
|
||||
<label class="j13-check"><input type="checkbox" name="show_in_footer" value="1"{{if .Form.ShowInFooter}} checked{{end}}/> 页脚显示</label>
|
||||
<label>正文(HTML)
|
||||
<textarea name="content" rows="12" required>{{.Form.Content}}</textarea>
|
||||
</label>
|
||||
<button type="submit">{{if .Form.IsEdit}}保存{{else}}创建{{end}}</button>
|
||||
{{if .Form.IsEdit}}<a href="/admin/pages" class="j13-linkbtn">取消编辑</a>{{end}}
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>已有单页</h2>
|
||||
{{if .Pages}}
|
||||
<table class="j13-admin-table">
|
||||
<thead>
|
||||
<tr><th>标题</th><th>Slug</th><th>排序</th><th>状态</th><th>入口</th><th>操作</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range .Pages}}
|
||||
<tr>
|
||||
<td>{{.Title}}</td>
|
||||
<td><code>{{.Slug}}</code>{{if .Published}} · <a href="/page/{{.Slug}}" target="_blank" rel="noopener">预览</a>{{end}}</td>
|
||||
<td>{{.SortOrder}}</td>
|
||||
<td>{{if .Published}}已发布{{else}}草稿{{end}}</td>
|
||||
<td>
|
||||
{{if .ShowInNav}}导航 {{end}}{{if .ShowInFooter}}页脚{{end}}
|
||||
{{if and (not .ShowInNav) (not .ShowInFooter)}}—{{end}}
|
||||
</td>
|
||||
<td>
|
||||
<a href="/admin/pages/{{.ID}}/edit">编辑</a>
|
||||
<form method="post" action="/admin/pages/{{.ID}}/publish" class="j13-inline-form">
|
||||
<input type="hidden" name="_csrf" value="{{$.CSRF}}"/>
|
||||
{{if .Published}}
|
||||
<input type="hidden" name="published" value="0"/>
|
||||
<button type="submit" class="j13-linkbtn">下架</button>
|
||||
{{else}}
|
||||
<input type="hidden" name="published" value="1"/>
|
||||
<button type="submit" class="j13-linkbtn">发布</button>
|
||||
{{end}}
|
||||
</form>
|
||||
<form method="post" action="/admin/pages/{{.ID}}/delete" class="j13-inline-form" onsubmit="return confirm('确认删除该单页?');">
|
||||
<input type="hidden" name="_csrf" value="{{$.CSRF}}"/>
|
||||
<button type="submit" class="j13-linkbtn">删除</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{else}}
|
||||
<p class="j13-empty">暂无单页</p>
|
||||
{{end}}
|
||||
</section>
|
||||
</main>
|
||||
{{template "base/footer" .}}
|
||||
{{end}}
|
||||
@@ -3,6 +3,7 @@
|
||||
<p>
|
||||
{{.SiteName}}
|
||||
{{if .ShowFriendLinksFooter}} · <a href="/links">友情链接</a>{{end}}
|
||||
{{range .FooterPages}} · <a href="/page/{{.Slug}}">{{.Title}}</a>{{end}}
|
||||
</p>
|
||||
</footer>
|
||||
<script src="/ssr-assets/site.js" defer></script>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<a href="/#search">搜索</a>
|
||||
<a href="/boards">板块</a>
|
||||
{{if .ShowFriendLinksNav}}<a href="/links">友链</a>{{end}}
|
||||
{{range .NavPages}}<a href="/page/{{.Slug}}">{{.Title}}</a>{{end}}
|
||||
{{if .LoggedIn}}
|
||||
<a href="/compose">发帖</a>
|
||||
<a href="/messages">私信{{if gt .UnreadCount 0}} <span class="j13-badge">{{.UnreadCount}}</span>{{end}}</a>
|
||||
|
||||
@@ -2,5 +2,5 @@ package templates
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed *.tmpl base/*.tmpl home/*.tmpl post/*.tmpl shared/*.tmpl status/*.tmpl auth/*.tmpl admin/*.tmpl profile/*.tmpl user/*.tmpl favorites/*.tmpl messages/*.tmpl links/*.tmpl boards/*.tmpl
|
||||
//go:embed *.tmpl base/*.tmpl home/*.tmpl post/*.tmpl shared/*.tmpl status/*.tmpl auth/*.tmpl admin/*.tmpl profile/*.tmpl user/*.tmpl favorites/*.tmpl messages/*.tmpl links/*.tmpl boards/*.tmpl page/*.tmpl
|
||||
var FS embed.FS
|
||||
|
||||
12
templates/page/view.tmpl
Normal file
12
templates/page/view.tmpl
Normal file
@@ -0,0 +1,12 @@
|
||||
{{define "page/view"}}
|
||||
{{template "base/head" .}}
|
||||
{{template "base/navbar" .}}
|
||||
{{if .Flash}}<div class="j13-flash" role="status">{{.Flash}}</div>{{end}}
|
||||
<main class="j13-main j13-page">
|
||||
<article class="j13-page__article">
|
||||
<h1>{{.PageTitle}}</h1>
|
||||
<div class="j13-page__body post-detail-content">{{.BodyHTML}}</div>
|
||||
</article>
|
||||
</main>
|
||||
{{template "base/footer" .}}
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user