From 3db4943cf6a3c438779fbc8b59d1eaa88bfbd4ce Mon Sep 17 00:00:00 2001 From: Jason Ernst Date: Mon, 21 Sep 2026 08:58:47 -0700 Subject: [PATCH 1/2] Admin: opaque panel chrome, empty states, Directory-tab JS fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Admin pages are default's admin_*.html rendered inside the active theme's header/footer, so a theme with a full-bleed photo (forest) put tables and forms straight on the picture (#596). goblog now owns the admin surface: www/css/admin.css, linked from _head.html after the theme's goblog.css, puts the admin nav and every admin page's content on an opaque .admin-panel in the theme's Bootstrap body colours. Every default admin template wraps its content in the panel (post-admin also gains the nav), which also puts the Plugins/Themes nav-tabs on a readable surface. All Posts, Pages, Post Types, Comments and Users show a muted empty state with a call to action where one exists. Plugins → Directory tab (#590): the README is fetched once per card and then only toggled; a button's spinner is restored only while it is still in the page, since a successful action re-renders the lists. The minimal theme's admin*.html and post-admin.html were stale byte copies of default's (its admin_nav even lacked Plugins/Themes); they are removed so minimal falls back to default's admin templates through theme.Load's layering. admin.html (the "all posts + create post" mashup /admin used to render) goes too: /admin now redirects to the dashboard. Co-Authored-By: Claude Opus 5 (1M context) --- plugins/docs/content/writing-a-theme.md | 2 +- templates/shared/_head.html | 4 + themes/default/templates/admin.html | 139 ---------- themes/default/templates/admin_all_posts.html | 6 + themes/default/templates/admin_comments.html | 4 +- themes/default/templates/admin_edit_page.html | 2 + .../templates/admin_edit_post_type.html | 2 + themes/default/templates/admin_new_post.html | 2 + themes/default/templates/admin_pages.html | 6 + themes/default/templates/admin_plugins.html | 13 +- .../default/templates/admin_post_types.html | 6 + themes/default/templates/admin_users.html | 4 +- themes/default/templates/post-admin.html | 3 + themes/minimal/templates/admin.html | 139 ---------- themes/minimal/templates/admin_all_posts.html | 92 ------- themes/minimal/templates/admin_comments.html | 64 ----- themes/minimal/templates/admin_dashboard.html | 98 ------- themes/minimal/templates/admin_edit_page.html | 151 ----------- .../templates/admin_edit_post_type.html | 65 ----- themes/minimal/templates/admin_nav.html | 25 -- themes/minimal/templates/admin_new_post.html | 94 ------- themes/minimal/templates/admin_pages.html | 84 ------ .../minimal/templates/admin_post_types.html | 98 ------- themes/minimal/templates/admin_settings.html | 86 ------ themes/minimal/templates/admin_users.html | 67 ----- themes/minimal/templates/post-admin.html | 245 ------------------ www/css/admin.css | 72 +++++ 27 files changed, 122 insertions(+), 1451 deletions(-) delete mode 100644 themes/default/templates/admin.html delete mode 100644 themes/minimal/templates/admin.html delete mode 100644 themes/minimal/templates/admin_all_posts.html delete mode 100644 themes/minimal/templates/admin_comments.html delete mode 100644 themes/minimal/templates/admin_dashboard.html delete mode 100644 themes/minimal/templates/admin_edit_page.html delete mode 100644 themes/minimal/templates/admin_edit_post_type.html delete mode 100644 themes/minimal/templates/admin_nav.html delete mode 100644 themes/minimal/templates/admin_new_post.html delete mode 100644 themes/minimal/templates/admin_pages.html delete mode 100644 themes/minimal/templates/admin_post_types.html delete mode 100644 themes/minimal/templates/admin_settings.html delete mode 100644 themes/minimal/templates/admin_users.html delete mode 100644 themes/minimal/templates/post-admin.html create mode 100644 www/css/admin.css diff --git a/plugins/docs/content/writing-a-theme.md b/plugins/docs/content/writing-a-theme.md index 39729b31..bcdca5c1 100644 --- a/plugins/docs/content/writing-a-theme.md +++ b/plugins/docs/content/writing-a-theme.md @@ -67,7 +67,7 @@ Every template is executed with a map, so keys are reached as `.settings`, `.pos | `title` | The page title default's head uses when there is no `post`. | | `version` | The running goblog version, for the footer. | | `recent` | The newest published post, for the "most recent" block in default's footer. | -| `admin_page` | True on admin renders; default's head loads the editor scripts when it is set. | +| `admin_page` | True on admin renders; default's head loads the editor scripts and, after your `goblog.css`, goblog's own `/css/admin.css`, which puts the admin nav and content on an opaque `.admin-panel` surface — so admin pages read on a photo or dark backdrop without the theme doing anything. | | `plugin_head_html`, `plugin_footer_html`, `plugins` | The HTML installed plugins inject and their per-template data, keyed by plugin name. Added to every **public** render; admin pages are rendered without them. | Beyond those, each template gets its own data. This is the contract of the running version, read off the render calls in `blog/blog.go` and `admin/`; a release can add keys, and removals are noted in the changelog. diff --git a/templates/shared/_head.html b/templates/shared/_head.html index 9a340646..ed24204d 100644 --- a/templates/shared/_head.html +++ b/templates/shared/_head.html @@ -71,6 +71,10 @@ {{ end }} + {{ if .admin_page }} + + + {{ end }} {{ with index .settings "custom_header_code" }}{{ if .Value }} {{ .Value | rawHTML }} {{ end }}{{ end }} diff --git a/themes/default/templates/admin.html b/themes/default/templates/admin.html deleted file mode 100644 index 1bb5c825..00000000 --- a/themes/default/templates/admin.html +++ /dev/null @@ -1,139 +0,0 @@ -{{ template "header.html" .}} - - -
- {{ template "admin_nav.html" . }} -

All Posts

- - - {{ range .posts }} - - - - - - - - {{ end }} -
{{ .Title }}{{ .CreatedAt.Format "01/02/06" }}{{ range .Tags }} - #{{ .Name }} - {{ end }} -
- - -

Create post

- -
- - -
- -
- - -
- -
- -
- -
-
-
-
-
- -
- -
- -
-
- -
-

* - required fields

-
- -
- - - -
- -
- - - - {{ template "footer.html" .}} diff --git a/themes/default/templates/admin_all_posts.html b/themes/default/templates/admin_all_posts.html index 5d6a8608..500c8ff2 100644 --- a/themes/default/templates/admin_all_posts.html +++ b/themes/default/templates/admin_all_posts.html @@ -39,7 +39,9 @@
{{ template "admin_nav.html" . }} +

All Posts

+ {{ if .posts }} {{ range .posts }} @@ -53,7 +55,11 @@

All Posts

{{ end }}
+ {{ else }} +

No posts yet. Write your first post.

+ {{ end }} +
diff --git a/themes/default/templates/admin_comments.html b/themes/default/templates/admin_comments.html index 04151bbb..fa6f0105 100644 --- a/themes/default/templates/admin_comments.html +++ b/themes/default/templates/admin_comments.html @@ -1,6 +1,7 @@ {{ template "header.html" .}}
{{ template "admin_nav.html" . }} +

Comments

Page {{ .page }} of {{ .total_pages }} · {{ .total }} comments

@@ -33,7 +34,7 @@

Comments

{{ else }} -

No comments yet.

+

No comments yet. Comments left on your posts show up here.

{{ end }} +
{{ template "admin_nav.html" . }} +

Create post

@@ -57,6 +58,7 @@

Create post

+
+ {{ template "admin_nav.html" . }} +
@@ -184,6 +186,7 @@

Revision History

+
diff --git a/themes/minimal/templates/admin.html b/themes/minimal/templates/admin.html deleted file mode 100644 index 1bb5c825..00000000 --- a/themes/minimal/templates/admin.html +++ /dev/null @@ -1,139 +0,0 @@ -{{ template "header.html" .}} - - -
- {{ template "admin_nav.html" . }} -

All Posts

- - - {{ range .posts }} - - - - - - - - {{ end }} -
{{ .Title }}{{ .CreatedAt.Format "01/02/06" }}{{ range .Tags }} - #{{ .Name }} - {{ end }} -
- - -

Create post

- -
- - -
- -
- - -
- -
- -
- -
-
-
-
-
- -
- -
- -
-
- -
-

* - required fields

-
- -
- - - -
- -
- - - - {{ template "footer.html" .}} diff --git a/themes/minimal/templates/admin_all_posts.html b/themes/minimal/templates/admin_all_posts.html deleted file mode 100644 index 5d6a8608..00000000 --- a/themes/minimal/templates/admin_all_posts.html +++ /dev/null @@ -1,92 +0,0 @@ -{{ template "header.html" .}} - - -
- {{ template "admin_nav.html" . }} -

All Posts

- - {{ range .posts }} - - - - - - - {{ end }} -
{{ .Title }}{{ .CreatedAt.Format "01/02/06" }}{{ if .PostType.Name }}{{ .PostType.Name }}{{ end }}{{ range .Tags }} - #{{ .Name }} - {{ end }} -
- - -
- - - -{{ template "footer.html" .}} diff --git a/themes/minimal/templates/admin_comments.html b/themes/minimal/templates/admin_comments.html deleted file mode 100644 index a0cf8faa..00000000 --- a/themes/minimal/templates/admin_comments.html +++ /dev/null @@ -1,64 +0,0 @@ -{{ template "header.html" .}} -
- {{ template "admin_nav.html" . }} -

Comments

-

Page {{ .page }} of {{ .total_pages }} · {{ .total }} comments

- - {{ if .comments }} - - - - - - - - - - - - - {{ range .comments }} - - - - - - - - - {{ end }} - -
DateNameEmailCommentPost
{{ .CreatedAt.Format "Jan 02, 2006 15:04" }}{{ .Name }}{{ .Email }}{{ if gt (len .Content) 80 }}{{ slice .Content 0 80 }}...{{ else }}{{ .Content }}{{ end }} - {{ $post := index $.comment_posts .PostID }} - {{ if $post.Title }}{{ $post.Title }}{{ else }}Post #{{ .PostID }}{{ end }} - [delete]
- {{ else }} -

No comments yet.

- {{ end }} - - -
- - -{{ template "footer.html" .}} diff --git a/themes/minimal/templates/admin_dashboard.html b/themes/minimal/templates/admin_dashboard.html deleted file mode 100644 index 39373c97..00000000 --- a/themes/minimal/templates/admin_dashboard.html +++ /dev/null @@ -1,98 +0,0 @@ -{{ template "header.html" .}} - - -
- {{ template "admin_nav.html" . }} -

Dashboard

-

Welcome to the admin dashboard.

- -

Recent Comments View all →

- {{ if .recent_comments }} - - - - - - - - - - - - - {{ range .recent_comments }} - - - - - - - - - {{ end }} - -
DateNameEmailCommentPost
{{ .CreatedAt.Format "Jan 02, 2006 15:04" }}{{ .Name }}{{ .Email }}{{ if gt (len .Content) 80 }}{{ slice .Content 0 80 }}...{{ else }}{{ .Content }}{{ end }} - {{ $post := index $.comment_posts .PostID }} - {{ if $post.Title }}{{ $post.Title }}{{ else }}Post #{{ .PostID }}{{ end }} - [delete]
- {{ else }} -

No comments yet.

- {{ end }} - -
- - - -{{ template "footer.html" .}} diff --git a/themes/minimal/templates/admin_edit_page.html b/themes/minimal/templates/admin_edit_page.html deleted file mode 100644 index e747ad4b..00000000 --- a/themes/minimal/templates/admin_edit_page.html +++ /dev/null @@ -1,151 +0,0 @@ -{{ template "header.html" .}} -
- {{ template "admin_nav.html" . }} -

Edit Page: {{ .page.Title }}

- - - - - {{ $disabledPlugins := .disabled_plugin_pages }} - {{ if index $disabledPlugins .page.PageType }} - - {{ end }} - -
-
- - -
- -
- -
- / - -
-
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
-
- - -
-
-
- - -
-
-
-
- - -
-
-
- - - Back to Pages - View Page -
-
- - - -{{ template "footer.html" .}} diff --git a/themes/minimal/templates/admin_edit_post_type.html b/themes/minimal/templates/admin_edit_post_type.html deleted file mode 100644 index 4e1a790a..00000000 --- a/themes/minimal/templates/admin_edit_post_type.html +++ /dev/null @@ -1,65 +0,0 @@ -{{ template "header.html" .}} -
- {{ template "admin_nav.html" . }} -

Edit Post Type: {{ .post_type.Name }}

- - - - -
-
- - -
- -
- -
- / - -
-
- -
- - -
- - - Back to Post Types - View Listing -
-
- - - -{{ template "footer.html" .}} diff --git a/themes/minimal/templates/admin_nav.html b/themes/minimal/templates/admin_nav.html deleted file mode 100644 index 4888d810..00000000 --- a/themes/minimal/templates/admin_nav.html +++ /dev/null @@ -1,25 +0,0 @@ - - diff --git a/themes/minimal/templates/admin_new_post.html b/themes/minimal/templates/admin_new_post.html deleted file mode 100644 index e2f52b3a..00000000 --- a/themes/minimal/templates/admin_new_post.html +++ /dev/null @@ -1,94 +0,0 @@ -{{ template "header.html" .}} - -
- {{ template "admin_nav.html" . }} - -

Create post

- -
- - -
- -
- - -
- -
- - -
- -
- -
- -
-
-
-
-
- -
- -
- -
-
- -
-

* - required fields

-
- -
- - - -
- -
- - - -{{ template "footer.html" .}} \ No newline at end of file diff --git a/themes/minimal/templates/admin_pages.html b/themes/minimal/templates/admin_pages.html deleted file mode 100644 index 03ca5837..00000000 --- a/themes/minimal/templates/admin_pages.html +++ /dev/null @@ -1,84 +0,0 @@ -{{ template "header.html" .}} -
- {{ template "admin_nav.html" . }} -

Pages

- - New Page - - - - - - - - - - - - - - - {{ $disabledPlugins := .disabled_plugin_pages }} - {{ range .pages }} - {{ $pluginDisabled := index $disabledPlugins .PageType }} - - - - - - - - - - {{ end }} - -
TitleSlugTypeNav OrderNavEnabledActions
{{ .Title }}/{{ .Slug }}{{ .PageType }}{{ if $pluginDisabled }} plugin disabled{{ end }}{{ .NavOrder }}{{ if .ShowInNav }}Yes{{ else }}No{{ end }}{{ if $pluginDisabled }}Plugin disabled{{ else if .Enabled }}Yes{{ else }}No{{ end }} - Edit - -
-
- - - -{{ template "footer.html" .}} diff --git a/themes/minimal/templates/admin_post_types.html b/themes/minimal/templates/admin_post_types.html deleted file mode 100644 index a2f36158..00000000 --- a/themes/minimal/templates/admin_post_types.html +++ /dev/null @@ -1,98 +0,0 @@ -{{ template "header.html" .}} -
- {{ template "admin_nav.html" . }} -

Post Types

- - - - - - - - - - - - - - - {{ range .post_types }} - - - - - - - {{ end }} - -
NameSlugDescriptionActions
{{ .Name }}/{{ .Slug }}{{ .Description }} - Edit - -
- -

Create New Post Type

-
-
-
- - -
-
- -
- / - -
-
-
-
- - -
- -
-
- - - -{{ template "footer.html" .}} diff --git a/themes/minimal/templates/admin_settings.html b/themes/minimal/templates/admin_settings.html deleted file mode 100644 index 2f388408..00000000 --- a/themes/minimal/templates/admin_settings.html +++ /dev/null @@ -1,86 +0,0 @@ -{{ template "header.html" .}} - -
- {{ template "admin_nav.html" . }} - -

Site Settings

- - -
-
General
-
-
- {{ $themes := .themes }} - {{ range .settings }} -
- - {{ if eq .Type "file" }} - - {{ else if eq .Type "textarea" }} - - {{ else if eq .Type "checkbox" }} -
- -
- {{ else if eq .Key "theme" }} - - {{ else }} - - {{ end }} -
- {{ end }} - -
-
-
- - {{ range .plugin_settings }} - {{ $pluginName := .PluginName }} - {{ $values := .CurrentValues }} - {{ $enabled := index $values "enabled" }} -
-
- Plugin: {{ .DisplayName }} ({{ .PluginName }}) -
- - -
-
-
-
-
- {{ range .Settings }} - {{ if ne .Key "enabled" }} -
- - {{ if .Description }}{{ .Description }}{{ end }} - {{ if eq .Type "textarea" }} - - {{ else if eq .Type "password" }} - - {{ else }} - - {{ end }} -
- {{ end }} - {{ end }} - -
-
-
-
- {{ end }} - -
- -{{ template "footer.html" .}} diff --git a/themes/minimal/templates/admin_users.html b/themes/minimal/templates/admin_users.html deleted file mode 100644 index f05cb8a7..00000000 --- a/themes/minimal/templates/admin_users.html +++ /dev/null @@ -1,67 +0,0 @@ -{{ template "header.html" .}} -
- {{ template "admin_nav.html" . }} -

Users

-

Page {{ .page }} of {{ .total_pages }} · {{ .total }} user{{ if ne .total 1 }}s{{ end }}

-

Admins can manage posts, pages, comments, settings and other users. Only GitHub users can be made admin, and the last admin can't be demoted.

- - {{ if .users }} - - - - - - - - - - - - {{ range .users }} - - - - - - - - {{ end }} - -
LoginNameProviderRole
{{ .Login }}{{ .Name }}{{ .Provider }}{{ if .IsAdmin }}Admin{{ end }} - {{ if .IsAdmin }} - {{ if $.can_demote }}[demote]{{ end }} - {{ else if eq .Provider "github" }} - [promote to admin] - {{ end }} -
- {{ else }} -

No users yet.

- {{ end }} - - -
- - -{{ template "footer.html" .}} diff --git a/themes/minimal/templates/post-admin.html b/themes/minimal/templates/post-admin.html deleted file mode 100644 index 7db68970..00000000 --- a/themes/minimal/templates/post-admin.html +++ /dev/null @@ -1,245 +0,0 @@ -{{ template "header.html" .}} - -
- -
-
- {{ if .post.Draft }} -

{{ .post.Title }}

- {{ else }} -

{{ .post.Title }}

- {{ end }} - - -

- {{range .post.Tags}} - #{{.Name}} - {{end}} -

-
-
-
-
-
 
-

Editable

- -

{{ .post.Slug }}

- - {{ if .post.Draft }} -

{{range $i, $e := .post.Tags}}{{if $i}}, {{end}}{{$e.Name}}{{end}}

- {{ else }} -

{{range $i, $e := .post.Tags}}{{if $i}}, {{end}}{{$e.Name}}{{end}}

- {{ end }} - {{ if .post_types }} - - {{ if .post.Draft }} - - {{ else }} - - {{ end }} - {{ end }} -
- {{ if .post.Draft }} - - {{ else }} - - {{ end }} -
-
 
- -
- -
- -
-
-
-
-
- -
- {{ if .post.Draft }} - - - {{ else }} - - - {{ end }} - -
-
-
-
-
 
-
-

Preview

-
-
-
- -
-
-

Backlinks

-

Posts that link to this post

- {{ if .backlinks }} -
    - {{ range .backlinks }} -
  • {{ .Title }} ({{ .CreatedAt.Format "Jan 02, 2006" }})
  • - {{ end }} -
- {{ else }} -

None

- {{ end }} -
-
- -
-
-

Linked Posts

-

Blog posts this post links to

- {{ if .outbound_links }} -
    - {{ range .outbound_links }} -
  • {{ .Title }} ({{ .CreatedAt.Format "Jan 02, 2006" }})
  • - {{ end }} -
- {{ else }} -

None

- {{ end }} -
-
- -
-
-

External Links

-

External URLs in this post

- {{ if .post.ExternalLinks }} -
    - {{ range .post.ExternalLinks }} -
  • {{ . }}
  • - {{ end }} -
- {{ else }} -

None

- {{ end }} -
-
- -
-
-

External Backlinks

-

External sites linking to this post

- {{ if .external_backlinks }} - - - - - - - - - - - {{ range .external_backlinks }} - - - - - - - {{ end }} - - - {{ else }} -

None

- {{ end }} -
-
- -
-
-

Revision History

-

Previous versions of this post

-
-

Loading...

-
-
-
- -
- - - - - -{{ template "footer.html" .}} diff --git a/www/css/admin.css b/www/css/admin.css new file mode 100644 index 00000000..2d0ce2fb --- /dev/null +++ b/www/css/admin.css @@ -0,0 +1,72 @@ +/* Admin chrome shared by every theme (#596). + * + * Admin pages are default's admin_*.html rendered inside the active theme's + * header/footer, so a theme with a photo or dark backdrop (forest) would put + * tables and forms straight on the picture. The nav and the page content sit + * on an opaque surface instead, in the theme's Bootstrap body colours so it + * still follows a light/dark theme. Linked after the theme's goblog.css so it + * wins. */ + +.admin-panel { + background: var(--bs-body-bg, #fff); + color: var(--bs-body-color, #212529); + padding: 1rem 1.5rem 1.5rem; + border-radius: .5rem; + box-shadow: 0 .25rem 1rem rgba(0, 0, 0, .12); + margin-top: 1rem; + margin-bottom: 2rem; + text-align: left; +} + +.admin-panel h1:first-child { + margin-top: .25rem; +} + +/* The secondary nav (admin_nav.html) gets the same surface so it reads on + * any backdrop; bg-body already sets the colour, this adds the frame. */ +.nav-scroller { + background: var(--bs-body-bg, #fff); + color: var(--bs-body-color, #212529); + padding: .25rem 1rem; + border-radius: .5rem; + box-shadow: 0 .25rem 1rem rgba(0, 0, 0, .12); + margin-top: 1rem; + overflow-x: auto; + -webkit-overflow-scrolling: touch; +} + +.nav-scroller .nav { + flex-wrap: nowrap; + white-space: nowrap; +} + +/* Dashboard count tiles: the number is what you scan for, so it gets the + * size; Tachyons is loaded on every page and its .h1-.h6 set height, so + * sizing uses Bootstrap's fs-* / display-* only. */ +.admin-tile { + display: block; + text-decoration: none; + color: inherit; +} + +.admin-tile .card { + transition: box-shadow .15s ease-in-out; +} + +.admin-tile:hover .card { + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .15); +} + +/* Installed-theme cards without a directory screenshot: a neutral tile with + * the theme's display name in place of the image. */ +.theme-placeholder { + display: flex; + align-items: center; + justify-content: center; + aspect-ratio: 16 / 9; + background: var(--bs-secondary-bg, #e9ecef); + color: var(--bs-secondary-color, #6c757d); + font-size: 1.5rem; + border-top-left-radius: var(--bs-card-inner-border-radius, .375rem); + border-top-right-radius: var(--bs-card-inner-border-radius, .375rem); +} From bf77d6695ff66c668e9f78368b220bba7377eb60 Mon Sep 17 00:00:00 2001 From: Jason Ernst Date: Mon, 21 Sep 2026 08:59:05 -0700 Subject: [PATCH 2/2] =?UTF-8?q?Admin:=20/admin=20=E2=86=92=20dashboard=20s?= =?UTF-8?q?ummary;=20installed=20themes=20as=20cards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GET /admin 302s to /admin/dashboard (still admin-gated: non-admins get the same 401 as every other admin page). The dashboard replaces the "Welcome" placeholder with count tiles (posts with a drafts sub-count, pages, comments, users) linking to their admin pages, the five newest posts (draft badge, admin edit link) beside the existing recent comments, and a Site panel: active theme (from the installer when wired, else the setting), enabled plugins from the registry, and the goblog version. blog gains CountPosts/CountPages/CountComments/GetRecentPosts; the user count reuses auth.ListUsers's total. Themes → Installed renders the same card grid as Browse: the directory screenshot when known (Status() now copies the index entry's screenshot_url onto the installed row — the only change to theme/installer), else a neutral placeholder tile with the display name; name, version, built-in/directory badge, an Active badge, and the existing Activate/Update/Uninstall buttons with their behaviour and confirmations. httpURL/esc/safeName still guard everything that reaches an href/src. Tests: /admin redirect and 401; dashboard data keys and Site panel; empty states and the panel on every admin route in default and minimal (templates layered like theme.Load, so minimal renders default's admin pages); no Tachyons .h1-.h6 classes in rendered admin pages; screenshot_url on installed themes. Co-Authored-By: Claude Opus 5 (1M context) --- admin/admin.go | 68 ++++- admin/admin_test.go | 252 ++++++++++++++++-- admin/themes_test.go | 20 +- blog/blog.go | 29 ++ blog/blog_test.go | 40 +++ theme/installer/installer.go | 4 + theme/installer/installer_test.go | 13 +- themes/default/templates/admin_dashboard.html | 194 +++++++++----- themes/default/templates/admin_themes.html | 44 +-- 9 files changed, 547 insertions(+), 117 deletions(-) diff --git a/admin/admin.go b/admin/admin.go index 4e1fb55f..3acd315e 100644 --- a/admin/admin.go +++ b/admin/admin.go @@ -588,24 +588,55 @@ func (a *Admin) GetSettings(c *gin.Context) { //////HTML API/////// -// Admin is the admin dashboard of the website +// Admin sends /admin to the dashboard. It used to render admin.html, an +// "all posts + create post" mashup that duplicated two other pages. func (a *Admin) Admin(c *gin.Context) { if !a.auth.IsAdmin(c) { c.JSON(http.StatusUnauthorized, "Not Authorized") return } - c.HTML(http.StatusOK, "admin.html", gin.H{ - "posts": a.b.GetPosts(true), - "logged_in": a.auth.IsLoggedIn(c), - "is_admin": a.auth.IsAdmin(c), - "version": a.version, - "recent": a.b.GetLatest(), - "admin_page": true, - "settings": a.b.GetSettings(), - "nav_pages": a.b.GetNavPages(), - }) + c.Redirect(http.StatusFound, "/admin/dashboard") +} + +// pluginSummary is one enabled plugin as the dashboard's Site panel lists it. +type pluginSummary struct { + Name string + DisplayName string +} + +// enabledPlugins lists the registered plugins that are switched on, in +// registration order, from the registry on the Gin context (nil when the +// middleware is not installed, e.g. in tests). +func (a *Admin) enabledPlugins(c *gin.Context) []pluginSummary { + var out []pluginSummary + if reg, exists := c.Get("plugin_registry"); exists { + if r, ok := reg.(*gplugin.Registry); ok { + for _, p := range r.Plugins() { + if r.IsPluginEnabled(p.Name()) { + out = append(out, pluginSummary{Name: p.Name(), DisplayName: p.DisplayName()}) + } + } + } + } + return out +} + +// activeTheme is the theme rendering this request: the installer's view when +// it is wired (it tracks activations without a restart), else the setting. +func (a *Admin) activeTheme() string { + if a.Themes != nil && a.Themes.ActiveTheme != nil { + return a.Themes.ActiveTheme() + } + if t, ok := a.b.GetSettings()["theme"]; ok && t.Value != "" { + return t.Value + } + return theme.DefaultName } +const dashboardRecentPosts = 5 + +// AdminDashboard renders the admin landing page: content counts, the newest +// posts and comments, and what the site is running (theme, plugins, version). func (a *Admin) AdminDashboard(c *gin.Context) { if !a.auth.IsAdmin(c) { c.JSON(http.StatusUnauthorized, "Not Authorized") @@ -617,8 +648,13 @@ func (a *Admin) AdminDashboard(c *gin.Context) { postIDs = append(postIDs, comment.PostID) } commentPosts := a.b.GetPostsByIDs(postIDs) + published, drafts := a.b.CountPosts() + // ListUsers already counts; one row is the cheapest page that reports it. + _, userCount, err := a.auth.ListUsers(0, 1) + if err != nil { + log.Println("ERROR COUNTING USERS: ", err) + } c.HTML(http.StatusOK, "admin_dashboard.html", gin.H{ - "posts": a.b.GetPosts(true), "logged_in": a.auth.IsLoggedIn(c), "is_admin": a.auth.IsAdmin(c), "version": a.version, @@ -628,6 +664,14 @@ func (a *Admin) AdminDashboard(c *gin.Context) { "recent_comments": recentComments, "comment_posts": commentPosts, "nav_pages": a.b.GetNavPages(), + "post_count": published, + "draft_count": drafts, + "page_count": a.b.CountPages(), + "comment_count": a.b.CountComments(), + "user_count": userCount, + "recent_posts": a.b.GetRecentPosts(dashboardRecentPosts), + "active_theme": a.activeTheme(), + "enabled_plugins": a.enabledPlugins(c), }) } diff --git a/admin/admin_test.go b/admin/admin_test.go index fe2e3ffa..a100ba52 100644 --- a/admin/admin_test.go +++ b/admin/admin_test.go @@ -7,6 +7,7 @@ import ( "goblog/admin" "goblog/auth" "goblog/blog" + tinstaller "goblog/theme/installer" "html/template" "io" "io/ioutil" @@ -19,6 +20,7 @@ import ( "strconv" "strings" "testing" + "time" "github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions/cookie" @@ -458,18 +460,26 @@ func TestCreatePost(t *testing.T) { t.Fatalf("Expected to get status %d but instead got %d\n%s", http.StatusBadRequest, w.Code, body) } - //get admin + //get admin: /admin is the dashboard's front door and redirects there router.SetFuncMap(template.FuncMap{ "rawHTML": func(s string) template.HTML { return template.HTML(s) }, }) router.LoadHTMLGlob("../themes/default/templates/*") - a.On("IsAdmin", mock.Anything).Return(true).Twice() - a.On("IsLoggedIn", mock.Anything).Return(true).Once() + a.On("IsAdmin", mock.Anything).Return(true).Once() req, _ = http.NewRequest("GET", "/admin", bytes.NewBuffer(jsonValue)) w = httptest.NewRecorder() router.ServeHTTP(w, req) - if w.Code != http.StatusOK { - t.Fatalf("Expected to get status %d but instead got %d\n", http.StatusOK, w.Code) + if w.Code != http.StatusFound || w.Header().Get("Location") != "/admin/dashboard" { + t.Fatalf("Expected a %d redirect to /admin/dashboard but got %d %q\n", http.StatusFound, w.Code, w.Header().Get("Location")) + } + + //get admin: not admin -> same 401 as every other admin page, no redirect + a.On("IsAdmin", mock.Anything).Return(false).Once() + req, _ = http.NewRequest("GET", "/admin", nil) + w = httptest.NewRecorder() + router.ServeHTTP(w, req) + if w.Code != http.StatusUnauthorized { + t.Fatalf("Expected to get status %d for non-admin /admin but instead got %d\n", http.StatusUnauthorized, w.Code) } // Create a comment to test deletion @@ -828,11 +838,7 @@ func TestAdminSettings_RendersCheckboxSetting(t *testing.T) { gin.SetMode(gin.TestMode) router := gin.New() router.Use(sessions.Sessions("s", cookie.NewStore([]byte("test")))) - tmpl := template.Must(template.New("").Funcs(template.FuncMap{ - "rawHTML": func(s string) template.HTML { return template.HTML(s) }, - }).ParseGlob("../templates/shared/*.html")) - template.Must(tmpl.ParseGlob("../themes/" + theme + "/templates/*.html")) - router.SetHTMLTemplate(tmpl) + router.SetHTMLTemplate(themeTemplates(t, theme)) router.GET("/admin/settings", ad.AdminSettings) a.On("IsAdmin", mock.Anything).Return(true) @@ -875,11 +881,7 @@ func newUsersHarness(t *testing.T, theme string) (*gin.Engine, *Auth, *gorm.DB) gin.SetMode(gin.TestMode) router := gin.New() router.Use(sessions.Sessions("s", cookie.NewStore([]byte("test")))) - tmpl := template.Must(template.New("").Funcs(template.FuncMap{ - "rawHTML": func(s string) template.HTML { return template.HTML(s) }, - }).ParseGlob("../templates/shared/*.html")) - template.Must(tmpl.ParseGlob("../themes/" + theme + "/templates/*.html")) - router.SetHTMLTemplate(tmpl) + router.SetHTMLTemplate(themeTemplates(t, theme)) router.GET("/admin/users", ad.AdminUsers) router.POST("/api/v1/admins", ad.PromoteAdmin) router.DELETE("/api/v1/admins", ad.DemoteAdmin) @@ -1116,3 +1118,223 @@ func TestDemoteAdminAPI(t *testing.T) { t.Fatalf("expected exactly one admin to remain, got %d", n) } } + +// themeTemplates parses the templates the way theme.Load layers them: the +// shared set, then default, then the named theme on top — so a theme that +// ships no admin templates (minimal) renders default's. +func themeTemplates(t *testing.T, theme string) *template.Template { + t.Helper() + tmpl := template.Must(template.New("").Funcs(template.FuncMap{ + "rawHTML": func(s string) template.HTML { return template.HTML(s) }, + }).ParseGlob("../templates/shared/*.html")) + template.Must(tmpl.ParseGlob("../themes/default/templates/*.html")) + if theme != "default" { + template.Must(tmpl.ParseGlob("../themes/" + theme + "/templates/*.html")) + } + return tmpl +} + +// newAdminHarness wires every admin HTML route over a fresh sqlite DB with a +// real auth.Auth for user management and the given theme's templates. +func newAdminHarness(t *testing.T, theme string) (*gin.Engine, *Auth, *gorm.DB, *admin.Admin) { + t.Helper() + db, _ := gorm.Open(sqlite.Open(":memory:")) + db.AutoMigrate(&auth.BlogUser{}, &auth.AdminUser{}, &blog.PostType{}, &blog.Post{}, &blog.Tag{}, &blog.Comment{}, &blog.Page{}, &blog.Setting{}) + realAuth := auth.New(db, "test") + a := &Auth{real: &realAuth} + b := blog.New(db, a, "test") + ad := admin.New(db, a, &b, "v9.9.9-test") + + gin.SetMode(gin.TestMode) + router := gin.New() + router.Use(sessions.Sessions("s", cookie.NewStore([]byte("test")))) + router.SetHTMLTemplate(themeTemplates(t, theme)) + router.GET("/admin", ad.Admin) + router.GET("/admin/dashboard", ad.AdminDashboard) + router.GET("/admin/posts", ad.AdminPosts) + router.GET("/admin/newpost", ad.AdminNewPost) + router.GET("/admin/pages", ad.AdminPages) + router.GET("/admin/pages/:id", ad.AdminEditPage) + router.GET("/admin/comments", ad.AdminComments) + router.GET("/admin/users", ad.AdminUsers) + router.GET("/admin/post-types", ad.AdminPostTypes) + router.GET("/admin/post-types/:id", ad.AdminEditPostType) + router.GET("/admin/plugins", ad.AdminPlugins) + router.GET("/admin/themes", ad.AdminThemes) + router.GET("/admin/posts/:yyyy/:mm/:dd/:slug", ad.Post) + return router, a, db, &ad +} + +func getHTML(t *testing.T, router *gin.Engine, path string) string { + t.Helper() + w := httptest.NewRecorder() + req, _ := http.NewRequest("GET", path, nil) + router.ServeHTTP(w, req) + if w.Code != http.StatusOK { + t.Fatalf("GET %s: expected 200, got %d: %.300s", path, w.Code, w.Body.String()) + } + return w.Body.String() +} + +// TestAdminDashboard checks the dashboard summary (#596): count tiles that +// link to their admin pages, the newest posts with draft badges linking to +// their admin edit page, recent comments, and the Site panel. +func TestAdminDashboard(t *testing.T) { + router, a, db, _ := newAdminHarness(t, "default") + a.On("IsAdmin", mock.Anything).Return(true) + a.On("IsLoggedIn", mock.Anything).Return(true) + + pt := blog.PostType{Name: "Post", Slug: "posts"} + db.Create(&pt) + base := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) + for i := 1; i <= 7; i++ { + db.Create(&blog.Post{Title: "Dash Post " + strconv.Itoa(i), Slug: "dash-post-" + strconv.Itoa(i), Content: "x", Draft: i == 7, PostTypeID: pt.ID, CreatedAt: base.Add(time.Duration(i) * time.Hour)}) + } + db.Create(&blog.Page{Title: "About", Slug: "about", Enabled: true}) + db.Create(&blog.Comment{PostID: 1, Name: "Commenter", Content: "Nice post"}) + seedUser(t, db, auth.ProviderGitHub, "1", "boss", true) + seedUser(t, db, auth.ProviderGitHub, "2", "plain", false) + db.Create(&blog.Setting{Key: "theme", Value: "minimal"}) + + body := getHTML(t, router, "/admin/dashboard") + + tile := func(id string) string { + re := regexp.MustCompile(`(?s)]*id="tile-` + id + `"[^>]*>.*?`) + m := re.FindString(body) + if m == "" { + t.Fatalf("no %s tile", id) + } + return m + } + if m := tile("posts"); !strings.Contains(m, `href="/admin/posts"`) || !strings.Contains(m, ">6<") || !strings.Contains(m, "1 draft") { + t.Errorf("posts tile should show 6 published, 1 draft and link to /admin/posts: %s", m) + } + if m := tile("pages"); !strings.Contains(m, `href="/admin/pages"`) || !strings.Contains(m, ">1<") { + t.Errorf("pages tile: %s", m) + } + if m := tile("comments"); !strings.Contains(m, `href="/admin/comments"`) || !strings.Contains(m, ">1<") { + t.Errorf("comments tile: %s", m) + } + if m := tile("users"); !strings.Contains(m, `href="/admin/users"`) || !strings.Contains(m, ">2<") { + t.Errorf("users tile: %s", m) + } + + // Recent posts: the latest five, newest first, linking to the admin editor. + rows := regexp.MustCompile(`(?s).*?`).FindAllString(body, -1) + if len(rows) != 5 { + t.Fatalf("expected 5 recent posts, got %d", len(rows)) + } + if !strings.Contains(rows[0], "Dash Post 7") || !strings.Contains(rows[4], "Dash Post 3") { + t.Errorf("recent posts must be newest first and capped at five: %v", rows) + } + var seven blog.Post + db.Preload("PostType").Where("slug = ?", "dash-post-7").First(&seven) + if !strings.Contains(body, `href="`+seven.Adminlink()+`"`) { + t.Errorf("recent post must link to its admin page %s", seven.Adminlink()) + } + if !strings.Contains(body, "Draft") { + t.Errorf("the draft post must carry a Draft badge") + } + if !strings.Contains(body, "Nice post") || !strings.Contains(body, `id="comment-row-`) { + t.Errorf("expected the recent comments table") + } + + // Site panel. + if !strings.Contains(body, `href="/admin/themes"`) || !strings.Contains(body, ">minimal<") { + t.Errorf("site panel must name the active theme and link to /admin/themes") + } + if !strings.Contains(body, `href="/admin/plugins"`) || !strings.Contains(body, "No plugins enabled") { + t.Errorf("site panel must list enabled plugins (none here) and link to /admin/plugins") + } + if !strings.Contains(body, "v9.9.9-test") { + t.Errorf("site panel must show the goblog version") + } + if strings.Contains(body, "Welcome to the admin dashboard") { + t.Errorf("the placeholder welcome text should be gone") + } + if !strings.Contains(body, `class="admin-panel"`) { + t.Errorf("admin content must sit in the opaque admin panel") + } +} + +// TestAdminDashboard_ActiveThemeFromInstaller: when the theme installer is +// wired, its view of the active theme wins over the stored setting. +func TestAdminDashboard_ActiveThemeFromInstaller(t *testing.T) { + router, a, db, ad := newAdminHarness(t, "default") + a.On("IsAdmin", mock.Anything).Return(true) + a.On("IsLoggedIn", mock.Anything).Return(true) + db.Create(&blog.Setting{Key: "theme", Value: "stale"}) + ad.Themes = &tinstaller.Installer{ActiveTheme: func() string { return "ocean" }} + body := getHTML(t, router, "/admin/dashboard") + if !strings.Contains(body, ">ocean<") || strings.Contains(body, ">stale<") { + t.Errorf("expected the installer's active theme") + } +} + +// TestAdminEmptyStates: every list page says so when it has nothing to list, +// with a call to action where one exists (#596). +func TestAdminEmptyStates(t *testing.T) { + for _, theme := range []string{"default", "minimal"} { + t.Run(theme, func(t *testing.T) { + router, a, _, _ := newAdminHarness(t, theme) + a.On("IsAdmin", mock.Anything).Return(true) + a.On("IsLoggedIn", mock.Anything).Return(true) + cases := map[string][]string{ + "/admin/posts": {"No posts yet", `href="/admin/newpost"`}, + "/admin/pages": {"No pages yet", "createPage()"}, + "/admin/post-types": {"No post types yet"}, + "/admin/comments": {"No comments yet"}, + "/admin/users": {"No users yet"}, + "/admin/dashboard": {"No posts yet", "No comments yet"}, + } + for path, wants := range cases { + body := getHTML(t, router, path) + for _, want := range wants { + if !strings.Contains(body, want) { + t.Errorf("%s: missing %q", path, want) + } + } + } + }) + } +} + +// TestAdminPages_RenderInPanel: every admin page wraps its content in the +// opaque panel below the nav, in default and in a theme that ships no admin +// templates of its own (minimal falls back to default's). +func TestAdminPages_RenderInPanel(t *testing.T) { + for _, theme := range []string{"default", "minimal"} { + t.Run(theme, func(t *testing.T) { + router, a, db, _ := newAdminHarness(t, theme) + a.On("IsAdmin", mock.Anything).Return(true) + a.On("IsLoggedIn", mock.Anything).Return(true) + pt := blog.PostType{Name: "Post", Slug: "posts"} + db.Create(&pt) + post := blog.Post{Title: "Panel Post", Slug: "panel-post", Content: "x", PostTypeID: pt.ID} + db.Create(&post) + db.Preload("PostType").First(&post, post.ID) + page := blog.Page{Title: "P", Slug: "p"} + db.Create(&page) + for _, path := range []string{ + "/admin/dashboard", "/admin/posts", "/admin/newpost", "/admin/pages", + "/admin/pages/" + strconv.Itoa(int(page.ID)), "/admin/comments", "/admin/users", + "/admin/post-types", "/admin/post-types/" + strconv.Itoa(int(pt.ID)), + "/admin/plugins", "/admin/themes", post.Adminlink(), + } { + body := getHTML(t, router, path) + if !strings.Contains(body, `class="admin-panel"`) { + t.Errorf("%s: content is not wrapped in .admin-panel", path) + } + if !strings.Contains(body, `href="/css/admin.css"`) { + t.Errorf("%s: admin.css is not linked", path) + } + if !strings.Contains(body, `class="nav-scroller`) { + t.Errorf("%s: admin nav missing", path) + } + if regexp.MustCompile(`class="[^"]*\bh[1-6]\b[^"]*"`).MatchString(body) { + t.Errorf("%s: Tachyons .h1-.h6 class in use (it sets height, not type size)", path) + } + } + }) + } +} diff --git a/admin/themes_test.go b/admin/themes_test.go index dd96fb4d..1baf7aa6 100644 --- a/admin/themes_test.go +++ b/admin/themes_test.go @@ -95,7 +95,8 @@ func newThemesHarness(t *testing.T) *themesHarness { entry := func(name, version string, files map[string][]byte, min string) directory.Entry { return directory.Entry{Kind: registry.KindTheme, Name: name, DisplayName: strings.ToUpper(name), Description: "d " + name, Version: version, Author: "a", License: "MIT", SourceURL: "https://github.com/o/" + name, DownloadURL: h.srv.URL + "/o/" + name + "/archive/refs/tags/v" + version + ".zip", - SHA256: registry.ContentHash(files), MinGoblogVersion: min, InstallType: "theme", AllowedHosts: []string{}, Stars: 1} + SHA256: registry.ContentHash(files), MinGoblogVersion: min, InstallType: "theme", AllowedHosts: []string{}, Stars: 1, + ScreenshotURL: "https://raw.test/o/" + name + "/screenshot.png"} } h.index = []directory.Entry{ entry("ocean", "1.0.0", oceanFiles, "0.5.0"), @@ -211,11 +212,18 @@ func TestThemeAPI_Lifecycle(t *testing.T) { for _, i := range st.Installed { if i.Name == "ocean" { oceanInstalled = true + // The Installed tab renders cards with the directory screenshot. + if i.ScreenshotURL != "https://raw.test/o/ocean/screenshot.png" { + t.Errorf("installed ocean screenshot_url = %q", i.ScreenshotURL) + } } } if !oceanInstalled { t.Errorf("expected ocean installed, got %+v", st.Installed) } + if !strings.Contains(w.Body.String(), `"screenshot_url":"https://raw.test/o/ocean/screenshot.png"`) { + t.Errorf("status JSON must expose screenshot_url for installed themes: %s", w.Body.String()) + } // Activate. w = h.do("POST", "/api/v1/themes/activate", `{"name":"ocean"}`) @@ -299,4 +307,14 @@ func TestAdminThemesPage(t *testing.T) { if !strings.Contains(body, "data-action=") { t.Errorf("page missing data-action= driven controls") } + // Installed themes render as a card grid like Browse (#596), inside the + // opaque admin panel so the page reads on any theme's backdrop. + for _, want := range []string{`id="installed-cards"`, `class="row g-3"`, `class="admin-panel"`, `screenshot_url`, `theme-placeholder`} { + if !strings.Contains(body, want) { + t.Errorf("page missing %q", want) + } + } + if strings.Contains(body, `id="installed-rows"`) { + t.Errorf("installed themes must no longer render as a table") + } } diff --git a/blog/blog.go b/blog/blog.go index 5e11fa9a..e5bc66fa 100644 --- a/blog/blog.go +++ b/blog/blog.go @@ -142,6 +142,35 @@ func (b *Blog) GetLatest() Post { return post } +// GetRecentPosts returns the newest n posts, drafts included, for the admin +// dashboard. +func (b *Blog) GetRecentPosts(n int) []Post { + var posts []Post + (*b.db).Preload("PostType").Order("created_at desc").Limit(n).Find(&posts) + return posts +} + +// CountPosts returns how many posts are published and how many are drafts. +func (b *Blog) CountPosts() (published, drafts int64) { + (*b.db).Model(&Post{}).Where("draft = ?", false).Count(&published) + (*b.db).Model(&Post{}).Where("draft = ?", true).Count(&drafts) + return published, drafts +} + +// CountPages returns the number of pages, enabled or not. +func (b *Blog) CountPages() int64 { + var n int64 + (*b.db).Model(&Page{}).Count(&n) + return n +} + +// CountComments returns the number of comments across all posts. +func (b *Blog) CountComments() int64 { + var n int64 + (*b.db).Model(&Comment{}).Count(&n) + return n +} + func (b *Blog) getTags() []Tag { var tags []Tag (*b.db).Preload("Posts").Order("name asc").Find(&tags) diff --git a/blog/blog_test.go b/blog/blog_test.go index 5584ffa6..1a716b4c 100644 --- a/blog/blog_test.go +++ b/blog/blog_test.go @@ -945,6 +945,46 @@ func TestGetComments(t *testing.T) { } } +// TestDashboardCounts covers the cheap counters and the recent-posts query +// the admin dashboard is built from. +func TestDashboardCounts(t *testing.T) { + db, _ := gorm.Open(sqlite.Open(":memory:")) + db.AutoMigrate(&blog.PostType{}, &blog.Post{}, &blog.Tag{}, &blog.Comment{}, &blog.Page{}) + b := blog.New(db, &Auth{}, "test") + + if pub, drafts := b.CountPosts(); pub != 0 || drafts != 0 { + t.Errorf("empty blog: posts = %d published, %d drafts", pub, drafts) + } + if b.CountPages() != 0 || b.CountComments() != 0 || len(b.GetRecentPosts(5)) != 0 { + t.Error("empty blog should count nothing") + } + + base := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) + for i := 1; i <= 7; i++ { + db.Create(&blog.Post{Title: "p" + strconv.Itoa(i), Slug: "p" + strconv.Itoa(i), Content: "x", Draft: i%3 == 0, CreatedAt: base.Add(time.Duration(i) * time.Hour)}) + } + db.Create(&blog.Page{Title: "About", Slug: "about"}) + db.Create(&blog.Page{Title: "Hidden", Slug: "hidden", Enabled: false}) + db.Create(&blog.Comment{PostID: 1, Name: "c", Content: "x"}) + + if pub, drafts := b.CountPosts(); pub != 5 || drafts != 2 { + t.Errorf("posts = %d published, %d drafts; want 5 and 2", pub, drafts) + } + if n := b.CountPages(); n != 2 { + t.Errorf("pages = %d, want 2 (disabled pages count too)", n) + } + if n := b.CountComments(); n != 1 { + t.Errorf("comments = %d, want 1", n) + } + recent := b.GetRecentPosts(5) + if len(recent) != 5 || recent[0].Title != "p7" || recent[4].Title != "p3" { + t.Errorf("recent = %+v; want p7..p3 newest first", recent) + } + if !recent[1].Draft { + t.Error("recent posts must include drafts") + } +} + // newCommentFixture builds a blog with one post and a /comments route, returning // a submit helper. The mock auth's user field controls who is logged in and // the settings table starts empty, so comments_require_login is at its default. diff --git a/theme/installer/installer.go b/theme/installer/installer.go index 2f8ee0a5..c1fc466c 100644 --- a/theme/installer/installer.go +++ b/theme/installer/installer.go @@ -79,6 +79,9 @@ type Installed struct { Active bool `json:"active"` UpdateAvailable bool `json:"update_available"` LatestVersion string `json:"latest_version,omitempty"` + // ScreenshotURL is the directory's screenshot for the theme, when the + // index lists it; built-in and hand-installed themes have none. + ScreenshotURL string `json:"screenshot_url,omitempty"` } // Available is a directory theme that is not installed. @@ -222,6 +225,7 @@ func (i *Installer) Status() Status { if e, ok := byName[name]; ok && !row.Builtin { row.LatestVersion = e.Version row.UpdateAvailable = row.Version != "" && pinstaller.Newer(e.Version, row.Version) + row.ScreenshotURL = e.ScreenshotURL } st.Installed = append(st.Installed, row) } diff --git a/theme/installer/installer_test.go b/theme/installer/installer_test.go index 1ed549bd..e855ec28 100644 --- a/theme/installer/installer_test.go +++ b/theme/installer/installer_test.go @@ -93,7 +93,8 @@ func newHarness(t *testing.T) *harness { entry := func(name, version string, files map[string][]byte, min string) directory.Entry { return directory.Entry{Kind: registry.KindTheme, Name: name, DisplayName: strings.ToUpper(name), Description: "d", Version: version, Author: "a", License: "MIT", SourceURL: "https://github.com/o/" + name, DownloadURL: h.srv.URL + "/o/" + name + "/archive/refs/tags/v" + version + ".zip", - SHA256: registry.ContentHash(files), MinGoblogVersion: min, InstallType: "theme", AllowedHosts: []string{}, Stars: 1} + SHA256: registry.ContentHash(files), MinGoblogVersion: min, InstallType: "theme", AllowedHosts: []string{}, Stars: 1, + ScreenshotURL: "https://raw.test/o/" + name + "/screenshot.png"} } h.index = []directory.Entry{ entry("ocean", "1.0.0", oceanFiles, "0.5.0"), @@ -175,6 +176,16 @@ func TestInstallActivateUpdateUninstall(t *testing.T) { if ocean.Version != "1.0.0" || ocean.Builtin || ocean.UpdateAvailable { t.Errorf("ocean status = %+v", ocean) } + // The installed row carries the directory's screenshot so the admin page + // can show installed themes as cards; built-ins have none. + if ocean.ScreenshotURL != "https://raw.test/o/ocean/screenshot.png" { + t.Errorf("ocean screenshot = %q", ocean.ScreenshotURL) + } + for _, i := range st.Installed { + if i.Builtin && i.ScreenshotURL != "" { + t.Errorf("built-in %s must not carry a screenshot: %+v", i.Name, i) + } + } if err := h.inst.ActivateTheme("ocean"); err != nil || h.active != "ocean" { t.Errorf("activate: %v active=%s", err, h.active) diff --git a/themes/default/templates/admin_dashboard.html b/themes/default/templates/admin_dashboard.html index 39373c97..a4c6cc0a 100644 --- a/themes/default/templates/admin_dashboard.html +++ b/themes/default/templates/admin_dashboard.html @@ -1,80 +1,132 @@ {{ template "header.html" .}} - -
{{ template "admin_nav.html" . }} +

Dashboard

-

Welcome to the admin dashboard.

-

Recent Comments View all →

- {{ if .recent_comments }} - - - - - - - - - - - - - {{ range .recent_comments }} - - - - - - - - + + +
+
+

Recent Posts View all →

+ {{ if .recent_posts }} +
DateNameEmailCommentPost
{{ .CreatedAt.Format "Jan 02, 2006 15:04" }}{{ .Name }}{{ .Email }}{{ if gt (len .Content) 80 }}{{ slice .Content 0 80 }}...{{ else }}{{ .Content }}{{ end }} - {{ $post := index $.comment_posts .PostID }} - {{ if $post.Title }}{{ $post.Title }}{{ else }}Post #{{ .PostID }}{{ end }} - [delete]
+ + {{ range .recent_posts }} + + + + + {{ end }} + +
{{ .Title }}{{ if .Draft }} Draft{{ end }}{{ .CreatedAt.Format "Jan 02, 2006" }}
+ {{ else }} +

No posts yet. Write your first post.

+ {{ end }} + +

Recent Comments View all →

+ {{ if .recent_comments }} + + + + + + + + + + + + + {{ range .recent_comments }} + + + + + + + + + {{ end }} + +
DateNameEmailCommentPost
{{ .CreatedAt.Format "Jan 02, 2006 15:04" }}{{ .Name }}{{ .Email }}{{ if gt (len .Content) 80 }}{{ slice .Content 0 80 }}...{{ else }}{{ .Content }}{{ end }} + {{ $post := index $.comment_posts .PostID }} + {{ if $post.Title }}{{ $post.Title }}{{ else }}Post #{{ .PostID }}{{ end }} + [delete]
+ {{ else }} +

No comments yet.

{{ end }} - - - {{ else }} -

No comments yet.

- {{ end }} +
+
+

Site

+
+
    +
  • + Theme + {{ .active_theme }} +
  • +
  • +
    + Plugins + Manage → +
    + {{ if .enabled_plugins }} +
      + {{ range .enabled_plugins }} +
    • {{ .DisplayName }}
    • + {{ end }} +
    + {{ else }} +
    No plugins enabled.
    + {{ end }} +
  • +
  • + goblog + {{ .version }} +
  • +
+
+
+
+ diff --git a/themes/default/templates/admin_themes.html b/themes/default/templates/admin_themes.html index 0620f911..290662a5 100644 --- a/themes/default/templates/admin_themes.html +++ b/themes/default/templates/admin_themes.html @@ -1,6 +1,7 @@ {{ template "header.html" .}}
{{ template "admin_nav.html" . }} +

Themes

Browse the theme directory and install themes with one click. Installed themes live under themes/installed/. Themes are code that renders every page, including this admin — install only themes you trust; the directory checks that a theme is well-formed, not that it is benign.

@@ -17,10 +18,7 @@

Themes

- - - -
ThemeVersionTypeActive
Loading…
+
Loading…
@@ -37,6 +35,7 @@

Themes

Loading…
+