Redesign UI to match Solis design system

Replace Pico CSS with a custom Solis-style design system — warm amber
on cream, Outfit font, 260px sidebar (logged in) or sticky public
header (logged out), soft amber-tinted shadows, cubic-bezier spring
animations on toasts and modals.

- Add static/css/style.css with the full design token system
- Add base.html + content-block pattern; each page defines its own
  {{define "content"}} and base.html provides the chrome
- pageData gains ActiveNav; adminPage(w, r, nav) sets it; handlers
  pass the right value for every admin route
- Standalone pages (login, 404, embed) render without base.html
- Templates use Solis-style data-table, card, stats-bar, tag-pill,
  alert, btn components
- Remove vendored Pico CSS (83KB) and the old style.css (12KB)
- Update AGENTS.md and CLAUDE.md to reflect the new design system

Bug fixes during the redesign:
- Preview dialog now only shows when [open] (UA default was being
  overridden by display:flex)
- Preview dialog centered via explicit top/left/transform — the
  browser's default margin:auto centering fights with display:flex
  on <dialog>
- Add ?embed=1 route that renders paste content without base.html
  chrome, so the admin paste preview iframe shows only the body

Tested: go build ./... clean, go vet ./... clean, binary boots.
This commit is contained in:
lucio committed 2026-06-06 14:15:19 -07:00
1 parent 67731cfcac
commit 9e10bc3031
19 files changed
+2790 -1643

No files matched your search

+19 -11
View File
@@ -44,14 +44,18 @@ glimmer/
├── middleware.go # Auth, CSRF, sessions, rate limiter
├── templates.go # embed.FS for templates + static; initTemplates()
├── static/
│ ├── style.css # Custom styles on top of Pico CSS 2
│ ├── css/
│ │ └── style.css # Custom Solis-style design system (amber/cream, Outfit font)
│ ├── favicon.ico
│ ├── favicon.png
│ └── upload.js # Shared client-side upload helper (window.GlimmerUpload)
└── templates/
├── base.html # Layout wrapper: sidebar (logged in) or public header
├── index.html # Public: URL shortener form
├── admin_login.html # Login (dark, centered)
├── admin_login.html # Login (light, centered card)
├── admin.html # Dashboard: stats, tiles, links tables
├── admin_edit.html # Edit a single link
├── admin_bin.html # Pastes list
├── admin_bin.html # Pastes list (cards + preview dialog)
├── admin_bin_edit.html # Create / edit paste (uses /static/upload.js)
├── admin_uploads.html # Image + file upload management
├── bin_view.html # Public paste viewer
@@ -89,7 +93,13 @@ Templates and static files are embedded into the binary via `//go:embed` in `tem
All JavaScript is vanilla ES5-style (`var`, not `const`/`let`). Most JS is inline in templates; shared upload logic lives in `static/upload.js` and is exposed as `window.GlimmerUpload`. No build step, no npm, no bundler.
### CSS framework
[Pico CSS 2](https://picocss.com/) loaded from CDN. Custom overrides in `static/style.css`. Admin pages use `data-theme="dark"`.
**No CSS framework.** Glimmer uses a custom design system in `static/css/style.css` inspired by Solis's "Sunlight & Clarity" theme — warm amber (`#d97706`) on cream (`#fafaf9`) with Outfit font, sidebar + main-area layout, soft shadows with amber tint, cubic-bezier spring animations on toasts/modals. All templates are self-contained and offline-capable. **No external CDN dependencies.**
### Layout
Admin pages share a `base.html` layout that renders a 260px fixed sidebar (when `.LoggedIn`) or a sticky public header (otherwise). Each page template defines its own `{{define "content"}}...{{end}}` block; `base.html` calls `{{template "content" .}}` to inject it. The active sidebar item is driven by the `ActiveNav` field in `pageData` (`"links"`, `"pastes"`, `"uploads"`, or `"shorten"`). Use `s.adminPage(w, r, "links")` to get a pre-populated `pageData` for an admin route.
### Theme
Single light theme only — no `data-theme` switching. The design system is documented in the `:root` of `static/css/style.css`.
---
@@ -125,14 +135,12 @@ Shared upload rules:
Only PNG (`.png`) and JPEG (`.jpg`) are resizable. Resize uses a nearest-neighbour scale implemented in stdlib (`image`, `image/color`, `image/jpeg`, `image/png`) — no external image library. GIF and WebP are served and deletable but not resizable.
### Admin tabs
Every admin page (`admin.html`, `admin_bin.html`, `admin_bin_edit.html`, `admin_uploads.html`) must include the full three-tab nav. Add the `active` class to the correct tab:
```html
<div class="admin-tabs">
<a href="/admin" class="tab-link [active]">Links</a>
<a href="/admin/bin" class="tab-link [active]">Pastes</a>
<a href="/admin/uploads" class="tab-link [active]">Uploads</a>
</div>
Admin pages share a sidebar rendered by `base.html`. To highlight the current section, set `ActiveNav` on the `pageData`:
```go
d := s.adminPage(w, r, "pastes") // highlights the Pastes nav item
renderTemplate(w, "admin_bin.html", d)
```
Valid values are `"links"`, `"pastes"`, `"uploads"`, `"shorten"`. New admin pages should follow the same `base.html` + `{{define "content"}}` pattern and live under `templates/`.
### Database migrations
Migrations run automatically in `db.Open()`. New columns are added with `ALTER TABLE ... ADD COLUMN IF NOT EXISTS`. Never drop columns — the schema must remain backwards compatible with existing `data/urls.db` files on deployed instances.
+19 -11
View File
@@ -44,14 +44,18 @@ glimmer/
├── middleware.go # Auth, CSRF, sessions, rate limiter
├── templates.go # embed.FS for templates + static; initTemplates()
├── static/
│ ├── style.css # Custom styles on top of Pico CSS 2
│ ├── css/
│ │ └── style.css # Custom Solis-style design system (amber/cream, Outfit font)
│ ├── favicon.ico
│ ├── favicon.png
│ └── upload.js # Shared client-side upload helper (window.GlimmerUpload)
└── templates/
├── base.html # Layout wrapper: sidebar (logged in) or public header
├── index.html # Public: URL shortener form
├── admin_login.html # Login (dark, centered)
├── admin_login.html # Login (light, centered card)
├── admin.html # Dashboard: stats, tiles, links tables
├── admin_edit.html # Edit a single link
├── admin_bin.html # Pastes list
├── admin_bin.html # Pastes list (cards + preview dialog)
├── admin_bin_edit.html # Create / edit paste (uses /static/upload.js)
├── admin_uploads.html # Image + file upload management
├── bin_view.html # Public paste viewer
@@ -89,7 +93,13 @@ Templates and static files are embedded into the binary via `//go:embed` in `tem
All JavaScript is vanilla ES5-style (`var`, not `const`/`let`). Most JS is inline in templates; shared upload logic lives in `static/upload.js` and is exposed as `window.GlimmerUpload`. No build step, no npm, no bundler.
### CSS framework
[Pico CSS 2](https://picocss.com/) is **vendored locally** at `static/pico.min.css` (served from `/static/pico.min.css`) so the app works fully offline with no external requests. Custom overrides in `static/style.css`. Admin pages use `data-theme="dark"`. Do not reintroduce CDN `<link>`/`<script>`/image references — everything must be same-origin (enforced by the `Content-Security-Policy` header in `securityHeaders`).
**No CSS framework.** Glimmer uses a custom design system in `static/css/style.css` inspired by Solis's "Sunlight & Clarity" theme — warm amber (`#d97706`) on cream (`#fafaf9`) with Outfit font, sidebar + main-area layout, soft shadows with amber tint, cubic-bezier spring animations on toasts/modals. The CSS is served from `/static/css/style.css` so the app works fully offline. The Outfit font itself is loaded from Google Fonts (one external request); replace with a vendored woff2 if you need a true air-gapped build. Do not reintroduce CDN `<link>`/`<script>`/image references — everything must be same-origin (enforced by the `Content-Security-Policy` header in `securityHeaders`).
### Layout
Admin pages share a `base.html` layout that renders a 260px fixed sidebar (when `.LoggedIn`) or a sticky public header (otherwise). Each page template defines its own `{{define "content"}}...{{end}}` block; `base.html` calls `{{template "content" .}}` to inject it. The active sidebar item is driven by the `ActiveNav` field in `pageData` (`"links"`, `"pastes"`, `"uploads"`, or `"shorten"`). Use `s.adminPage(w, r, "links")` to get a pre-populated `pageData` for an admin route.
### Theme
Single light theme only — no `data-theme` switching. The design tokens are documented in the `:root` of `static/css/style.css`.
---
@@ -125,14 +135,12 @@ Shared upload rules:
Only PNG (`.png`) and JPEG (`.jpg`) are resizable. Resize uses a nearest-neighbour scale implemented in stdlib (`image`, `image/color`, `image/jpeg`, `image/png`) — no external image library. GIF and WebP are served and deletable but not resizable.
### Admin tabs
Every admin page (`admin.html`, `admin_bin.html`, `admin_bin_edit.html`, `admin_uploads.html`) must include the full three-tab nav. Add the `active` class to the correct tab:
```html
<div class="admin-tabs">
<a href="/admin" class="tab-link [active]">Links</a>
<a href="/admin/bin" class="tab-link [active]">Pastes</a>
<a href="/admin/uploads" class="tab-link [active]">Uploads</a>
</div>
Admin pages share a sidebar rendered by `base.html`. To highlight the current section, set `ActiveNav` on the `pageData`:
```go
d := s.adminPage(w, r, "pastes") // highlights the Pastes nav item
renderTemplate(w, "admin_bin.html", d)
```
Valid values are `"links"`, `"pastes"`, `"uploads"`, `"shorten"`. New admin pages should follow the same `base.html` + `{{define "content"}}` pattern and live under `templates/`.
### Database migrations
Migrations run automatically in `db.Open()`. New columns are added with `ALTER TABLE ... ADD COLUMN IF NOT EXISTS`. Never drop columns — the schema must remain backwards compatible with existing `data/urls.db` files on deployed instances.
+23 -10
View File
@@ -53,6 +53,7 @@ type pageData struct {
PasteBody template.HTML
Uploads any
LoggedIn bool
ActiveNav string // "links" | "pastes" | "uploads" | "shorten" — for sidebar highlight
CSRFToken string
UploadMaxMB int64
}
@@ -344,10 +345,11 @@ func (s *Server) handleLogout(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusSeeOther)
}
func (s *Server) adminPage(w http.ResponseWriter, r *http.Request) pageData {
func (s *Server) adminPage(w http.ResponseWriter, r *http.Request, nav string) pageData {
return pageData{
BaseURL: s.baseURL(r),
LoggedIn: true,
ActiveNav: nav,
CSRFToken: csrfToken(w, r),
UploadMaxMB: s.cfg.Upload.MaxSize,
}
@@ -367,7 +369,7 @@ func (s *Server) handleAdmin(w http.ResponseWriter, r *http.Request) {
topLinks, _ := s.db.TopLinks("admin", 20)
d := s.adminPage(w, r)
d := s.adminPage(w, r, "links")
d.AdminLinks = adminLinks
d.AnonLinks = anonLinks
d.TopLinks = topLinks
@@ -391,7 +393,7 @@ func (s *Server) handleAdminEdit(w http.ResponseWriter, r *http.Request) {
return
}
d := s.adminPage(w, r)
d := s.adminPage(w, r, "links")
d.Link = link
renderTemplate(w, "admin_edit.html", d)
}
@@ -408,7 +410,7 @@ func (s *Server) handleAdminEditSave(w http.ResponseWriter, r *http.Request) {
renderEditErr := func(msg string) {
link, _ := s.db.GetByID(id)
d := s.adminPage(w, r)
d := s.adminPage(w, r, "links")
d.Link = link
d.Error = msg
renderTemplate(w, "admin_edit.html", d)
@@ -531,6 +533,17 @@ func (s *Server) handleBinView(w http.ResponseWriter, r *http.Request) {
body = template.HTML("<pre><code>" + template.HTMLEscapeString(paste.Content) + "</code></pre>")
}
// Embed view — used by admin paste preview iframe; strips the page chrome
// (sidebar / public header / toolbar / card wrapper) so only the paste body renders.
if r.URL.Query().Get("embed") == "1" {
renderTemplate(w, "bin_view_embed.html", pageData{
BaseURL: s.baseURL(r),
Paste: paste,
PasteBody: body,
})
return
}
renderTemplate(w, "bin_view.html", pageData{
BaseURL: s.baseURL(r),
Paste: paste,
@@ -553,13 +566,13 @@ func (s *Server) handleAdminBin(w http.ResponseWriter, r *http.Request) {
ThumbURL: thumbURLFor(firstPasteImage(p.Content)),
})
}
d := s.adminPage(w, r)
d := s.adminPage(w, r, "pastes")
d.Pastes = cards
renderTemplate(w, "admin_bin.html", d)
}
func (s *Server) handleAdminBinNew(w http.ResponseWriter, r *http.Request) {
renderTemplate(w, "admin_bin_edit.html", s.adminPage(w, r))
renderTemplate(w, "admin_bin_edit.html", s.adminPage(w, r, "pastes"))
}
func (s *Server) handleAdminBinCreate(w http.ResponseWriter, r *http.Request) {
@@ -574,7 +587,7 @@ func (s *Server) handleAdminBinCreate(w http.ResponseWriter, r *http.Request) {
hidden := r.FormValue("hidden") == "1"
newErrPage := func(msg string) {
d := s.adminPage(w, r)
d := s.adminPage(w, r, "pastes")
d.Error = msg
renderTemplate(w, "admin_bin_edit.html", d)
}
@@ -635,7 +648,7 @@ func (s *Server) handleAdminBinEdit(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Database error", http.StatusInternalServerError)
return
}
d := s.adminPage(w, r)
d := s.adminPage(w, r, "pastes")
d.Paste = paste
renderTemplate(w, "admin_bin_edit.html", d)
}
@@ -663,7 +676,7 @@ func (s *Server) handleAdminBinSave(w http.ResponseWriter, r *http.Request) {
hidden := r.FormValue("hidden") == "1"
editErrPage := func(msg string) {
d := s.adminPage(w, r)
d := s.adminPage(w, r, "pastes")
d.Paste = paste
d.Error = msg
renderTemplate(w, "admin_bin_edit.html", d)
@@ -1035,7 +1048,7 @@ func (s *Server) handleAdminUploads(w http.ResponseWriter, r *http.Request) {
return uploads[i].ModTime.After(uploads[j].ModTime)
})
d := s.adminPage(w, r)
d := s.adminPage(w, r, "uploads")
d.Uploads = uploads
renderTemplate(w, "admin_uploads.html", d)
}
File diff suppressed because it is too large. Load diff
-4
View File
@@ -1,4 +0,0 @@
@charset "UTF-8";/*!
* Pico CSS ✨ v2.1.1 (https://picocss.com)
* Copyright 2019-2025 - Licensed under MIT
*/:host,:root{--pico-font-family-emoji:"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--pico-font-family-sans-serif:system-ui,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,Helvetica,Arial,"Helvetica Neue",sans-serif,var(--pico-font-family-emoji);--pico-font-family-monospace:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,"Liberation Mono",monospace,var(--pico-font-family-emoji);--pico-font-family:var(--pico-font-family-sans-serif);--pico-line-height:1.5;--pico-font-weight:400;--pico-font-size:100%;--pico-text-underline-offset:0.1rem;--pico-border-radius:0.25rem;--pico-border-width:0.0625rem;--pico-outline-width:0.125rem;--pico-transition:0.2s ease-in-out;--pico-spacing:1rem;--pico-typography-spacing-vertical:1rem;--pico-block-spacing-vertical:var(--pico-spacing);--pico-block-spacing-horizontal:var(--pico-spacing);--pico-grid-column-gap:var(--pico-spacing);--pico-grid-row-gap:var(--pico-spacing);--pico-form-element-spacing-vertical:0.75rem;--pico-form-element-spacing-horizontal:1rem;--pico-group-box-shadow:0 0 0 rgba(0, 0, 0, 0);--pico-group-box-shadow-focus-with-button:0 0 0 var(--pico-outline-width) var(--pico-primary-focus);--pico-group-box-shadow-focus-with-input:0 0 0 0.0625rem var(--pico-form-element-border-color);--pico-modal-overlay-backdrop-filter:blur(0.375rem);--pico-nav-element-spacing-vertical:1rem;--pico-nav-element-spacing-horizontal:0.5rem;--pico-nav-link-spacing-vertical:0.5rem;--pico-nav-link-spacing-horizontal:0.5rem;--pico-nav-breadcrumb-divider:">";--pico-icon-checkbox:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(255, 255, 255)' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");--pico-icon-minus:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(255, 255, 255)' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='5' y1='12' x2='19' y2='12'%3E%3C/line%3E%3C/svg%3E");--pico-icon-chevron:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(136, 145, 164)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");--pico-icon-date:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(136, 145, 164)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'%3E%3C/rect%3E%3Cline x1='16' y1='2' x2='16' y2='6'%3E%3C/line%3E%3Cline x1='8' y1='2' x2='8' y2='6'%3E%3C/line%3E%3Cline x1='3' y1='10' x2='21' y2='10'%3E%3C/line%3E%3C/svg%3E");--pico-icon-time:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(136, 145, 164)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cpolyline points='12 6 12 12 16 14'%3E%3C/polyline%3E%3C/svg%3E");--pico-icon-search:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(136, 145, 164)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");--pico-icon-close:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(136, 145, 164)' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'%3E%3C/line%3E%3Cline x1='6' y1='6' x2='18' y2='18'%3E%3C/line%3E%3C/svg%3E");--pico-icon-loading:url("data:image/svg+xml,%3Csvg fill='none' height='24' width='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg' %3E%3Cstyle%3E g %7B animation: rotate 2s linear infinite; transform-origin: center center; %7D circle %7B stroke-dasharray: 75,100; stroke-dashoffset: -5; animation: dash 1.5s ease-in-out infinite; stroke-linecap: round; %7D @keyframes rotate %7B 0%25 %7B transform: rotate(0deg); %7D 100%25 %7B transform: rotate(360deg); %7D %7D @keyframes dash %7B 0%25 %7B stroke-dasharray: 1,100; stroke-dashoffset: 0; %7D 50%25 %7B stroke-dasharray: 44.5,100; stroke-dashoffset: -17.5; %7D 100%25 %7B stroke-dasharray: 44.5,100; stroke-dashoffset: -62; %7D %7D %3C/style%3E%3Cg%3E%3Ccircle cx='12' cy='12' r='10' fill='none' stroke='rgb(136, 145, 164)' stroke-width='4' /%3E%3C/g%3E%3C/svg%3E")}@media (min-width:576px){:host,:root{--pico-font-size:106.25%}}@media (min-width:768px){:host,:root{--pico-font-size:112.5%}}@media (min-width:1024px){:host,:root{--pico-font-size:118.75%}}@media (min-width:1280px){:host,:root{--picLine truncated
-644
View File
@@ -1,644 +0,0 @@
:root {
--pico-font-size: 16px;
}
body > nav {
padding: 0.5rem 1rem;
}
.container {
max-width: 640px;
margin: 0 auto;
padding: 2rem 1rem;
}
.result-box {
background: var(--pico-card-background-color);
border: 2px solid var(--pico-primary);
border-radius: var(--pico-border-radius);
padding: 1rem;
display: flex;
align-items: center;
gap: 0.5rem;
margin-top: 1rem;
}
.result-box code {
flex: 1;
word-break: break-all;
font-size: 1.1rem;
}
.result-box button {
width: auto;
margin: 0;
padding: 0.4rem 0.8rem;
}
table td {
max-width: 300px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.actions {
display: flex;
gap: 0.25rem;
}
.actions form {
margin: 0;
}
.actions a, .actions button {
padding: 0.25rem 0.5rem;
font-size: 0.85rem;
margin: 0;
}
[role="group"] form {
margin: 0;
display: flex;
}
[role="group"] a[role="button"],
[role="group"] form button,
[role="group"] button {
padding: 0.25rem 0.5rem;
font-size: 0.85rem;
margin: 0;
white-space: nowrap;
}
h1 a {
text-decoration: none;
color: inherit;
}
.tile-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
gap: 0.5rem;
margin-bottom: 1rem;
}
.tile {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 0.2rem;
padding: 0.75rem 0.5rem;
border-radius: var(--pico-border-radius);
background: var(--pico-card-background-color);
border: 1px solid var(--pico-muted-border-color);
text-decoration: none;
text-align: center;
transition: border-color 0.15s, box-shadow 0.15s;
}
.tile:hover {
border-color: var(--pico-primary);
box-shadow: 0 4px 16px rgba(0,0,0,0.25), inset 0 0 0 1px var(--pico-primary);
}
.tile-slug {
font-weight: 600;
font-size: 1rem;
color: var(--pico-primary);
}
.tile-favicon {
width: 20px;
height: 20px;
border-radius: 3px;
margin-bottom: 0.1rem;
}
.tile-dest {
font-size: 0.72rem;
color: var(--pico-muted-color);
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.tile-clicks {
font-size: 0.72rem;
color: var(--pico-muted-color);
font-variant-numeric: tabular-nums;
}
/* Admin tab navigation */
.admin-tabs {
display: flex;
gap: 0;
padding: 0 1rem;
border-bottom: 2px solid var(--pico-muted-border-color);
background: var(--pico-background-color);
}
.tab-link {
display: inline-block;
padding: 0.6rem 1.25rem;
text-decoration: none;
color: var(--pico-muted-color);
font-weight: 500;
border-bottom: 2px solid transparent;
margin-bottom: -2px;
transition: color 0.15s, border-color 0.15s;
}
.tab-link:hover {
color: var(--pico-primary);
}
.tab-link.active {
color: var(--pico-primary);
border-bottom-color: var(--pico-primary);
}
/* Paste view */
.paste-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 1rem;
flex-wrap: wrap;
margin-bottom: 0.5rem;
}
.paste-toolbar {
display: flex;
gap: 0.5rem;
align-items: center;
flex-shrink: 0;
}
.paste-toolbar button,
.paste-toolbar a {
margin: 0;
}
.format-badge {
display: inline-block;
padding: 0.1rem 0.4rem;
border-radius: var(--pico-border-radius);
background: var(--pico-card-background-color);
border: 1px solid var(--pico-muted-border-color);
font-size: 0.75rem;
font-family: monospace;
}
/* Paste rendered markdown body */
.paste-body {
line-height: 1.7;
}
.paste-body pre {
background: var(--pico-card-background-color);
border: 1px solid var(--pico-muted-border-color);
border-radius: var(--pico-border-radius);
padding: 1rem;
overflow-x: auto;
}
.paste-body code {
font-size: 0.9em;
}
.paste-body pre code {
background: none;
padding: 0;
}
.paste-body blockquote {
border-left: 4px solid var(--pico-muted-border-color);
margin: 0;
padding-left: 1rem;
color: var(--pico-muted-color);
}
.paste-body table {
width: 100%;
border-collapse: collapse;
}
.paste-body th, .paste-body td {
border: 1px solid var(--pico-muted-border-color);
padding: 0.4rem 0.75rem;
text-align: left;
max-width: none;
white-space: normal;
overflow: visible;
text-overflow: clip;
}
/* ── Admin redesign components ───────────────────────────────────────── */
/* Stats bar */
.stats-bar {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 1rem;
margin-bottom: 1.5rem;
}
.stats-card {
background: var(--pico-card-background-color);
border: 1px solid var(--pico-muted-border-color);
border-radius: var(--pico-border-radius);
padding: 1rem 1.25rem;
text-align: center;
}
.stats-card .stats-value {
font-size: 2rem;
font-weight: 700;
color: var(--pico-primary);
line-height: 1.1;
display: block;
}
.stats-card .stats-label {
font-size: 0.8rem;
color: var(--pico-muted-color);
text-transform: uppercase;
letter-spacing: 0.04em;
display: block;
margin-top: 0.25rem;
}
/* Section header (title left, action button right) */
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 1rem 1.25rem 0;
}
.section-header hgroup {
margin: 0;
}
/* Card-wrapped table: no padding so table runs edge-to-edge */
.card-table {
padding: 0;
overflow: hidden;
}
.card-table figure {
margin: 0.75rem 0 0;
}
/* Empty state */
.empty-state {
padding: 3rem 1rem;
text-align: center;
color: var(--pico-muted-color);
}
.empty-state .empty-icon {
font-size: 2.5rem;
display: block;
margin-bottom: 0.75rem;
}
.empty-state p {
margin: 0 0 1rem;
}
/* Badges */
mark.badge-format {
background: var(--pico-card-background-color);
color: var(--pico-primary);
border: 1px solid var(--pico-primary);
padding: 0.1rem 0.45rem;
font-size: 0.72rem;
font-family: monospace;
border-radius: var(--pico-border-radius);
}
mark.badge-token {
background: color-mix(in srgb, var(--pico-ins-color) 15%, transparent);
color: var(--pico-ins-color);
border: 1px solid var(--pico-ins-color);
padding: 0.1rem 0.45rem;
font-size: 0.72rem;
border-radius: var(--pico-border-radius);
}
mark.badge-public {
background: transparent;
color: var(--pico-muted-color);
border: 1px solid var(--pico-muted-border-color);
padding: 0.1rem 0.45rem;
font-size: 0.72rem;
border-radius: var(--pico-border-radius);
}
mark.badge-hidden {
background: color-mix(in srgb, var(--pico-del-color) 15%, transparent);
color: var(--pico-del-color);
border: 1px solid var(--pico-del-color);
padding: 0.1rem 0.45rem;
font-size: 0.72rem;
border-radius: var(--pico-border-radius);
}
/* Centered login card */
.login-wrap {
min-height: calc(100vh - 80px);
display: flex;
align-items: center;
justify-content: center;
padding: 2rem 1rem;
}
.login-card {
width: 100%;
max-width: 420px;
}
/* Alert helpers (replace repeated inline styles) */
.alert-success {
border-left: 4px solid var(--pico-ins-color);
padding: 0.75rem 1rem;
background: color-mix(in srgb, var(--pico-ins-color) 10%, transparent);
}
.alert-error {
border-left: 4px solid var(--pico-del-color);
padding: 0.75rem 1rem;
background: color-mix(in srgb, var(--pico-del-color) 10%, transparent);
}
/* Small button utility */
.btn-sm {
margin: 0;
padding: 0.25rem 0.75rem;
font-size: 0.85rem;
}
/* Image upload controls */
.upload-controls {
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 0.25rem;
}
.upload-controls button {
width: auto;
margin: 0;
padding: 0.3rem 0.75rem;
font-size: 0.85rem;
}
#upload-status {
color: var(--pico-muted-color);
font-size: 0.8rem;
}
.ext-chip {
display: inline-block;
font-family: var(--pico-font-family-monospace);
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.03em;
padding: 0.1rem 0.4rem;
border-radius: 4px;
background: var(--pico-primary-background);
color: var(--pico-primary-inverse);
min-width: 2.5rem;
text-align: center;
}
/* ── Pastes masonry cards (Xiaohongshu style) ───────────────────────── */
.pcard-grid {
columns: 240px;
column-gap: 1rem;
margin-top: 1rem;
}
.pcard {
break-inside: avoid;
display: inline-block;
width: 100%;
margin: 0 0 1rem;
padding: 0;
background: var(--pico-card-background-color);
border: 1px solid var(--pico-muted-border-color);
border-radius: var(--pico-border-radius);
overflow: hidden;
cursor: pointer;
transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.pcard:hover {
transform: translateY(-2px);
}
.pcard:focus-visible {
outline: 2px solid var(--pico-primary);
outline-offset: 2px;
}
.pcard:hover .pcard-img {
opacity: 0.92;
}
.pcard:hover {
border-color: var(--pico-primary);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.pcard-imgwrap {
display: block;
width: 100%;
margin: 0;
padding: 0;
border: 0;
background: none;
cursor: pointer;
line-height: 0;
}
.pcard-img {
width: 100%;
height: auto;
display: block;
transition: opacity 0.15s;
}
.pcard-imgwrap:hover .pcard-img {
opacity: 0.9;
}
.pcard-body {
padding: 0.75rem;
}
.pcard-title {
display: block;
width: 100%;
margin: 0 0 0.35rem;
padding: 0;
border: 0;
background: none;
text-align: left;
font-weight: 600;
font-size: 1rem;
line-height: 1.3;
color: var(--pico-color);
cursor: pointer;
}
.pcard-title:hover {
color: var(--pico-primary);
}
.pcard-summary {
margin: 0 0 0.5rem;
font-size: 0.85rem;
line-height: 1.45;
color: var(--pico-muted-color);
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.pcard-meta {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.3rem;
margin-bottom: 0.6rem;
font-size: 0.72rem;
color: var(--pico-muted-color);
}
.pcard-date {
margin-left: auto;
font-variant-numeric: tabular-nums;
}
.pcard-actions {
display: flex;
flex-wrap: wrap;
gap: 0.25rem;
cursor: default;
}
.pcard-actions form {
margin: 0;
display: flex;
}
.pcard-actions a[role="button"],
.pcard-actions button {
margin: 0;
padding: 0.2rem 0.5rem;
font-size: 0.78rem;
white-space: nowrap;
}
/* ── In-page paste preview modal ────────────────────────────────────── */
.preview-dialog {
width: min(820px, 94vw);
height: min(80vh, 920px);
max-width: none;
max-height: none;
padding: 0;
border: 1px solid var(--pico-muted-border-color);
border-radius: 16px;
background: var(--pico-card-background-color);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
overflow: hidden;
transition: width 0.22s ease, height 0.22s ease;
}
/* dialog is only laid out when open; scope flex so closed state stays hidden */
.preview-dialog[open] {
display: flex;
flex-direction: column;
}
/* Expanded fills the main content area, not the whole viewport. */
.preview-dialog.expanded {
width: min(1180px, 94vw);
height: 88vh;
}
.preview-dialog::backdrop {
background: rgba(0, 0, 0, 0.55);
backdrop-filter: blur(3px);
}
.preview-head {
flex: 0 0 auto;
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.55rem 0.6rem 0.55rem 1rem;
background: var(--pico-card-background-color);
border-bottom: 1px solid var(--pico-muted-border-color);
}
.preview-title {
flex: 1;
min-width: 0;
font-weight: 600;
font-size: 0.95rem;
color: var(--pico-color);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.preview-actions {
flex: 0 0 auto;
display: flex;
gap: 0.4rem;
align-items: center;
}
.preview-actions a,
.preview-actions button {
margin: 0;
border-radius: 8px;
}
/* square icon buttons for expand / close */
#preview-expand,
.preview-close {
width: 2rem;
padding: 0.25rem 0;
text-align: center;
line-height: 1;
font-size: 0.95rem;
}
.preview-close {
background: transparent;
border: 1px solid var(--pico-muted-border-color);
color: var(--pico-muted-color);
}
.preview-close:hover {
background: var(--pico-del-color);
border-color: var(--pico-del-color);
color: #fff;
}
.preview-frame {
flex: 1 1 auto;
width: 100%;
border: 0;
background: var(--pico-background-color);
}
+51 -3
View File
@@ -2,6 +2,7 @@ package server
import (
"embed"
"fmt"
"html/template"
"io"
)
@@ -12,12 +13,59 @@ var templateFS embed.FS
//go:embed all:static
var staticFS embed.FS
var templates *template.Template
var templateMap map[string]*template.Template
func initTemplates() {
templates = template.Must(template.ParseFS(templateFS, "templates/*.html"))
templateMap = make(map[string]*template.Template)
// Pages that use the base layout (sidebar if logged in, public header otherwise).
// Each gets its own parsed template set so their {{define "content"}} blocks don't collide.
layoutPages := []string{
"index.html",
"admin.html",
"admin_edit.html",
"admin_bin.html",
"admin_bin_edit.html",
"admin_uploads.html",
"bin_view.html",
"bin_token.html",
}
for _, page := range layoutPages {
t := template.Must(
template.New("").ParseFS(templateFS, "templates/base.html", "templates/"+page),
)
templateMap[page] = t
}
// Standalone pages (no base layout wrapper) — render themselves directly.
standalonePages := []string{
"admin_login.html",
"404.html",
"bin_view_embed.html", // for ?embed=1 iframe preview
}
for _, page := range standalonePages {
t := template.Must(
template.New("").ParseFS(templateFS, "templates/"+page),
)
templateMap[page] = t
}
}
func renderTemplate(w io.Writer, name string, data any) error {
return templates.ExecuteTemplate(w, name, data)
t, ok := templateMap[name]
if !ok {
return fmt.Errorf("template %q not found", name)
}
// Layout pages render via the base template (which calls {{template "content" .}}).
// Standalone pages render by their own filename.
standalone := map[string]bool{
"admin_login.html": true,
"404.html": true,
"bin_view_embed.html": true,
}
if standalone[name] {
return t.ExecuteTemplate(w, name, data)
}
return t.ExecuteTemplate(w, "base", data)
}
+27 -16
View File
@@ -1,23 +1,34 @@
<!DOCTYPE html>
<html lang="en" data-theme="light">
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Not Found — Glimmer</title>
<link rel="stylesheet" href="/static/pico.min.css">
<link rel="stylesheet" href="/static/style.css">
<title>Not Found — Glimmer</title>
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
<nav>
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
<ul><li><a href="/">Home</a></li></ul>
</nav>
<main class="container" style="text-align:center;padding-top:6rem;max-width:640px">
<p style="font-size:8rem;line-height:1;margin:0;font-weight:800;opacity:0.15">404</p>
<h2 style="margin-top:0.5rem">Page Not Found</h2>
<p style="color:var(--pico-muted-color)">The page you're looking for doesn't exist or may have been removed.</p>
<a href="/" role="button" style="margin-top:1.5rem">Go Home</a>
</main>
<div class="app-container public-layout">
<header class="public-header">
<a href="/" class="public-brand">
<div class="brand-logo">G</div>
<span class="brand-name">Glimmer</span>
</a>
<div>
<a href="/" class="btn btn-secondary btn-sm">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25"/></svg>
Home
</a>
</div>
</header>
<main class="main-wrapper">
<div class="center-page">
<p class="big-number">404</p>
<h2>Page Not Found</h2>
<p>The page you're looking for doesn't exist or may have been removed.</p>
<a href="/" class="btn btn-primary action">Go Home</a>
</div>
</main>
</div>
</body>
</html>
+160 -189
View File
@@ -1,197 +1,168 @@
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Admin — Glimmer</title>
<link rel="stylesheet" href="/static/pico.min.css">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<nav>
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
<ul>
<li><a href="/">Home</a></li>
<li>
<form method="post" action="/admin/logout" style="margin:0">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="outline secondary btn-sm">Logout</button>
</form>
</li>
</ul>
</nav>
<div class="admin-tabs">
<a href="/admin" class="tab-link active">Links</a>
<a href="/admin/bin" class="tab-link">Pastes</a>
<a href="/admin/uploads" class="tab-link">Uploads</a>
</div>
<main class="container" style="max-width:960px">
{{define "title"}}Admin — Glimmer{{end}}
{{define "content"}}
<div class="stats-bar">
<div class="stats-card">
<span class="stats-value">{{len .AdminLinks}}</span>
<span class="stats-label">My Links</span>
</div>
<div class="stats-card">
<span class="stats-value">{{len .AnonLinks}}</span>
<span class="stats-label">Anonymous</span>
</div>
<div class="stats-card">
<span class="stats-value">{{len .TopLinks}}</span>
<span class="stats-label">Quick Links</span>
</div>
</div>
<div class="page-header">
<div class="page-title">
<h1>Dashboard</h1>
<p>Overview of your short links and recent activity.</p>
</div>
<div class="page-actions">
<a href="/" class="btn btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:18px;height:18px"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15"/></svg>
New Link
</a>
</div>
</div>
{{if .TopLinks}}
<article>
<header>
<h3>Quick Links</h3>
</header>
<div class="tile-grid">
{{range .TopLinks}}
<a href="/{{.Slug}}" class="tile" target="_blank" rel="noopener noreferrer" title="{{.URL}}">
<span class="tile-slug">/{{.Slug}}</span>
<span class="tile-dest">{{.URL}}</span>
<span class="tile-clicks">{{.Clicks}} clicks</span>
</a>
{{end}}
</div>
</article>
{{end}}
{{if .Success}}
<div class="alert alert-success">{{.Success}}</div>
{{end}}
{{if .Success}}
<article aria-label="success" class="alert-success">{{.Success}}</article>
{{end}}
<div class="stats-bar">
<div class="stats-card">
<span class="stats-value">{{len .AdminLinks}}</span>
<span class="stats-label">My Links</span>
</div>
<div class="stats-card">
<span class="stats-value">{{len .AnonLinks}}</span>
<span class="stats-label">Anonymous</span>
</div>
<div class="stats-card">
<span class="stats-value">{{len .TopLinks}}</span>
<span class="stats-label">Quick Links</span>
</div>
</div>
<article class="card-table">
<div class="section-header">
<hgroup>
<h2>My Links</h2>
<p>{{len .AdminLinks}} links</p>
</hgroup>
<a href="/" role="button" class="outline btn-sm">+ New Link</a>
</div>
<figure>
<table role="grid">
<thead>
<tr>
<th>Slug</th>
<th>Destination</th>
<th>Clicks</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{{range .AdminLinks}}
<tr>
<td><a href="/{{.Slug}}" target="_blank">/{{.Slug}}</a></td>
<td title="{{.URL}}">{{.URL}}</td>
<td>{{.Clicks}}</td>
<td>{{.CreatedAt.Format "2006-01-02 15:04"}}</td>
<td>
<div role="group">
<a href="/admin/edit/{{.ID}}" role="button" class="outline">Edit</a>
<button type="button" class="outline" onclick="showQR('/{{.Slug}}')">QR</button>
<form method="post" action="/admin/delete/{{.ID}}" onsubmit="return confirm('Delete /{{.Slug}}?')">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="outline secondary">Del</button>
</form>
</div>
</td>
</tr>
{{else}}
<tr>
<td colspan="5">
<div class="empty-state">
<span class="empty-icon">&#128279;</span>
<p>No links yet.</p>
<a href="/">Create your first link</a>
</div>
</td>
</tr>
{{end}}
</tbody>
</table>
</figure>
</article>
{{if .TopLinks}}
<section style="margin-bottom: 2rem;">
<div class="section-header">
<div>
<h2 class="section-title">Quick Links</h2>
<p class="section-subtitle">Top 20 most-clicked links — one click to open.</p>
</div>
</div>
<div class="tile-grid">
{{range .TopLinks}}
<a href="/{{.Slug}}" class="tile" target="_blank" rel="noopener noreferrer" title="{{.URL}}">
<span class="tile-slug">/{{.Slug}}</span>
<span class="tile-dest" data-hostname>{{.URL}}</span>
<span class="tile-clicks">{{.Clicks}} clicks</span>
</a>
{{end}}
</div>
</section>
{{end}}
<article class="card-table">
<div class="section-header">
<hgroup>
<h2>Anonymous Links</h2>
<p>{{len .AnonLinks}} links</p>
</hgroup>
</div>
<figure>
<table role="grid">
<thead>
<tr>
<th>Slug</th>
<th>Destination</th>
<th>Clicks</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{{range .AnonLinks}}
<tr>
<td><a href="/{{.Slug}}" target="_blank">/{{.Slug}}</a></td>
<td title="{{.URL}}">{{.URL}}</td>
<td>{{.Clicks}}</td>
<td>{{.CreatedAt.Format "2006-01-02 15:04"}}</td>
<td>
<div role="group">
<a href="/admin/edit/{{.ID}}" role="button" class="outline">Edit</a>
<button type="button" class="outline" onclick="showQR('/{{.Slug}}')">QR</button>
<form method="post" action="/admin/delete/{{.ID}}" onsubmit="return confirm('Delete /{{.Slug}}?')">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="outline secondary">Del</button>
</form>
</div>
</td>
</tr>
{{else}}
<tr>
<td colspan="5">
<div class="empty-state">
<span class="empty-icon">&#128101;</span>
<p>No anonymous links.</p>
</div>
</td>
</tr>
{{end}}
</tbody>
</table>
</figure>
</article>
<section style="margin-bottom: 2rem;">
<div class="section-header">
<div>
<h2 class="section-title">My Links</h2>
<p class="section-subtitle">{{len .AdminLinks}} links created by you.</p>
</div>
</div>
<div class="card card-flush">
<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<th>Slug</th>
<th>Destination</th>
<th class="col-numeric">Clicks</th>
<th>Created</th>
<th class="col-actions">Actions</th>
</tr>
</thead>
<tbody>
{{range .AdminLinks}}
<tr>
<td><a href="/{{.Slug}}" target="_blank" rel="noopener noreferrer">/{{.Slug}}</a></td>
<td title="{{.URL}}"><span class="text-truncate" style="display:inline-block;max-width:340px;vertical-align:middle">{{.URL}}</span></td>
<td class="col-numeric">{{.Clicks}}</td>
<td>{{.CreatedAt.Format "2006-01-02 15:04"}}</td>
<td class="col-actions">
<div class="flex gap-1">
<a href="/admin/edit/{{.ID}}" class="btn btn-secondary btn-sm">Edit</a>
<button type="button" class="btn btn-secondary btn-sm" onclick="openQRModal('{{.Slug}}', '{{.Slug}}')">QR</button>
<form method="post" action="/admin/delete/{{.ID}}" style="display:inline" onsubmit="return confirm('Delete /{{.Slug}}?')">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-danger btn-sm">Del</button>
</form>
</div>
</td>
</tr>
{{else}}
<tr><td colspan="5">
<div class="empty-state">
<span class="empty-state-icon">🔗</span>
<p class="empty-state-text">No links yet.</p>
<a href="/" class="btn btn-primary btn-sm empty-state-action">Create your first link</a>
</div>
</td></tr>
{{end}}
</tbody>
</table>
</div>
</div>
</section>
<section style="margin-bottom: 2rem;">
<div class="section-header">
<div>
<h2 class="section-title">Anonymous Links</h2>
<p class="section-subtitle">{{len .AnonLinks}} links created by unauthenticated users.</p>
</div>
</div>
<div class="card card-flush">
<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<th>Slug</th>
<th>Destination</th>
<th class="col-numeric">Clicks</th>
<th>Created</th>
<th class="col-actions">Actions</th>
</tr>
</thead>
<tbody>
{{range .AnonLinks}}
<tr>
<td><a href="/{{.Slug}}" target="_blank" rel="noopener noreferrer">/{{.Slug}}</a></td>
<td title="{{.URL}}"><span class="text-truncate" style="display:inline-block;max-width:340px;vertical-align:middle">{{.URL}}</span></td>
<td class="col-numeric">{{.Clicks}}</td>
<td>{{.CreatedAt.Format "2006-01-02 15:04"}}</td>
<td class="col-actions">
<div class="flex gap-1">
<a href="/admin/edit/{{.ID}}" class="btn btn-secondary btn-sm">Edit</a>
<button type="button" class="btn btn-secondary btn-sm" onclick="openQRModal('{{.Slug}}', '{{.Slug}}')">QR</button>
<form method="post" action="/admin/delete/{{.ID}}" style="display:inline" onsubmit="return confirm('Delete /{{.Slug}}?')">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-danger btn-sm">Del</button>
</form>
</div>
</td>
</tr>
{{else}}
<tr><td colspan="5">
<div class="empty-state">
<span class="empty-state-icon">👥</span>
<p class="empty-state-text">No anonymous links.</p>
</div>
</td></tr>
{{end}}
</tbody>
</table>
</div>
</div>
</section>
</main>
<dialog id="qr-dialog">
<article>
<header>
<button aria-label="Close" rel="prev" onclick="document.getElementById('qr-dialog').close()"></button>
<h3>QR Code</h3>
</header>
<div id="qr-container" style="text-align:center"></div>
</article>
</dialog>
<script>
document.querySelectorAll('.tile-dest').forEach(el => {
try { el.textContent = new URL(el.textContent.trim()).hostname; } catch(e) {}
});
function showQR(slug) {
var container = document.getElementById('qr-container');
container.innerHTML = '<p>Loading...</p>';
document.getElementById('qr-dialog').showModal();
fetch('/admin/qr' + slug)
.then(function(r) { return r.text(); })
.then(function(svg) {
container.innerHTML = svg +
'<p style="margin-top:0.5rem;word-break:break-all">' + location.origin + slug + '</p>';
});
}
// Compress URL displays to hostname for visual cleanliness
document.querySelectorAll('[data-hostname]').forEach(function(el) {
try {
var u = new URL(el.textContent.trim());
el.textContent = u.hostname + (u.pathname !== '/' ? u.pathname : '');
} catch (e) {}
});
</script>
</body>
</html>
{{end}}
+150 -171
View File
@@ -1,184 +1,163 @@
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pastes — Admin</title>
<link rel="stylesheet" href="/static/pico.min.css">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<nav>
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
<ul>
<li><a href="/">Home</a></li>
<li>
<form method="post" action="/admin/logout" style="margin:0">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="outline secondary btn-sm">Logout</button>
</form>
</li>
</ul>
</nav>
<div class="admin-tabs">
<a href="/admin" class="tab-link">Links</a>
<a href="/admin/bin" class="tab-link active">Pastes</a>
<a href="/admin/uploads" class="tab-link">Uploads</a>
</div>
<main class="container" style="max-width:1180px">
{{if .Error}}
<article aria-label="error" class="alert-error">{{.Error}}</article>
{{end}}
{{define "title"}}Pastes — Admin{{end}}
{{define "content"}}
<div class="section-header" style="padding-left:0;padding-right:0">
<hgroup>
<h2>Pastes</h2>
<p>{{len .Pastes}} pastes</p>
</hgroup>
<a href="/admin/bin/new" role="button" class="btn-sm">+ New Paste</a>
</div>
<div class="page-header">
<div class="page-title">
<h1>Pastes</h1>
<p>{{len .Pastes}} paste{{if ne (len .Pastes) 1}}s{{end}} — Markdown &amp; plain text, optionally token-protected.</p>
</div>
<div class="page-actions">
<a href="/admin/bin/new" class="btn btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:18px;height:18px"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15"/></svg>
New Paste
</a>
</div>
</div>
{{if .Pastes}}
<div class="pcard-grid">
{{range .Pastes}}
<article class="pcard js-preview" data-name="{{.Name}}" data-token="{{.Token}}" data-title="{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}}" role="button" tabindex="0">
{{if .ThumbURL}}
<div class="pcard-imgwrap">
<img class="pcard-img" src="{{.ThumbURL}}" alt="" loading="lazy">
</div>
{{end}}
<div class="pcard-body">
<h3 class="pcard-title">{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}}</h3>
{{if .Summary}}<p class="pcard-summary">{{.Summary}}</p>{{end}}
<div class="pcard-meta">
<mark class="badge-format">{{.Format}}</mark>
{{if .Token}}<mark class="badge-token">&#128274;</mark>{{else}}<mark class="badge-public">public</mark>{{end}}
{{if .Hidden}}<mark class="badge-hidden">hidden</mark>{{end}}
<span class="pcard-date">{{.UpdatedAt.Format "01-02 15:04"}}</span>
</div>
<div class="pcard-actions" role="group">
<button type="button" class="outline" onclick="copyPasteLink('{{.Name}}','{{.Token}}', this)">Copy link</button>
<a href="/admin/bin/edit/{{.ID}}" role="button" class="outline">Edit</a>
<button type="button" class="outline" onclick="showBinQR('{{.Name}}', false)">QR</button>
<form method="post" action="/admin/bin/delete/{{.ID}}" onsubmit="return confirm('Delete paste {{.Name}}?')">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="outline secondary">Del</button>
</form>
</div>
</div>
</article>
{{end}}
</div>
{{else}}
<div class="empty-state">
<span class="empty-icon">&#128196;</span>
<p>No pastes yet.</p>
<a href="/admin/bin/new">Create your first paste</a>
</div>
{{end}}
</main>
{{if .Error}}
<div class="alert alert-error">{{.Error}}</div>
{{end}}
<dialog id="preview-dialog" class="preview-dialog">
<div class="preview-head">
<span class="preview-title" id="preview-title">Preview</span>
<div class="preview-actions">
<a id="preview-open" href="#" target="_blank" rel="noopener" role="button" class="outline btn-sm">Open &#8599;</a>
<button type="button" class="outline btn-sm" id="preview-expand" onclick="toggleExpand()" aria-label="Expand">&#8690;</button>
<button type="button" class="btn-sm preview-close" onclick="closePreview()" aria-label="Close">&#10005;</button>
</div>
</div>
<iframe id="preview-frame" class="preview-frame" src="about:blank" title="Paste preview"></iframe>
</dialog>
<dialog id="qr-dialog">
<article>
<header>
<button aria-label="Close" rel="prev" onclick="document.getElementById('qr-dialog').close()"></button>
<h3 id="qr-title">QR Code</h3>
</header>
<div id="qr-container" style="text-align:center"></div>
</article>
{{if .Pastes}}
<div class="paste-grid">
{{range .Pastes}}
<article class="paste-card js-preview" data-name="{{.Name}}" data-token="{{.Token}}" data-title="{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}}">
{{if .ThumbURL}}
<div class="paste-card-thumb">
<img src="{{.ThumbURL}}" alt="" loading="lazy">
</div>
{{else}}
<div class="paste-card-thumb">
<span class="paste-card-thumb-empty">{{.Format}}</span>
</div>
{{end}}
<div class="paste-card-body">
<h3 class="paste-card-title">{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}}</h3>
{{if .Summary}}<p class="paste-card-summary">{{.Summary}}</p>{{end}}
<div class="paste-card-meta">
<span class="tag-pill badge-format">{{.Format}}</span>
{{if .Token}}
<span class="tag-pill badge-token">🔒</span>
{{else}}
<span class="tag-pill badge-public">public</span>
{{end}}
{{if .Hidden}}<span class="tag-pill badge-hidden">hidden</span>{{end}}
<span class="paste-card-date">{{.UpdatedAt.Format "01-02 15:04"}}</span>
</div>
</div>
<div class="paste-card-actions">
<button type="button" class="btn btn-secondary btn-sm" onclick="event.stopPropagation();copyPasteLink('{{.Name}}','{{.Token}}', this)">Copy link</button>
<a href="/admin/bin/edit/{{.ID}}" class="btn btn-secondary btn-sm" onclick="event.stopPropagation()">Edit</a>
<button type="button" class="btn btn-secondary btn-sm" onclick="event.stopPropagation();showBinQR('{{.Name}}', false)">QR</button>
<form method="post" action="/admin/bin/delete/{{.ID}}" style="display:inline" onsubmit="return confirm('Delete paste {{.Name}}?')">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-danger btn-sm">Del</button>
</form>
</div>
</article>
{{end}}
</div>
{{else}}
<div class="card">
<div class="empty-state">
<span class="empty-state-icon">📄</span>
<p class="empty-state-text">No pastes yet.</p>
<a href="/admin/bin/new" class="btn btn-primary empty-state-action">Create your first paste</a>
</div>
</div>
{{end}}
<!-- Paste preview dialog -->
<dialog id="preview-dialog" class="preview-dialog">
<div class="preview-head">
<span class="preview-title" id="preview-title">Preview</span>
<div class="preview-actions">
<a id="preview-open" href="#" target="_blank" rel="noopener" class="btn btn-secondary btn-sm">Open ↗</a>
<button type="button" class="btn btn-secondary btn-sm" id="preview-expand" onclick="toggleExpand()" aria-label="Expand">⤢</button>
<button type="button" class="btn btn-secondary btn-sm" onclick="closePreview()" aria-label="Close">✕</button>
</div>
</div>
<iframe id="preview-frame" class="preview-frame" src="about:blank" title="Paste preview"></iframe>
</dialog>
<script>
function previewURL(name, token) {
var u = '/bin/' + encodeURIComponent(name);
if (token) u += '/' + encodeURIComponent(token);
return u;
}
function previewURL(name, token) {
var u = '/bin/' + encodeURIComponent(name);
if (token) u += '/' + encodeURIComponent(token);
return u;
}
function openPreview(name, token, title) {
var dlg = document.getElementById('preview-dialog');
var url = previewURL(name, token);
document.getElementById('preview-frame').src = url;
document.getElementById('preview-open').href = url;
document.getElementById('preview-title').textContent = title || name;
dlg.classList.remove('expanded');
document.getElementById('preview-expand').innerHTML = '&#8690;';
document.getElementById('preview-expand').setAttribute('aria-label', 'Expand');
dlg.showModal();
}
function openPreview(name, token, title) {
var dlg = document.getElementById('preview-dialog');
var fullURL = previewURL(name, token);
// iframe uses the embed view so it strips the sidebar / header / toolbar —
// only the paste body is rendered inside the dialog.
var embedURL = fullURL + '?embed=1';
document.getElementById('preview-frame').src = embedURL;
// The "Open ↗" link goes to the full URL (with chrome) so a new tab shows the
// normal public page.
document.getElementById('preview-open').href = fullURL;
document.getElementById('preview-title').textContent = title || name;
dlg.classList.remove('expanded');
document.getElementById('preview-expand').innerHTML = '⤢';
document.getElementById('preview-expand').setAttribute('aria-label', 'Expand');
dlg.showModal();
}
function closePreview() {
document.getElementById('preview-dialog').close();
}
function closePreview() {
document.getElementById('preview-dialog').close();
}
function toggleExpand() {
var dlg = document.getElementById('preview-dialog');
var expanded = dlg.classList.toggle('expanded');
var btn = document.getElementById('preview-expand');
btn.innerHTML = expanded ? '&#8689;' : '&#8690;';
btn.setAttribute('aria-label', expanded ? 'Shrink' : 'Expand');
}
function toggleExpand() {
var dlg = document.getElementById('preview-dialog');
var expanded = dlg.classList.toggle('expanded');
var btn = document.getElementById('preview-expand');
btn.innerHTML = expanded ? '⤡' : '⤢';
btn.setAttribute('aria-label', expanded ? 'Shrink' : 'Expand');
}
function copyPasteLink(name, token, btn) {
var url = location.origin + previewURL(name, token);
navigator.clipboard.writeText(url).then(function() {
var orig = btn.textContent;
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = orig; }, 1500);
});
}
function copyPasteLink(name, token, btn) {
var url = location.origin + previewURL(name, token);
var orig = btn.textContent;
navigator.clipboard.writeText(url).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = orig; }, 1500);
});
}
// Clicking anywhere on a card opens the preview, except on the action
// buttons. Data attributes avoid quoting issues with paste titles.
document.querySelectorAll('.js-preview').forEach(function(el) {
el.addEventListener('click', function(e) {
if (e.target.closest('.pcard-actions')) return;
openPreview(el.dataset.name, el.dataset.token, el.dataset.title);
});
el.addEventListener('keydown', function(e) {
if ((e.key === 'Enter' || e.key === ' ') && !e.target.closest('.pcard-actions')) {
e.preventDefault();
openPreview(el.dataset.name, el.dataset.token, el.dataset.title);
}
});
});
function showBinQR(name, full) {
var url = location.origin + '/bin/' + encodeURIComponent(name);
var fetchUrl = '/admin/bin/qr/' + encodeURIComponent(name);
if (full) fetchUrl += '?full=1';
var overlay = document.getElementById('qr-modal-overlay');
document.getElementById('qr-modal-image').src = fetchUrl;
document.getElementById('qr-modal-link').textContent = url + (full ? ' (with token)' : '');
var dl = document.getElementById('qr-modal-download');
dl.href = fetchUrl;
dl.download = name + '_QR.svg';
overlay.classList.add('show');
}
// Clear the iframe when the dialog is dismissed via Esc / backdrop / button.
document.getElementById('preview-dialog').addEventListener('close', function() {
document.getElementById('preview-frame').src = 'about:blank';
});
// Click on paste card opens preview, except when clicking action buttons
document.querySelectorAll('.js-preview').forEach(function(el) {
el.addEventListener('click', function(e) {
if (e.target.closest('.paste-card-actions')) return;
if (e.target.closest('a, button, form, input')) return;
openPreview(el.dataset.name, el.dataset.token, el.dataset.title);
});
el.setAttribute('tabindex', '0');
el.setAttribute('role', 'button');
el.addEventListener('keydown', function(e) {
if ((e.key === 'Enter' || e.key === ' ') && !e.target.closest('.paste-card-actions')) {
e.preventDefault();
openPreview(el.dataset.name, el.dataset.token, el.dataset.title);
}
});
});
function showBinQR(name, full) {
var container = document.getElementById('qr-container');
var title = document.getElementById('qr-title');
container.innerHTML = '<p>Loading...</p>';
title.textContent = full ? 'Full QR Code (with token)' : 'QR Code';
document.getElementById('qr-dialog').showModal();
var url = '/admin/bin/qr/' + encodeURIComponent(name);
if (full) url += '?full=1';
fetch(url)
.then(function(r) { return r.text(); })
.then(function(svg) {
var fullLink = location.origin + '/bin/' + name;
var note = '';
if (full) {
note = '<small style="color:var(--pico-muted-color)">(includes access token)</small>';
}
container.innerHTML = svg +
'<p style="margin-top:0.5rem;word-break:break-all">' + fullLink + '</p>' + note;
});
}
// Clear iframe when dialog closes
document.getElementById('preview-dialog').addEventListener('close', function() {
document.getElementById('preview-frame').src = 'about:blank';
});
</script>
</body>
</html>
{{end}}
+179 -178
View File
@@ -1,193 +1,194 @@
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{if .Paste}}Edit Paste{{else}}New Paste{{end}} — Admin</title>
<link rel="stylesheet" href="/static/pico.min.css">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<nav>
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
<ul>
<li><a href="/">Home</a></li>
<li>
<form method="post" action="/admin/logout" style="margin:0">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="outline secondary btn-sm">Logout</button>
</form>
</li>
</ul>
</nav>
<div class="admin-tabs">
<a href="/admin" class="tab-link">Links</a>
<a href="/admin/bin" class="tab-link active">Pastes</a>
<a href="/admin/uploads" class="tab-link">Uploads</a>
</div>
<main class="container" style="max-width:860px">
<article>
<header>
<h2>{{if .Paste}}Edit Paste{{else}}New Paste{{end}}</h2>
</header>
{{define "title"}}{{if .Paste}}Edit Paste{{else}}New Paste{{end}} — Admin{{end}}
{{define "content"}}
{{if .Error}}
<article aria-label="error" class="alert-error">{{.Error}}</article>
{{end}}
<div class="page-header">
<div class="page-title">
<h1>{{if .Paste}}Edit Paste{{else}}New Paste{{end}}</h1>
<p>{{if .Paste}}Update the content and access settings.{{else}}Write a new paste — Markdown or plain text, optionally token-protected.{{end}}</p>
</div>
<div class="page-actions">
<a href="/admin/bin" class="btn btn-secondary">Back to pastes</a>
</div>
</div>
{{if .Paste}}
{{with .Paste}}
<form method="post" action="/admin/bin/edit/{{.ID}}">
{{else}}{{end}}
{{else}}
<form method="post" action="/admin/bin/new">
{{end}}
{{if .Error}}
<div class="alert alert-error">{{.Error}}</div>
{{end}}
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<div style="display:grid;grid-template-columns:1fr 2fr;gap:1rem;">
<label>
Name <small>(URL slug)</small>
{{if .Paste}}
{{with .Paste}}<input type="text" name="name" value="{{.Name}}" required pattern="[a-zA-Z0-9_-]+" title="Letters, numbers, hyphens, underscores">{{end}}
{{else}}
<input type="text" name="name" required pattern="[a-zA-Z0-9_-]+" placeholder="my-script" title="Letters, numbers, hyphens, underscores">
{{end}}
</label>
<label>
Title <small>(optional)</small>
{{if .Paste}}
{{with .Paste}}<input type="text" name="title" value="{{.Title}}" placeholder="A short description">{{end}}
{{else}}
<input type="text" name="title" placeholder="A short description">
{{end}}
</label>
</div>
<div class="card">
{{if .Paste}}
{{with .Paste}}<form method="post" action="/admin/bin/edit/{{.ID}}">{{else}}{{end}}
{{else}}
<form method="post" action="/admin/bin/new">
{{end}}
<label>Format
<select name="format">
{{if .Paste}}
{{with .Paste}}
<option value="markdown"{{if eq .Format "markdown"}} selected{{end}}>Markdown</option>
<option value="text"{{if eq .Format "text"}} selected{{end}}>Plain text</option>
{{end}}
{{else}}
<option value="markdown" selected>Markdown</option>
<option value="text">Plain text</option>
{{end}}
</select>
</label>
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<label>Content</label>
<div class="upload-controls">
<button type="button" id="upload-img-btn" class="outline secondary" title="PNG, JPEG, GIF, WebP — up to 50 MB">Upload Image <small style="opacity:.7">(50 MB)</small></button>
<button type="button" id="upload-file-btn" class="outline secondary" title="Any file type — up to 5 MB">Upload File <small style="opacity:.7">(5 MB)</small></button>
<input type="file" id="img-input" accept="image/png,image/jpeg,image/gif,image/webp" style="display:none">
<input type="file" id="file-input" style="display:none">
<small id="upload-status"></small>
</div>
{{if .Paste}}
{{with .Paste}}<textarea name="content" rows="20" style="font-family:monospace;font-size:0.9rem">{{.Content}}</textarea>{{end}}
{{else}}
<textarea name="content" rows="20" style="font-family:monospace;font-size:0.9rem" placeholder="# Hello&#10;&#10;Write your markdown here..."></textarea>
{{end}}
<div class="form-row">
<div class="form-group">
<label for="name" class="form-label">Name <small class="text-muted">(URL slug)</small></label>
{{if .Paste}}
{{with .Paste}}<input type="text" id="name" name="name" value="{{.Name}}" required pattern="[a-zA-Z0-9_-]+" title="Letters, numbers, hyphens, underscores">{{end}}
{{else}}
<input type="text" id="name" name="name" required pattern="[a-zA-Z0-9_-]+" placeholder="my-script" title="Letters, numbers, hyphens, underscores">
{{end}}
<small class="form-help">Path: <code>/bin/<span id="name-preview">{{if .Paste}}{{with .Paste}}{{.Name}}{{end}}{{else}}...{{end}}</span></code></small>
</div>
<fieldset>
<legend>Access Token</legend>
{{if .Paste}}
{{with .Paste}}
{{if .Token}}
<p>Current token: <code>{{.Token}}</code> &mdash; URL: <code>/bin/{{.Name}}/{{.Token}}</code></p>
<label><input type="radio" name="token_action" value="keep" checked onchange="toggleCustomToken()"> Keep current token</label>
<label><input type="radio" name="token_action" value="regenerate" onchange="toggleCustomToken()"> Regenerate token</label>
<label><input type="radio" name="token_action" value="custom" onchange="toggleCustomToken()"> Set custom token</label>
<label><input type="radio" name="token_action" value="disable" onchange="toggleCustomToken()"> Disable token (public access)</label>
{{else}}
<p>Token is currently <strong>disabled</strong> — paste is publicly accessible.</p>
<label><input type="radio" name="token_action" value="keep" checked onchange="toggleCustomToken()"> Keep disabled</label>
<label><input type="radio" name="token_action" value="regenerate" onchange="toggleCustomToken()"> Enable with new token</label>
<label><input type="radio" name="token_action" value="custom" onchange="toggleCustomToken()"> Set custom token</label>
{{end}}
<div id="custom-token-wrap" style="display:none;margin-left:2rem">
<input type="text" name="custom_token" placeholder="Enter custom token" pattern="[a-zA-Z0-9_-]+" maxlength="64">
</div>
<label style="margin-top:0.5rem">
<input type="checkbox" name="hidden" value="1" {{if .Hidden}}checked{{end}}>
Hide paste (return 404 if accessed without token)
</label>
{{end}}
{{else}}
<label><input type="radio" name="enable_token" value="0" checked onchange="toggleCustomToken()"> No token (public access)</label>
<label><input type="radio" name="enable_token" value="1" onchange="toggleCustomToken()"> Generate access token</label>
<label><input type="radio" name="enable_token" value="custom" onchange="toggleCustomToken()"> Custom token</label>
<div id="custom-token-wrap" style="display:none;margin-left:2rem">
<input type="text" name="custom_token" placeholder="Enter custom token" pattern="[a-zA-Z0-9_-]+" maxlength="64">
</div>
<label style="margin-top:0.5rem">
<input type="checkbox" name="hidden" value="1">
Hide paste (return 404 if accessed without token)
</label>
{{end}}
</fieldset>
<div class="form-group">
<label for="title" class="form-label">Title <small class="text-muted">(optional)</small></label>
{{if .Paste}}
{{with .Paste}}<input type="text" id="title" name="title" value="{{.Title}}" placeholder="A short description">{{end}}
{{else}}
<input type="text" id="title" name="title" placeholder="A short description">
{{end}}
</div>
</div>
<div role="group" style="margin-top:1rem">
<button type="submit">Save</button>
<a href="/admin/bin" role="button" class="outline secondary">Cancel</a>
</div>
<div class="form-group">
<label for="format" class="form-label">Format</label>
<select id="format" name="format">
{{if .Paste}}
{{with .Paste}}
<option value="markdown"{{if eq .Format "markdown"}} selected{{end}}>Markdown</option>
<option value="text"{{if eq .Format "text"}} selected{{end}}>Plain text</option>
{{end}}
{{else}}
<option value="markdown" selected>Markdown</option>
<option value="text">Plain text</option>
{{end}}
</select>
</div>
<div class="form-group">
<label for="content" class="form-label">Content</label>
<div class="upload-controls" style="margin-bottom: 0.5rem;">
<button type="button" id="upload-img-btn" class="btn btn-secondary btn-sm" title="PNG, JPEG, GIF, WebP — up to 50 MB">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 001.5-1.5V6a1.5 1.5 0 00-1.5-1.5H3.75A1.5 1.5 0 002.25 6v12a1.5 1.5 0 001.5 1.5zm10.5-11.25h.008v.008h-.008V8.25zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z"/></svg>
Upload Image
</button>
<button type="button" id="upload-file-btn" class="btn btn-secondary btn-sm" title="Any file type — up to 5 MB">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13"/></svg>
Upload File
</button>
<input type="file" id="img-input" accept="image/png,image/jpeg,image/gif,image/webp" style="display:none">
<input type="file" id="file-input" style="display:none">
<small id="upload-status" class="upload-status"></small>
</div>
{{if .Paste}}
{{with .Paste}}<textarea id="content" name="content" rows="20">{{.Content}}</textarea>{{end}}
{{else}}
<textarea id="content" name="content" rows="20" placeholder="# Hello&#10;&#10;Write your markdown here..."></textarea>
{{end}}
</div>
<fieldset>
<legend>Access Token</legend>
{{if .Paste}}
{{with .Paste}}
{{if .Token}}
<p class="text-muted" style="margin-bottom: 0.75rem;">
Current token: <code>{{.Token}}</code> — URL: <code>/bin/{{.Name}}/{{.Token}}</code>
</p>
<label><input type="radio" name="token_action" value="keep" checked onchange="toggleCustomToken()"> Keep current token</label>
<label><input type="radio" name="token_action" value="regenerate" onchange="toggleCustomToken()"> Regenerate token</label>
<label><input type="radio" name="token_action" value="custom" onchange="toggleCustomToken()"> Set custom token</label>
<label><input type="radio" name="token_action" value="disable" onchange="toggleCustomToken()"> Disable token (public access)</label>
{{else}}
<p class="text-muted" style="margin-bottom: 0.75rem;">Token is currently <strong>disabled</strong> — paste is publicly accessible.</p>
<label><input type="radio" name="token_action" value="keep" checked onchange="toggleCustomToken()"> Keep disabled</label>
<label><input type="radio" name="token_action" value="regenerate" onchange="toggleCustomToken()"> Enable with new token</label>
<label><input type="radio" name="token_action" value="custom" onchange="toggleCustomToken()"> Set custom token</label>
{{end}}
<div id="custom-token-wrap" style="display:none; margin: 0.5rem 0 0.5rem 1.5rem;">
<input type="text" name="custom_token" placeholder="Enter custom token" pattern="[a-zA-Z0-9_-]+" maxlength="64">
</div>
<label style="margin-top: 0.5rem;">
<input type="checkbox" name="hidden" value="1" {{if .Hidden}}checked{{end}}>
Hide paste (return 404 if accessed without token)
</label>
{{end}}
{{else}}
<label><input type="radio" name="enable_token" value="0" checked onchange="toggleCustomToken()"> No token (public access)</label>
<label><input type="radio" name="enable_token" value="1" onchange="toggleCustomToken()"> Generate access token</label>
<label><input type="radio" name="enable_token" value="custom" onchange="toggleCustomToken()"> Custom token</label>
<div id="custom-token-wrap" style="display:none; margin: 0.5rem 0 0.5rem 1.5rem;">
<input type="text" name="custom_token" placeholder="Enter custom token" pattern="[a-zA-Z0-9_-]+" maxlength="64">
</div>
<label style="margin-top: 0.5rem;">
<input type="checkbox" name="hidden" value="1">
Hide paste (return 404 if accessed without token)
</label>
{{end}}
</fieldset>
<div class="flex gap-1" style="margin-top: 1.5rem;">
<button type="submit" class="btn btn-primary btn-lg">Save paste</button>
<a href="/admin/bin" class="btn btn-secondary btn-lg">Cancel</a>
</div>
</form>
{{if .Paste}}{{with .Paste}}{{end}}{{end}}
</div>
</form>
{{if .Paste}}{{with .Paste}}{{end}}{{end}}
</article>
</main>
<script src="/static/upload.js"></script>
<script>
function toggleCustomToken() {
var wrap = document.getElementById('custom-token-wrap');
if (!wrap) return;
var checked = document.querySelector('input[name="token_action"][value="custom"]:checked') ||
document.querySelector('input[name="enable_token"][value="custom"]:checked');
wrap.style.display = checked ? 'block' : 'none';
}
function toggleCustomToken() {
var wrap = document.getElementById('custom-token-wrap');
if (!wrap) return;
var checked = document.querySelector('input[name="token_action"][value="custom"]:checked') ||
document.querySelector('input[name="enable_token"][value="custom"]:checked');
wrap.style.display = checked ? 'block' : 'none';
}
(function() {
var textarea = document.querySelector('textarea[name="content"]');
var status = document.getElementById('upload-status');
// Slug preview updater
(function() {
var nameInput = document.getElementById('name');
var preview = document.getElementById('name-preview');
if (nameInput && preview) {
nameInput.addEventListener('input', function() {
preview.textContent = this.value || '...';
});
}
})();
function insertAtCursor(text) {
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var before = textarea.value.substring(0, start);
var after = textarea.value.substring(end);
textarea.value = before + text + '\n' + after;
textarea.selectionStart = textarea.selectionEnd = start + text.length + 1;
textarea.focus();
}
(function() {
var textarea = document.querySelector('textarea[name="content"]');
var status = document.getElementById('upload-status');
var uploader = window.GlimmerUpload.init({
imgBtn: document.getElementById('upload-img-btn'),
fileBtn: document.getElementById('upload-file-btn'),
imgInput: document.getElementById('img-input'),
fileInput: document.getElementById('file-input'),
statusEl: status,
maxImageMB: {{.UploadMaxMB}},
onUploaded: function(data) {
insertAtCursor(data.markdown);
status.textContent = 'Uploaded';
setTimeout(function() { status.textContent = ''; }, 3000);
}
});
function insertAtCursor(text) {
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var before = textarea.value.substring(0, start);
var after = textarea.value.substring(end);
textarea.value = before + text + '\n' + after;
textarea.selectionStart = textarea.selectionEnd = start + text.length + 1;
textarea.focus();
}
textarea.addEventListener('paste', function(e) {
var items = (e.clipboardData || {}).items || [];
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf('image') !== -1) {
e.preventDefault();
uploader.doUpload(items[i].getAsFile(), true);
return;
}
}
});
})();
var uploader = window.GlimmerUpload.init({
imgBtn: document.getElementById('upload-img-btn'),
fileBtn: document.getElementById('upload-file-btn'),
imgInput: document.getElementById('img-input'),
fileInput: document.getElementById('file-input'),
statusEl: status,
maxImageMB: {{.UploadMaxMB}},
onUploaded: function(data) {
insertAtCursor(data.markdown);
status.textContent = 'Uploaded';
setTimeout(function() { status.textContent = ''; }, 3000);
}
});
textarea.addEventListener('paste', function(e) {
var items = (e.clipboardData || {}).items || [];
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf('image') !== -1) {
e.preventDefault();
uploader.doUpload(items[i].getAsFile(), true);
return;
}
}
});
})();
</script>
</body>
</html>
{{end}}
+47 -48
View File
@@ -1,52 +1,51 @@
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Edit Link — Glimmer</title>
<link rel="stylesheet" href="/static/pico.min.css">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<nav>
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
<ul>
<li><a href="/admin">Back to list</a></li>
<li>
<form method="post" action="/admin/logout" style="margin:0">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="outline secondary btn-sm">Logout</button>
</form>
</li>
</ul>
</nav>
<main class="container">
<article>
<header>
<h2>Edit Link</h2>
</header>
{{define "title"}}Edit Link — Glimmer{{end}}
{{define "content"}}
{{if .Error}}
<article aria-label="error" class="alert-error">{{.Error}}</article>
{{end}}
<div class="page-header">
<div class="page-title">
<h1>Edit Link</h1>
<p>Update the slug or destination URL.</p>
</div>
<div class="page-actions">
<a href="/admin" class="btn btn-secondary">Back to list</a>
</div>
</div>
{{with .Link}}
<form method="post" action="/admin/edit/{{.ID}}">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<label for="slug">Slug</label>
<input type="text" id="slug" name="slug" value="{{.Slug}}" required pattern="[a-zA-Z0-9_-]+" title="Letters, numbers, hyphens, underscores only">
{{if .Error}}
<div class="alert alert-error">{{.Error}}</div>
{{end}}
<label for="url">Destination URL</label>
<input type="url" id="url" name="url" value="{{.URL}}" required>
{{with .Link}}
<div class="card" style="max-width: 640px;">
<form method="post" action="/admin/edit/{{.ID}}">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<div role="group">
<button type="submit">Save</button>
<a href="/admin" role="button" class="outline secondary">Cancel</a>
</div>
</form>
{{end}}
</article>
</main>
</body>
</html>
<div class="form-group">
<label for="slug" class="form-label">Slug</label>
<input type="text" id="slug" name="slug" value="{{.Slug}}" required pattern="[a-zA-Z0-9_-]+" title="Letters, numbers, hyphens, underscores only">
<small class="form-help">The short path users will visit: <code>/<span id="slug-preview">{{.Slug}}</span></code></small>
</div>
<div class="form-group">
<label for="url" class="form-label">Destination URL</label>
<input type="url" id="url" name="url" value="{{.URL}}" required>
</div>
<hr class="divider">
<div class="flex gap-1">
<button type="submit" class="btn btn-primary">Save changes</button>
<a href="/admin" class="btn btn-secondary">Cancel</a>
</div>
</form>
</div>
<script>
document.getElementById('slug').addEventListener('input', function() {
document.getElementById('slug-preview').textContent = this.value || '...';
});
</script>
{{else}}
<div class="alert alert-error">Link not found.</div>
{{end}}
{{end}}
+33 -34
View File
@@ -1,44 +1,43 @@
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="csrf-token" content="{{.CSRFToken}}">
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Admin Login — Glimmer</title>
<link rel="stylesheet" href="/static/pico.min.css">
<link rel="stylesheet" href="/static/style.css">
<title>Admin Login — Glimmer</title>
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
<nav>
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
<ul><li><a href="/">Home</a></li></ul>
</nav>
<main>
<div class="login-wrap">
<article class="login-card">
<header>
<hgroup>
<h2>Admin Login</h2>
<p>Sign in to manage your links</p>
</hgroup>
</header>
<body class="login-container">
<div class="login-card">
<div class="login-header">
<div class="brand">
<div class="brand-logo">G</div>
<span class="brand-name">Glimmer</span>
</div>
<h2>Admin Login</h2>
<p>Sign in to manage your links</p>
</div>
{{if .Error}}
<article aria-label="error" class="alert-error">{{.Error}}</article>
{{end}}
{{if .Error}}
<div class="alert alert-error">{{.Error}}</div>
{{end}}
<form method="post" action="/admin/login">
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
<label for="username">Username</label>
<input type="text" id="username" name="username" required autofocus>
<form action="/admin/login" method="POST">
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
<div class="form-group">
<label for="username" class="form-label">Username</label>
<input type="text" id="username" name="username" placeholder="admin" required autofocus>
</div>
<button type="submit">Log in</button>
</form>
</article>
</div>
</main>
<div class="form-group" style="margin-bottom: 1.75rem;">
<label for="password" class="form-label">Password</label>
<input type="password" id="password" name="password" placeholder="••••••••" required>
</div>
<button type="submit" class="btn btn-primary btn-lg btn-block">Log in</button>
</form>
</div>
</body>
</html>
+167 -179
View File
@@ -1,191 +1,179 @@
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Uploads — Admin</title>
<link rel="stylesheet" href="/static/pico.min.css">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<nav>
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
<ul>
<li><a href="/">Home</a></li>
<li>
<form method="post" action="/admin/logout" style="margin:0">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="outline secondary btn-sm">Logout</button>
</form>
</li>
</ul>
</nav>
<div class="admin-tabs">
<a href="/admin" class="tab-link">Links</a>
<a href="/admin/bin" class="tab-link">Pastes</a>
<a href="/admin/uploads" class="tab-link active">Uploads</a>
</div>
<main class="container" style="max-width:960px">
{{if .Error}}
<article aria-label="error" class="alert-error">{{.Error}}</article>
{{end}}
{{define "title"}}Uploads — Admin{{end}}
{{define "content"}}
<article class="card-table">
<div class="section-header">
<hgroup>
<h2>Uploads</h2>
<p>{{len .Uploads}} files</p>
</hgroup>
<div class="upload-controls">
<button type="button" id="upload-img-btn" class="btn-sm" title="PNG, JPEG, GIF, WebP — up to 50 MB">Upload Image <small style="opacity:.7">(50 MB)</small></button>
<button type="button" id="upload-file-btn" class="btn-sm outline" title="Any file type — up to 5 MB">Upload File <small style="opacity:.7">(5 MB)</small></button>
<input type="file" id="img-input" accept="image/png,image/jpeg,image/gif,image/webp" style="display:none">
<input type="file" id="file-input" style="display:none">
<small id="upload-status"></small>
</div>
</div>
<figure>
<table role="grid">
<thead>
<tr>
<th>Preview</th>
<th>File</th>
<th>Size</th>
<th>Dimensions</th>
<th>Uploaded</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{{range .Uploads}}
<tr>
<td>
{{if .IsImage}}<a href="{{.URL}}" target="_blank"><img src="{{.URL}}" style="max-width:72px;max-height:52px;object-fit:contain;border-radius:4px"></a>
{{else}}<a href="{{.URL}}" target="_blank" style="font-size:1.5rem" title="Download file">&#128196;</a>
{{end}}
</td>
<td>
<div style="display:flex;align-items:center;gap:.4rem;flex-wrap:wrap">
<span class="ext-chip">{{.Ext}}</span>
{{if .OriginalName}}<span style="font-size:0.85rem">{{.OriginalName}}</span>{{end}}
</div>
<code style="font-size:0.7rem;opacity:.6">{{.Filename}}</code>
</td>
<td id="size-{{.Filename}}">{{.SizeHuman}}</td>
<td id="dim-{{.Filename}}">{{if .Width}}{{.Width}}&times;{{.Height}}{{else}}&mdash;{{end}}</td>
<td>{{.ModTime.Format "2006-01-02 15:04"}}</td>
<td>
<div role="group">
<button type="button" class="outline btn-sm" onclick="copyMarkdown('{{.Filename}}', {{.IsImage}}, {{.OriginalName}}, this)">Copy</button>
{{if .CanResize}}<button type="button" class="outline btn-sm" onclick="openResize('{{.Filename}}', {{.Width}}, {{.Height}})">Resize</button>{{end}}
<form method="post" action="/admin/uploads/delete/{{.Filename}}" onsubmit="return confirm('Delete this file?')" style="margin:0">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="outline secondary btn-sm">Del</button>
</form>
</div>
</td>
</tr>
{{else}}
<tr>
<td colspan="6">
<div class="empty-state">
<span class="empty-icon">&#128196;</span>
<p>No uploads yet. Use the buttons above to upload an image or file.</p>
</div>
</td>
</tr>
{{end}}
</tbody>
</table>
</figure>
</article>
</main>
<div class="page-header">
<div class="page-title">
<h1>Uploads</h1>
<p>Manage your uploaded images and files. Use them in pastes via the markdown link.</p>
</div>
<div class="page-actions">
<a href="/admin/bin" class="btn btn-secondary">Back to pastes</a>
</div>
</div>
<dialog id="resize-dialog">
<article>
<header>
<button aria-label="Close" rel="prev" onclick="document.getElementById('resize-dialog').close()"></button>
<h3>Resize Image</h3>
</header>
<p id="resize-current" style="color:var(--pico-muted-color)"></p>
<label>
Max dimension (px)
<input type="number" id="resize-dim" value="1200" min="64" max="8192" step="1">
</label>
<small id="resize-status" style="color:var(--pico-muted-color)"></small>
<footer>
<button type="button" class="secondary outline" onclick="document.getElementById('resize-dialog').close()">Cancel</button>
<button type="button" id="resize-confirm">Resize</button>
</footer>
</article>
</dialog>
{{if .Error}}
<div class="alert alert-error">{{.Error}}</div>
{{end}}
<div class="card card-flush">
<div class="card-header">
<div>
<h2 class="card-title">All uploads</h2>
<p class="card-subtitle">{{len .Uploads}} file{{if ne (len .Uploads) 1}}s{{end}} stored locally.</p>
</div>
<div class="upload-controls">
<button type="button" id="upload-img-btn" class="btn btn-primary btn-sm" title="PNG, JPEG, GIF, WebP — up to 50 MB">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 001.5-1.5V6a1.5 1.5 0 00-1.5-1.5H3.75A1.5 1.5 0 002.25 6v12a1.5 1.5 0 001.5 1.5zm10.5-11.25h.008v.008h-.008V8.25zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z"/></svg>
Upload Image <small style="opacity:.6">(50 MB)</small>
</button>
<button type="button" id="upload-file-btn" class="btn btn-secondary btn-sm" title="Any file type — up to 5 MB">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13"/></svg>
Upload File <small style="opacity:.6">(5 MB)</small>
</button>
<input type="file" id="img-input" accept="image/png,image/jpeg,image/gif,image/webp" style="display:none">
<input type="file" id="file-input" style="display:none">
<small id="upload-status" class="upload-status"></small>
</div>
</div>
<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<th style="width: 90px;">Preview</th>
<th>File</th>
<th>Size</th>
<th>Dimensions</th>
<th>Uploaded</th>
<th class="col-actions">Actions</th>
</tr>
</thead>
<tbody>
{{range .Uploads}}
<tr>
<td>
{{if .IsImage}}
<a href="{{.URL}}" target="_blank" rel="noopener noreferrer">
<img src="{{.URL}}" style="max-width:72px; max-height:52px; object-fit:contain; border-radius:4px; border:1px solid var(--color-border)" alt="">
</a>
{{else}}
<a href="{{.URL}}" target="_blank" rel="noopener noreferrer" style="font-size:1.5rem; text-decoration:none" title="Download file">📄</a>
{{end}}
</td>
<td>
<div style="display:flex; align-items:center; gap:0.5rem; flex-wrap:wrap;">
<span class="ext-chip">{{.Ext}}</span>
{{if .OriginalName}}<span style="font-size:0.9rem">{{.OriginalName}}</span>{{end}}
</div>
<code style="font-size:0.7rem; opacity:.6; display:block; margin-top:0.2rem;">{{.Filename}}</code>
</td>
<td id="size-{{.Filename}}">{{.SizeHuman}}</td>
<td id="dim-{{.Filename}}">{{if .Width}}{{.Width}}&times;{{.Height}}{{else}}—{{end}}</td>
<td>{{.ModTime.Format "2006-01-02 15:04"}}</td>
<td class="col-actions">
<div class="flex gap-1">
<button type="button" class="btn btn-secondary btn-sm" onclick="copyMarkdown('{{.Filename}}', {{.IsImage}}, '{{.OriginalName}}', this)">Copy</button>
{{if .CanResize}}<button type="button" class="btn btn-secondary btn-sm" onclick="openResize('{{.Filename}}', {{.Width}}, {{.Height}})">Resize</button>{{end}}
<form method="post" action="/admin/uploads/delete/{{.Filename}}" style="display:inline" onsubmit="return confirm('Delete this file?')">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-danger btn-sm">Del</button>
</form>
</div>
</td>
</tr>
{{else}}
<tr><td colspan="6">
<div class="empty-state">
<span class="empty-state-icon">📄</span>
<p class="empty-state-text">No uploads yet. Use the buttons above to upload an image or file.</p>
</div>
</td></tr>
{{end}}
</tbody>
</table>
</div>
</div>
<dialog id="resize-dialog">
<article>
<header>
<button aria-label="Close" onclick="document.getElementById('resize-dialog').close()"></button>
<h3>Resize Image</h3>
</header>
<p id="resize-current" class="text-muted" style="margin-bottom: 1rem;"></p>
<label class="form-label" for="resize-dim">Max dimension (px)</label>
<input type="number" id="resize-dim" value="1200" min="64" max="8192" step="1">
<small id="resize-status" class="text-muted" style="display:block; margin-top:0.5rem;"></small>
<footer>
<button type="button" class="btn btn-secondary" onclick="document.getElementById('resize-dialog').close()">Cancel</button>
<button type="button" id="resize-confirm" class="btn btn-primary">Resize</button>
</footer>
</article>
</dialog>
<script src="/static/upload.js"></script>
<script>
var currentResizeFile = '';
var currentResizeFile = '';
function copyMarkdown(filename, isImage, originalName, btn) {
var url = '/uploads/' + filename;
var label = originalName || filename;
var md = isImage ? '![](' + url + ')' : '[' + label + '](' + url + ')';
navigator.clipboard.writeText(md).then(function() {
var orig = btn.textContent;
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = orig; }, 1500);
});
}
function copyMarkdown(filename, isImage, originalName, btn) {
var url = '/uploads/' + filename;
var label = originalName || filename;
var md = isImage ? '![](' + url + ')' : '[' + label + '](' + url + ')';
var orig = btn.textContent;
navigator.clipboard.writeText(md).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = orig; }, 1500);
});
}
function openResize(filename, w, h) {
currentResizeFile = filename;
document.getElementById('resize-current').textContent = 'Current: ' + w + '×' + h;
document.getElementById('resize-status').textContent = '';
document.getElementById('resize-confirm').disabled = false;
document.getElementById('resize-dialog').showModal();
}
function openResize(filename, w, h) {
currentResizeFile = filename;
document.getElementById('resize-current').textContent = 'Current: ' + w + '×' + h;
document.getElementById('resize-status').textContent = '';
document.getElementById('resize-confirm').disabled = false;
document.getElementById('resize-dialog').showModal();
}
document.getElementById('resize-confirm').addEventListener('click', function() {
var dim = document.getElementById('resize-dim').value;
var status = document.getElementById('resize-status');
var btn = this;
status.textContent = 'Resizing…';
btn.disabled = true;
document.getElementById('resize-confirm').addEventListener('click', function() {
var dim = document.getElementById('resize-dim').value;
var status = document.getElementById('resize-status');
var btn = this;
status.textContent = 'Resizing…';
btn.disabled = true;
var fd = new FormData();
fd.append('csrf_token', window.GlimmerUpload.getCsrfToken());
fd.append('max_dim', dim);
var fd = new FormData();
fd.append('csrf_token', window.GlimmerUpload.getCsrfToken());
fd.append('max_dim', dim);
fetch('/admin/uploads/resize/' + currentResizeFile, { method: 'POST', body: fd, credentials: 'same-origin' })
.then(function(r) { return r.json(); })
.then(function(data) {
btn.disabled = false;
if (data.error) {
status.textContent = 'Error: ' + data.error;
return;
}
var sizeEl = document.getElementById('size-' + currentResizeFile);
var dimEl = document.getElementById('dim-' + currentResizeFile);
if (sizeEl) sizeEl.textContent = data.size_human;
if (dimEl) dimEl.textContent = data.width + '×' + data.height;
status.textContent = 'Done — ' + data.size_human;
var imgs = document.querySelectorAll('img[src="/uploads/' + currentResizeFile + '"]');
imgs.forEach(function(img) { img.src = '/uploads/' + currentResizeFile + '?t=' + Date.now(); });
})
.catch(function() {
btn.disabled = false;
status.textContent = 'Failed';
});
});
fetch('/admin/uploads/resize/' + currentResizeFile, { method: 'POST', body: fd, credentials: 'same-origin' })
.then(function(r) { return r.json(); })
.then(function(data) {
btn.disabled = false;
if (data.error) {
status.textContent = 'Error: ' + data.error;
return;
}
var sizeEl = document.getElementById('size-' + currentResizeFile);
var dimEl = document.getElementById('dim-' + currentResizeFile);
if (sizeEl) sizeEl.textContent = data.size_human;
if (dimEl) dimEl.textContent = data.width + '×' + data.height;
status.textContent = 'Done — ' + data.size_human;
var imgs = document.querySelectorAll('img[src="/uploads/' + currentResizeFile + '"]');
imgs.forEach(function(img) { img.src = '/uploads/' + currentResizeFile + '?t=' + Date.now(); });
})
.catch(function() {
btn.disabled = false;
status.textContent = 'Failed';
});
});
window.GlimmerUpload.init({
imgBtn: document.getElementById('upload-img-btn'),
fileBtn: document.getElementById('upload-file-btn'),
imgInput: document.getElementById('img-input'),
fileInput: document.getElementById('file-input'),
statusEl: document.getElementById('upload-status'),
maxImageMB: {{.UploadMaxMB}},
onUploaded: function() { location.reload(); }
});
window.GlimmerUpload.init({
imgBtn: document.getElementById('upload-img-btn'),
fileBtn: document.getElementById('upload-file-btn'),
imgInput: document.getElementById('img-input'),
fileInput: document.getElementById('file-input'),
statusEl: document.getElementById('upload-status'),
maxImageMB: {{.UploadMaxMB}},
onUploaded: function() { location.reload(); }
});
</script>
</body>
</html>
{{end}}
+120
View File
@@ -0,0 +1,120 @@
{{define "base"}}<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="csrf-token" content="{{.CSRFToken}}">
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<title>{{block "title" .}}Glimmer{{end}}</title>
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
<div class="app-container {{if not .LoggedIn}}public-layout{{end}}">
{{if .LoggedIn}}
<aside class="sidebar">
<a href="/admin" class="brand">
<div class="brand-logo">G</div>
<span class="brand-name">Glimmer</span>
</a>
<nav>
<ul class="nav-list">
<li class="nav-item {{if eq .ActiveNav "links"}}active{{end}}">
<a href="/admin" class="nav-link">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M13.19 8.688a4.5 4.5 0 011.242 7.244l-4.5 4.5a4.5 4.5 0 01-6.364-6.364l1.757-1.757m13.35-.622l1.757-1.757a4.5 4.5 0 00-6.364-6.364l-4.5 4.5a4.5 4.5 0 001.242 7.244"/></svg>
Links
</a>
</li>
<li class="nav-item {{if eq .ActiveNav "pastes"}}active{{end}}">
<a href="/admin/bin" class="nav-link">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"/></svg>
Pastes
</a>
</li>
<li class="nav-item {{if eq .ActiveNav "uploads"}}active{{end}}">
<a href="/admin/uploads" class="nav-link">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 001.5-1.5V6a1.5 1.5 0 00-1.5-1.5H3.75A1.5 1.5 0 002.25 6v12a1.5 1.5 0 001.5 1.5zm10.5-11.25h.008v.008h-.008V8.25zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z"/></svg>
Uploads
</a>
</li>
<li class="nav-item {{if eq .ActiveNav "shorten"}}active{{end}}">
<a href="/" class="nav-link">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15"/></svg>
New Link
</a>
</li>
</ul>
</nav>
<div class="sidebar-footer">
<a href="/" class="btn btn-secondary btn-sm btn-block" style="justify-content:center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25"/></svg>
Home
</a>
<form action="/admin/logout" method="POST" style="margin:0">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-secondary btn-sm btn-block" style="justify-content:center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15M12 9l-3 3m0 0l3 3m-3-3h12.75"/></svg>
Log out
</button>
</form>
</div>
</aside>
{{else}}
<header class="public-header">
<a href="/" class="public-brand">
<div class="brand-logo">G</div>
<span class="brand-name">Glimmer</span>
</a>
<div>
{{if .LoggedIn}}
<a href="/admin" class="btn btn-secondary btn-sm">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M9 12h3.75M9 15h3.75M9 18h3.75m3 .75H18a2.25 2.25 0 002.25-2.25V6.108c0-1.135-.845-2.098-1.976-2.192a48.424 48.424 0 00-1.123-.08m-5.801 0c-.065.21-.1.433-.1.664 0 .414.336.75.75.75h4.5a.75.75 0 00.75-.75 2.25 2.25 0 00-.1-.664m-5.8 0A2.251 2.251 0 0113.5 2.25H15c1.012 0 1.867.668 2.15 1.586m-5.8 0c-.376.023-.75.05-1.124.08C9.095 4.01 8.25 4.973 8.25 6.108V8.25m0 0H4.875c-.621 0-1.125.504-1.125 1.125v11.25c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V9.375c0-.621-.504-1.125-1.125-1.125H8.25zM6.75 12h.008v.008H6.75V12zm0 3h.008v.008H6.75V15zm0 3h.008v.008H6.75V18z"/></svg>
Admin
</a>
{{else}}
<a href="/admin/login" class="btn btn-secondary btn-sm">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 6a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0zM4.501 20.118a7.5 7.5 0 0114.998 0A17.933 17.933 0 0112 21.75c-2.676 0-5.216-.584-7.499-1.632z"/></svg>
Admin
</a>
{{end}}
</div>
</header>
{{end}}
<main class="main-wrapper">
{{template "content" .}}
</main>
</div>
<!-- QR Code Preview Modal -->
<div id="qr-modal-overlay" class="qr-modal-overlay" onclick="if(event.target===this)closeQRModal()">
<div id="qr-modal-card" class="qr-modal-card">
<button class="qr-modal-close" onclick="closeQRModal()" aria-label="Close">&times;</button>
<h3>QR Code</h3>
<img id="qr-modal-image" class="qr-modal-image" src="" alt="QR Code">
<code id="qr-modal-link" class="qr-modal-link"></code>
<a id="qr-modal-download" download="" href="" class="btn btn-primary btn-block" style="font-size:0.9rem; text-align:center;">Download PNG</a>
</div>
</div>
<script>
function openQRModal(slug, name) {
var overlay = document.getElementById('qr-modal-overlay');
document.getElementById('qr-modal-image').src = '/admin/qr/' + slug;
document.getElementById('qr-modal-link').textContent = '/admin/qr/' + slug;
var dl = document.getElementById('qr-modal-download');
dl.href = '/admin/qr/' + slug;
dl.download = (name || slug) + '_QR.svg';
overlay.classList.add('show');
}
function closeQRModal() {
document.getElementById('qr-modal-overlay').classList.remove('show');
document.getElementById('qr-modal-image').src = '';
}
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') closeQRModal();
});
</script>
</body>
</html>{{end}}
+30 -39
View File
@@ -1,43 +1,34 @@
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Access Token Required — Glimmer</title>
<link rel="stylesheet" href="/static/pico.min.css">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<nav>
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
<ul><li><a href="/">Home</a></li></ul>
</nav>
<main class="container" style="max-width:480px;padding-top:4rem;text-align:center">
<p style="font-size:4rem;line-height:1;margin:0">&#128274;</p>
<h2 style="margin-top:0.5rem">Access Token Required</h2>
<p style="color:var(--pico-muted-color)">This paste is protected. Enter the access token to view it.</p>
{{define "title"}}Access Token Required — Glimmer{{end}}
{{define "content"}}
<div style="max-width: 480px; margin: 4rem auto 0;">
{{if .Error}}
<article aria-label="error" class="alert-error" style="text-align:left">{{.Error}}</article>
{{end}}
<div class="card" style="text-align: center; padding: 2.5rem 2rem;">
<div style="font-size: 3.5rem; line-height: 1; margin-bottom: 0.5rem;">🔒</div>
<h2 style="font-size: 1.5rem;">Access Token Required</h2>
<p class="text-muted" style="margin-bottom: 1.5rem;">This paste is protected. Enter the access token to view it.</p>
{{if .Error}}
<div class="alert alert-error" style="text-align: left;">{{.Error}}</div>
{{end}}
<form id="token-form" style="text-align: left;">
<div class="form-group">
<label for="token-input" class="form-label">Token</label>
<input type="text" id="token-input" placeholder="Enter access token" required autofocus>
</div>
<button type="submit" class="btn btn-primary btn-lg btn-block">View Paste</button>
</form>
</div>
</div>
<form id="token-form" style="text-align:left;margin-top:1.5rem">
<label>
Token
<input type="text" id="token-input" required placeholder="Enter access token" autofocus>
</label>
<button type="submit" style="width:100%">View Paste</button>
</form>
</main>
<script>
document.getElementById('token-form').addEventListener('submit', function(e) {
e.preventDefault();
var token = document.getElementById('token-input').value.trim();
if (token) {
window.location.href = window.location.pathname + '/' + encodeURIComponent(token);
}
});
document.getElementById('token-form').addEventListener('submit', function(e) {
e.preventDefault();
var token = document.getElementById('token-input').value.trim();
if (token) {
window.location.href = window.location.pathname + '/' + encodeURIComponent(token);
}
});
</script>
</body>
</html>
{{end}}
+49 -47
View File
@@ -1,49 +1,51 @@
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{with .Paste}}{{with .Title}}<title>{{.}}</title>{{else}}<title>{{with $.Paste}}{{.Name}}{{end}}</title>{{end}}{{end}}
<link rel="stylesheet" href="/static/pico.min.css">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<nav>
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
<ul><li>{{if .LoggedIn}}<a href="/admin/bin">Admin</a>{{else}}<a href="/admin/login">Admin</a>{{end}}</li></ul>
</nav>
<main class="container" style="max-width:860px">
{{with .Paste}}
<div class="paste-header">
<div>
<h2 style="margin-bottom:0.25rem">{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}}</h2>
<small style="color:var(--pico-muted-color)">
<code>/bin/{{.Name}}</code>
&nbsp;&middot;&nbsp;
<span class="format-badge">{{.Format}}</span>
&nbsp;&middot;&nbsp;
{{if .Token}}<span style="color:var(--pico-ins-color)">&#128274; token protected</span>{{else}}<span>public</span>{{end}}
&nbsp;&middot;&nbsp;
updated {{.UpdatedAt.Format "2006-01-02 15:04"}}
</small>
</div>
<div class="paste-toolbar">
<a href="?raw=1" role="button" class="outline" style="padding:0.3rem 0.75rem;font-size:0.85rem">Raw</a>
<button class="outline" style="padding:0.3rem 0.75rem;font-size:0.85rem"
onclick="navigator.clipboard.writeText(document.getElementById('paste-raw').innerText).then(()=>{this.textContent='Copied!';setTimeout(()=>this.textContent='Copy',1500)})">Copy</button>
</div>
</div>
<hr>
{{end}}
{{define "title"}}{{if .Paste}}{{with .Paste}}{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}}{{end}}{{else}}Paste{{end}} — Glimmer{{end}}
{{define "content"}}
{{with .Paste}}
<div style="max-width: 900px; margin: 0 auto;">
<div class="paste-body">
{{.PasteBody}}
</div>
<div class="paste-header">
<div>
<h2>{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}}</h2>
<div class="paste-meta">
<code>/bin/{{.Name}}</code>
<span class="tag-pill badge-format">{{.Format}}</span>
{{if .Token}}
<span class="tag-pill badge-token">🔒 token protected</span>
{{else}}
<span class="tag-pill badge-public">public</span>
{{end}}
<span class="text-muted">updated {{.UpdatedAt.Format "2006-01-02 15:04"}}</span>
</div>
</div>
<div class="paste-toolbar">
<a href="?raw=1" class="btn btn-secondary btn-sm">Raw</a>
<button class="btn btn-primary btn-sm" onclick="copyPaste(this)">Copy</button>
</div>
</div>
{{with .Paste}}
<pre id="paste-raw" style="display:none">{{.Content}}</pre>
{{end}}
</main>
</body>
</html>
<div class="card" style="padding: 2rem;">
<div class="paste-body">
{{$.PasteBody}}
</div>
</div>
<pre id="paste-raw" style="display:none">{{.Content}}</pre>
</div>
<script>
function copyPaste(btn) {
var orig = btn.textContent;
navigator.clipboard.writeText(document.getElementById('paste-raw').innerText).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = orig; }, 1500);
});
}
</script>
{{else}}
<div class="card center-page">
<h2>Paste not found</h2>
<p class="text-muted">This paste may have been deleted or is hidden.</p>
</div>
{{end}}
{{end}}
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{with .Paste}}<title>{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}} — Glimmer Paste</title>{{end}}
<link rel="stylesheet" href="/static/css/style.css">
<style>
/* Strip the page chrome when embedded — no header/toolbar/card wrapper */
body { padding: 1.5rem; }
.embed-wrap { max-width: 820px; margin: 0 auto; }
</style>
</head>
<body>
<div class="embed-wrap">
{{with .Paste}}
<div class="paste-body">
{{$.PasteBody}}
</div>
{{end}}
</div>
</body>
</html>
+66 -59
View File
@@ -1,64 +1,71 @@
<!DOCTYPE html>
<html lang="en" data-theme="light">
<head>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Glimmer</title>
<link rel="stylesheet" href="/static/pico.min.css">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<nav>
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
<ul><li>{{if .LoggedIn}}<a href="/admin">Admin</a>{{else}}<a href="/admin/login">Admin</a>{{end}}</li></ul>
</nav>
<main class="container">
<hgroup>
<h2>Shorten a URL</h2>
<p>Paste a long URL and get a short link</p>
</hgroup>
{{define "title"}}Glimmer{{end}}
{{define "content"}}
<div style="max-width: 640px; margin: 1.5rem auto 0;">
{{if .Error}}
<article aria-label="error" style="border-left: 4px solid var(--pico-del-color); padding: 0.75rem 1rem;">
{{.Error}}
</article>
{{end}}
<div class="card" style="text-align: center; padding: 2.5rem 2rem;">
<div class="brand" style="justify-content: center; margin-bottom: 1rem;">
<div class="brand-logo">G</div>
<span class="brand-name">Glimmer</span>
</div>
<h1 style="font-size: 1.75rem; margin-bottom: 0.5rem;">Shorten a URL</h1>
<p class="text-muted" style="margin-bottom: 2rem;">Paste a long URL and get a short link.</p>
{{if .ShortURL}}
<article aria-label="success">
<p>Your short link is ready:</p>
<p><small>{{.OriginalURL}}</small></p>
<div class="result-box">
<code id="short-url">{{.ShortURL}}</code>
<button onclick="navigator.clipboard.writeText(document.getElementById('short-url').textContent).then(()=>{this.textContent='Copied!'})">Copy</button>
</div>
{{if .QRSVG}}
<div style="text-align:center; margin-top:1rem;">{{.QRSVG}}</div>
{{end}}
</article>
{{end}}
{{if .Error}}
<div class="alert alert-error">{{.Error}}</div>
{{end}}
<form method="post" action="/shorten" id="shorten-form">
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
<label for="url">URL to shorten</label>
<input type="text" inputmode="url" id="url" name="url" placeholder="https://example.com/very/long/url" required>
{{if .ShortURL}}
<div class="alert alert-success" style="text-align:left;">
<div style="flex-grow: 1;">
<strong>Your short link is ready.</strong>
<p class="text-muted" style="font-size: 0.85rem; margin-top: 0.25rem; word-break: break-all;">{{.OriginalURL}}</p>
</div>
</div>
<div class="result-box">
<code id="short-url">{{.ShortURL}}</code>
<button class="btn btn-secondary btn-sm" onclick="copyToClipboard(document.getElementById('short-url').textContent, this)">Copy</button>
</div>
{{if .QRSVG}}
<div class="qr-display">{{.QRSVG}}</div>
{{end}}
{{end}}
{{if .LoggedIn}}
<label for="slug">Custom slug <small>(optional)</small></label>
<input type="text" id="slug" name="slug" placeholder="my-link" pattern="[a-zA-Z0-9_-]+" title="Letters, numbers, hyphens, underscores only">
{{end}}
<form method="post" action="/shorten" id="shorten-form" style="text-align: left;">
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
<button type="submit">Shorten</button>
</form>
<script>
document.getElementById('shorten-form').addEventListener('submit', function() {
const input = document.getElementById('url');
if (input.value && !input.value.includes('://')) {
input.value = 'https://' + input.value;
}
});
</script>
</main>
</body>
</html>
<div class="form-group">
<label for="url" class="form-label">URL to shorten</label>
<input type="text" inputmode="url" id="url" name="url" placeholder="https://example.com/very/long/url" required>
</div>
{{if .LoggedIn}}
<div class="form-group">
<label for="slug" class="form-label">Custom slug <small class="text-muted">(optional)</small></label>
<input type="text" id="slug" name="slug" placeholder="my-link" pattern="[a-zA-Z0-9_-]+" title="Letters, numbers, hyphens, underscores only">
<small class="form-help">Leave blank to auto-generate a 3-character slug.</small>
</div>
{{end}}
<button type="submit" class="btn btn-primary btn-lg btn-block">Shorten</button>
</form>
</div>
</div>
<script>
document.getElementById('shorten-form').addEventListener('submit', function() {
var input = document.getElementById('url');
if (input.value && input.value.indexOf('://') === -1) {
input.value = 'https://' + input.value;
}
});
function copyToClipboard(text, btn) {
var orig = btn.textContent;
navigator.clipboard.writeText(text).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = orig; }, 1500);
});
}
</script>
{{end}}