Initial commit: simpleblog
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block title %}Albums · {{ site_title }}{% endblock %}
|
||||
|
||||
{% block admin_content %}
|
||||
<h1>Albums</h1>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Upload a photo to an album</h2>
|
||||
<form id="album-upload-form" method="POST" action="{{ url_for('admin.upload') }}" enctype="multipart/form-data" class="stack">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<div class="form-group">
|
||||
<label for="album-photo-file">Photo file</label>
|
||||
<input type="file" id="album-photo-file" name="file" accept="image/*" multiple required>
|
||||
<small>Choose one or more photos to add to this album.</small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="album-photo-album">Album</label>
|
||||
<select id="album-photo-album" name="album" required>
|
||||
{% for a in albums %}
|
||||
<option value="{{ a.slug }}">{{ a.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Upload photo</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>New album</h2>
|
||||
<form method="POST" action="{{ url_for('admin.album_new') }}" class="stack">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<div class="form-group">
|
||||
<label for="name">Album name</label>
|
||||
<input type="text" id="name" name="name" placeholder="e.g. Road trip 2026" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description">Description</label>
|
||||
<textarea id="description" name="description" rows="3"></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Create album</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% if editing %}
|
||||
<div class="admin-panel">
|
||||
<h2>Edit: {{ editing.name }}</h2>
|
||||
<form method="POST" action="{{ url_for('admin.album_edit', slug=editing.slug) }}" class="stack">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<div class="form-group">
|
||||
<label for="name">Album name</label>
|
||||
<input type="text" id="name" name="name" value="{{ editing.name }}" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description">Description</label>
|
||||
<textarea id="description" name="description" rows="3">{{ editing.description or '' }}</textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>All albums</h2>
|
||||
{% if albums %}
|
||||
<table class="admin-table">
|
||||
<thead><tr><th>Name</th><th>Photos</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{% for a in albums %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('public.photos', slug=a.slug) }}">{{ a.name }}</a></td>
|
||||
<td>{{ album_counts.get(a.id, 0) }}</td>
|
||||
<td>
|
||||
<a class="primary" href="{{ url_for('admin.album_edit', slug=a.slug) }}">Edit</a>
|
||||
<span class="field-hint">·</span>
|
||||
<form method="POST" action="{{ url_for('admin.album_delete', slug=a.slug) }}" style="display:inline;" onsubmit="return confirm('Delete this album? Its photos stay, but become ungrouped.');">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button class="btn btn-danger" type="submit">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="empty-state">No albums yet.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if ungrouped_count %}
|
||||
<p><a class="primary" href="{{ url_for('admin.media_list') }}">Manage photos ({{ ungrouped_count }} ungrouped)</a></p>
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
// NOTE: one file per request, with FormData built from scratch. Cloning the
|
||||
// form (new FormData(form)) also re-sends the <input type="file"> parts, so
|
||||
// the server stored the selected photo twice.
|
||||
// NOTE: every upload is awaited before location.reload(). The old version
|
||||
// fired all the fetches and reloaded synchronously in the same tick, which
|
||||
// aborted the in-flight requests — the album came back unchanged, so uploads
|
||||
// looked broken even though /admin/upload was healthy.
|
||||
(function () {
|
||||
var form = document.getElementById("album-upload-form");
|
||||
if (!form) return;
|
||||
form.addEventListener("submit", async function (e) {
|
||||
e.preventDefault();
|
||||
var fileInput = form.elements["album-photo-file"];
|
||||
var files = Array.prototype.slice.call(fileInput.files);
|
||||
if (!files.length) { alert("Choose one or more photos."); return; }
|
||||
var album = form.elements["album-photo-album"].value;
|
||||
var albumName = album ? form.elements["album-photo-album"].options[form.elements["album-photo-album"].selectedIndex].text : "";
|
||||
var csrf = form.elements["csrf_token"].value;
|
||||
var btn = form.querySelector("button[type=submit]");
|
||||
btn.disabled = true;
|
||||
var ok = 0, failed = [];
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
btn.textContent = "Uploading " + (i + 1) + "/" + files.length + "...";
|
||||
var fd = new FormData();
|
||||
fd.append("csrf_token", csrf);
|
||||
if (album) fd.append("album", album);
|
||||
fd.append("file", files[i], files[i].name);
|
||||
try {
|
||||
var r = await fetch(form.action, { method: "POST", credentials: "same-origin", body: fd });
|
||||
if (!r.ok) throw new Error("HTTP " + r.status);
|
||||
await r.json();
|
||||
ok++;
|
||||
} catch (err) {
|
||||
failed.push(files[i].name + ": " + err.message);
|
||||
}
|
||||
}
|
||||
btn.disabled = false;
|
||||
btn.textContent = "Upload photo";
|
||||
if (failed.length) {
|
||||
alert(ok + " added to '" + albumName + "', " + failed.length + " failed:\n" + failed.join("\n"));
|
||||
} else {
|
||||
alert(ok + " photo" + (ok === 1 ? "" : "s") + " added to '" + albumName + "'.");
|
||||
}
|
||||
location.reload();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,187 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='vendor/leaflet/leaflet.css') }}">
|
||||
{% endblock %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>Analytics</h1>
|
||||
<p class="muted">Anonymous visitor tracking. Only an opaque <code>visitor_id</code> cookie is stored; locations are approximate and derived from the visitor's IP — the address itself is never saved.</p>
|
||||
<div class="admin-stat-grid">
|
||||
<div class="admin-stat"><span class="num">{{ total_visitors }}</span><span class="label">Unique visitors</span></div>
|
||||
<div class="admin-stat"><span class="num">{{ total_visits }}</span><span class="label">Total visits</span></div>
|
||||
<div class="admin-stat"><span class="num">{{ unique_pages }}</span><span class="label">Pages viewed</span></div>
|
||||
<div class="admin-stat"><span class="num">{{ 'n/a' if total_visitors == 0 else (total_visits | int / (total_visitors or 1) | round(2)) }}</span><span class="label">Avg. pages/visit</span></div>
|
||||
<div class="admin-stat"><span class="num">{{ total_countries }}</span><span class="label">Countries</span></div>
|
||||
<div class="admin-stat"><span class="num">{{ total_cities }}</span><span class="label">Cities</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Visitor map</h2>
|
||||
{% if map_points %}
|
||||
<p class="muted">Each circle is a city. Larger circles mean more visits — click one for the city, region, country and counts.</p>
|
||||
{% else %}
|
||||
<p class="empty-state">No location data yet. The map fills in as visitors arrive; locations come from the visitor's IP (or, for local/LAN visitors, this server's own region).</p>
|
||||
{% endif %}
|
||||
<div id="visitor-map" class="visitor-map"></div>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Location trends</h2>
|
||||
{% if location_trend.series %}
|
||||
<p class="muted">Visits per day over the last {{ location_trend.labels|length }} days, by location. Hover the chart for daily counts.</p>
|
||||
<div class="chart-wrap"><canvas id="location-trend-chart" height="280"></canvas></div>
|
||||
<div id="location-trend-legend" class="chart-legend"></div>
|
||||
{% else %}
|
||||
<p class="empty-state">No visits in the last 30 days.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<div class="admin-split">
|
||||
<div>
|
||||
<h2>Top countries</h2>
|
||||
<table class="admin-table">
|
||||
<thead><tr><th>Country</th><th>Visitors</th><th>Visits</th></tr></thead>
|
||||
<tbody>
|
||||
{% for r in top_countries %}
|
||||
<tr>
|
||||
<td>{% if r.country_code %}<span class="location-flag">{{ r.country_code|country_flag }}</span> {% endif %}{{ r.country }}</td>
|
||||
<td>{{ r.visitors }}</td>
|
||||
<td>{{ r.visits }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="3" class="empty-state">No location data yet.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div>
|
||||
<h2>Top cities</h2>
|
||||
<table class="admin-table">
|
||||
<thead><tr><th>City</th><th>Visitors</th><th>Visits</th></tr></thead>
|
||||
<tbody>
|
||||
{% for r in top_cities %}
|
||||
<tr>
|
||||
<td>
|
||||
{% if r.country_code %}<span class="location-flag">{{ r.country_code|country_flag }}</span> {% endif %}{{ r.city }}
|
||||
<span class="muted">{% if r.region %}{{ r.region }}, {% endif %}{{ r.country }}</span>
|
||||
</td>
|
||||
<td>{{ r.visitors }}</td>
|
||||
<td>{{ r.visits }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="3" class="empty-state">No city data yet.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Where visitors to each page come from</h2>
|
||||
{% if page_locations %}
|
||||
<p class="muted">The busiest pages and the countries their readers came from. Counts are unique visitors per country.</p>
|
||||
<table class="admin-table">
|
||||
<thead><tr><th>Page</th><th>Top locations</th><th>Visits</th></tr></thead>
|
||||
<tbody>
|
||||
{% for page in page_locations %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ page.path }}"><code>{{ page.path }}</code></a>
|
||||
{% if page.title %}<br><span class="muted">{{ page.title }}</span>{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% for c in page.countries %}
|
||||
<span class="location-chip">{% if c.country_code %}{{ c.country_code|country_flag }} {% endif %}{{ c.country }} <strong>{{ c.visitors }}</strong></span>
|
||||
{% endfor %}
|
||||
{% if page.more_countries %}<span class="muted">+{{ page.more_countries }} more</span>{% endif %}
|
||||
</td>
|
||||
<td>{{ page.visits }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="empty-state">No page visits yet.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Most viewed pages</h2>
|
||||
<table class="admin-table">
|
||||
<thead><tr><th>Page</th><th>Title</th><th>Visits</th></tr></thead>
|
||||
<tbody>
|
||||
{% for r in top_pages %}
|
||||
<tr>
|
||||
<td><code>{{ r.page_path }}</code></td>
|
||||
<td>{{ r.title or "(untitled)" }}</td>
|
||||
<td>{{ r.c }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="3" class="empty-state">No visits yet.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Devices</h2>
|
||||
<table class="admin-table">
|
||||
<thead><tr><th>Device</th><th>Visitors</th></tr></thead>
|
||||
<tbody>
|
||||
{% for r in top_devices %}
|
||||
<tr><td>{{ r.device }}</td><td>{{ r.c }}</td></tr>
|
||||
{% else %}
|
||||
<tr><td colspan="2" class="empty-state">No data yet.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Browsers</h2>
|
||||
<table class="admin-table">
|
||||
<thead><tr><th>Browser</th><th>Visitors</th></tr></thead>
|
||||
<tbody>
|
||||
{% for r in top_browsers %}
|
||||
<tr><td>{{ r.browser or "(unknown)" }}</td><td>{{ r.c }}</td></tr>
|
||||
{% else %}
|
||||
<tr><td colspan="2" class="empty-state">No data yet.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Where they came from</h2>
|
||||
<table class="admin-table">
|
||||
<thead><tr><th>Source</th><th>Visitors</th></tr></thead>
|
||||
<tbody>
|
||||
{% for r in top_sources %}
|
||||
<tr><td>{{ r.source }}{% if loop.first %} <span class="term" style="font-size:.8em">(raw referrers below)</span>{% endif %}</td><td>{{ r.c }}</td></tr>
|
||||
{% else %}
|
||||
<tr><td colspan="2" class="empty-state">No data yet.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="admin-table">
|
||||
<thead><tr><th>Referrer domain</th><th>Visitors</th></tr></thead>
|
||||
<tbody>
|
||||
{% for r in top_domains %}
|
||||
<tr><td>{{ r.referrer_domain or "—" }}</td><td>{{ r.c }}</td></tr>
|
||||
{% else %}
|
||||
<tr><td colspan="2" class="empty-state">No referrers yet.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script type="application/json" id="visitor-map-data">{{ map_points | tojson }}</script>
|
||||
{% if location_trend.series %}
|
||||
<script type="application/json" id="location-trend-data">{{ location_trend | tojson }}</script>
|
||||
{% endif %}
|
||||
<script src="{{ url_for('static', filename='vendor/leaflet/leaflet.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/admin_analytics.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,447 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>Appearance</h1>
|
||||
|
||||
<!-- ==========================================================================
|
||||
ONE FORM. Every control lives in a single <form>, so a single "Save all"
|
||||
submits site_title / site_tagline / comments_enabled AND custom_css (the
|
||||
merged theme + raw CSS) together. Because they are all submitted at once,
|
||||
saving one section can no longer clobber another — the handler only writes
|
||||
keys that are present in request.form, and here every key is always present.
|
||||
|
||||
Theme styling (accent / background / text / sidebar / font / columns /
|
||||
header layout / radius / dark) is rendered into the raw-CSS textarea live
|
||||
as you tweak the controls (see buildTheme() below), so that textarea is the
|
||||
single source of truth for custom_css: it holds the generated :root block
|
||||
plus any hand-written CSS you add. The "Reset theme to defaults" button
|
||||
regenerates the :root block from the built-in defaults.
|
||||
========================================================================== -->
|
||||
<form id="appearance-form" method="post" action="{{ url_for('admin.appearance') }}" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
|
||||
<!-- --- Site identity ---------------------------------------------------- -->
|
||||
<div class="admin-panel identity">
|
||||
<h2>Site identity</h2>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="site-title">Site title</label>
|
||||
<input type="text" id="site-title" name="site_title" value="{{ site_title }}" autocomplete="off">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="site-tagline">Tagline / statement</label>
|
||||
<input type="text" id="site-tagline" name="site_tagline" value="{{ site_tagline }}" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="meta-description">Default meta description</label>
|
||||
<input type="text" id="meta-description" name="meta_description" value="{{ meta_description }}" autocomplete="off"
|
||||
placeholder="Used by search engines and social previews when a page has no excerpt">
|
||||
<span class="field-hint">Posts use their excerpt first; this is the fallback for home, archive, tag and other pages.</span>
|
||||
</div>
|
||||
|
||||
<!-- Use radio buttons (not checkbox+hidden): a checkbox's unchecked state
|
||||
omits the key, so the old hidden "0" trick relied on "0" being truthy,
|
||||
which it isn't in Python — meaning admins could never switch comments
|
||||
OFF via this page. Radios submit an explicit 1/0 that the route reads
|
||||
verbatim. -->
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input type="radio" name="comments_enabled" value="1" {% if comments_enabled %}checked{% endif %}>
|
||||
Enable comments on posts and pages
|
||||
</label>
|
||||
<label class="checkbox-label">
|
||||
<input type="radio" name="comments_enabled" value="0" {% if not comments_enabled %}checked{% endif %}>
|
||||
Disable comments on posts and pages
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- --- Theme editor (GUI) ------------------------------------------------ -->
|
||||
<div class="theme-editor">
|
||||
<h2>Theme</h2>
|
||||
<p class="field-hint">These controls render into the Custom CSS box below as you change them. Edit the box directly for anything more advanced.</p>
|
||||
|
||||
<!-- Colour controls -->
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="t-accent">Accent / link colour</label>
|
||||
<div class="swatch-row">
|
||||
<input type="color" id="t-accent" name="t-accent" value="{{ theme.accent }}">
|
||||
<input type="text" id="t-accent-hex" class="hex-input" value="{{ theme.accent }}" spellcheck="false" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="t-bg">Page background</label>
|
||||
<div class="swatch-row">
|
||||
<input type="color" id="t-bg" name="t-bg" value="{{ theme.background }}">
|
||||
<input type="text" id="t-bg-hex" class="hex-input" value="{{ theme.background }}" spellcheck="false" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="t-text">Text colour</label>
|
||||
<div class="swatch-row">
|
||||
<input type="color" id="t-text" name="t-text" value="{{ theme.text }}">
|
||||
<input type="text" id="t-text-hex" class="hex-input" value="{{ theme.text }}" spellcheck="false" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="t-sidebar">Sidebar / panel background</label>
|
||||
<div class="swatch-row">
|
||||
<input type="color" id="t-sidebar" name="t-sidebar" value="{{ theme.sidebar }}">
|
||||
<input type="text" id="t-sidebar-hex" class="hex-input" value="{{ theme.sidebar }}" spellcheck="false" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="t-font">Font family</label>
|
||||
<select id="t-font" name="t-font">
|
||||
{% for opt in theme.fonts %}
|
||||
<option value="{{ opt.value }}" {% if opt.value == theme.font %}selected{% endif %}>{{ opt.label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Layout controls -->
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="t-posts">Post grid columns</label>
|
||||
<select id="t-posts" name="t-posts">
|
||||
{% for opt in theme.post_columns %}
|
||||
<option value="{{ opt.value }}" {% if opt.value == theme.posts %}selected{% endif %}>{{ opt.label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="t-header">Site header</label>
|
||||
<select id="t-header" name="t-header">
|
||||
{% for opt in theme.header_layouts %}
|
||||
<option value="{{ opt.value }}" {% if opt.value == theme.header %}selected{% endif %}>{{ opt.label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="t-radius">Corner radius: <span id="radius-val">{{ theme.radius }}px</span></label>
|
||||
<input type="range" id="t-radius" name="t-radius" min="0" max="24" step="1" value="{{ theme.radius }}">
|
||||
</div>
|
||||
|
||||
<label class="checkbox-label" for="t-dark">
|
||||
<input type="checkbox" id="t-dark" name="t-dark" {% if theme.dark %}checked{% endif %}>
|
||||
Enable dark mode
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- --- Raw custom CSS (single source of truth for custom_css) ------------- -->
|
||||
<div class="admin-panel">
|
||||
<h2>Custom CSS</h2>
|
||||
<p class="field-hint">The theme variables above are rendered here live; add any extra rules below them.</p>
|
||||
<div class="form-group">
|
||||
<label for="custom-css-editor">Custom CSS</label>
|
||||
<textarea id="custom-css-editor" rows="16" placeholder="body { background: #fff; }"></textarea>
|
||||
<input type="hidden" id="custom-css-hidden" name="custom_css" value="{{ custom_css }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- --- Header image ------------------------------------------------------ -->
|
||||
<div class="admin-panel">
|
||||
<h2>Header image</h2>
|
||||
<p class="field-hint">Upload a banner/header image for the top of every public page. Leave blank to remove it.</p>
|
||||
{% if header_image %}
|
||||
<div class="form-group">
|
||||
<label>Current header image</label>
|
||||
<img src="{{ header_image }}" alt="{{ site_title }}" style="max-height:90px;width:auto;border:1px solid var(--color-border);border-radius:6px;">
|
||||
<button type="submit" class="btn-danger" name="remove_header" value="1">Remove</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="form-group">
|
||||
<label for="header-image">Header image</label>
|
||||
<input type="file" id="header-image" name="header_image" accept="image/png,image/jpeg,image/gif,image/webp">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- --- Actions ------------------------------------------------------------ -->
|
||||
<div class="admin-panel">
|
||||
<button type="submit" class="btn-primary">Save all</button>
|
||||
<button type="button" id="reset-theme" class="btn-secondary">Reset theme to defaults</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Live preview of the themed site -->
|
||||
<div class="theme-preview-wrap">
|
||||
<h2>Live preview</h2>
|
||||
<p class="field-hint">This mini-site uses the exact variables you just set. Changes update as you tweak them.</p>
|
||||
<div id="theme-preview" class="theme-preview">
|
||||
<style id="theme-vars"></style>
|
||||
<header class="site-header" id="preview-header">
|
||||
<div class="header-inner">
|
||||
<div class="site-logo"><span id="preview-logo">{{ site_title }}</span></div>
|
||||
<nav class="main-nav" aria-label="preview nav">
|
||||
<button type="button" id="preview-menu">Menu</button>
|
||||
<ul class="nav-menu" id="preview-nav">
|
||||
<li><a href="#!">Dashboard</a></li>
|
||||
<li><a href="#!">Posts</a></li>
|
||||
<li><a href="#!">Categories</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
<main class="site-main" id="preview-main">
|
||||
<p class="page-heading"><a href="#!">{{ site_title }}</a></p>
|
||||
<section class="posts-grid" id="preview-posts">
|
||||
{% for _i in range(0, 6) %}
|
||||
<article class="post-card">
|
||||
<h2><a href="#!">I Spent weeks Fighting My Local AI Coding Agent — Here's Everything I Learned</a></h2>
|
||||
<p class="post-meta"><span>October 27, 2026 by brian</span></p>
|
||||
<div class="post-excerpt">
|
||||
<p>How I built a coding agent that runs entirely on my own hardware — no API, no cloud, no monthly bill — and the build steps that actually work. A while back I decided I wanted a coding agent I could leave running without paying for it.</p>
|
||||
<p>Something that …</p>
|
||||
</div>
|
||||
<div class="post-tags"><span class="tag-icon">📁</span><a class="tag" href="#!">ai</a><a class="tag" href="#!">emerging_technology</a><a class="tag" href="#!">thoughts</a></div>
|
||||
<div class="post-footer"><a href="#!" class="read-more">Read more →</a><a href="#!" class="comment-link">💬 Leave a comment</a></div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
/* --- Theme editor controls ------------------------------------------------- */
|
||||
.theme-editor { border: 1px solid var(--color-border); border-radius: 8px; padding: 20px 24px; }
|
||||
.swatch-row { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
|
||||
.swatch-row input[type="color"] { width: 56px; height: 40px; padding: 3px; border: 1px solid var(--color-border); border-radius: 6px; background: #fff; cursor: pointer; }
|
||||
.swatch-row .hex-input { flex: 1; padding: 11px 12px; border: 1px solid var(--color-border); border-radius: 5px; font-family: var(--font-stack); }
|
||||
.checkbox-label { display: flex; align-items: center; gap: 8px; margin: 16px 0 14px; font-size: 0.95rem; color: var(--color-text); }
|
||||
.checkbox-label input { width: auto; }
|
||||
|
||||
/* --- Live preview (mini site) ---------------------------------------------- */
|
||||
.theme-preview-wrap > h2 { margin-top: 0; }
|
||||
.theme-preview { border: 1px solid var(--color-border); border-radius: 8px; overflow: hidden; background: #fff; }
|
||||
.theme-preview .site-header { border-bottom-width: 2px; }
|
||||
@media (max-width: 620px) {
|
||||
.theme-preview .nav-menu { display: none !important; }
|
||||
}
|
||||
|
||||
/* --- Action buttons -------------------------------------------------------- */
|
||||
.admin-panel > .form-group:not(:last-of-type) button[type="submit"],
|
||||
.admin-panel > .form-group:not(:last-of-type) input[type="file"] { margin-bottom: 12px; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
|
||||
// Defaults match the built-in theme.css :root so a fresh site looks unchanged.
|
||||
var DEFAULTS = {
|
||||
accent: '#00a0d1', background: '#ffffff', text: '#1e1e1e',
|
||||
font: '"-apple-system", BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif',
|
||||
posts: 1, header: 'side', radius: 6, dark: false
|
||||
};
|
||||
|
||||
var state = {
|
||||
accent: document.getElementById('t-accent').value,
|
||||
background: document.getElementById('t-bg').value,
|
||||
text: document.getElementById('t-text').value,
|
||||
sidebar: document.getElementById('t-sidebar').value,
|
||||
font: document.getElementById('t-font').value,
|
||||
posts: document.getElementById('t-posts').value,
|
||||
header: document.getElementById('t-header').value,
|
||||
radius: document.getElementById('t-radius').value,
|
||||
dark: document.getElementById('t-dark').checked
|
||||
};
|
||||
|
||||
function toHex(col) {
|
||||
try { return getComputedStyle(document.documentElement || { style: function () {} }).getPropertyValue('color').trim(); } catch (e) {}
|
||||
var c = document.createElement('canvas').getContext('2d');
|
||||
c.fillStyle = col; return '#' + c.fillStyle.toString().slice(4);
|
||||
}
|
||||
|
||||
// Build the :root variable block + grid/header rules as a CSS string. This is
|
||||
// exactly what gets spliced into the raw-CSS textarea on submit (and reset), so
|
||||
// the textarea stays the single source of truth for custom_css.
|
||||
function buildTheme() {
|
||||
var light = [
|
||||
['--color-accent', state.accent],
|
||||
['--color-link', state.accent],
|
||||
['--color-link-hover', shade(state.accent, -18)],
|
||||
['--color-text', state.text],
|
||||
['--color-muted', lerpAlpha(state.text, 0.55)],
|
||||
['--color-border', lerpAlpha(state.text, 0.92)],
|
||||
['--color-bg', state.background],
|
||||
['--color-sidebar-bg', state.sidebar],
|
||||
['--color-card-bg', '#f7f8fa'],
|
||||
['--font-stack', state.font],
|
||||
['--border-radius', Math.round(Number(state.radius)) + 'px']
|
||||
];
|
||||
var dark = [
|
||||
['--color-accent', state.accent],
|
||||
['--color-link', state.accent],
|
||||
['--color-link-hover', shade(state.accent, -22)],
|
||||
['--color-text', state.text],
|
||||
['--color-muted', lerpAlpha(state.text, 0.55)],
|
||||
['--color-border', lerpAlpha(state.text, 0.92)],
|
||||
['--color-bg', state.background],
|
||||
['--color-sidebar-bg', state.sidebar],
|
||||
['--color-card-bg', 'rgba(255, 255, 255, 0.03)'],
|
||||
['--font-stack', state.font],
|
||||
['--border-radius', Math.round(Number(state.radius)) + 'px']
|
||||
];
|
||||
var vars = (state.dark ? dark : light).map(function (pair) { return pair.join(':') + ';'; }).join('\n ');
|
||||
var rules = [];
|
||||
var cols = Number(state.posts);
|
||||
rules.push('.posts-grid { grid-template-columns: repeat(' + cols + ', 1fr); }');
|
||||
rules.push('#preview-header { flex-direction: ' + (state.header === 'stacked' ? 'column' : 'row') + '; }');
|
||||
var out = ':root {\n' + vars + '\n}\n';
|
||||
if (rules.length) out += '\n' + rules.join('\n') + '\n';
|
||||
// Emit an explicit marker when dark mode is on. The old detection looked for
|
||||
// a literal #121212/#1c1c1c background, but buildTheme() writes --color-bg
|
||||
// from the chosen colour — so a custom dark background would silently lose
|
||||
// dark mode on reload. This marker is unambiguous and always present in dark.
|
||||
if (state.dark) out += '/* theme-dark */\n';
|
||||
return out;
|
||||
}
|
||||
|
||||
function renderVars() { document.getElementById('theme-vars').textContent = buildTheme(); }
|
||||
|
||||
// The hidden field is the single source of truth for custom_css. It always holds
|
||||
// the generated theme block (from buildTheme()) followed by whatever manual CSS the
|
||||
// user has typed in the editor. This avoids parsing/stripping the textarea on every
|
||||
// change — no risk of duplicating the grid rules, dark marker, or manual CSS.
|
||||
function setHidden() {
|
||||
var ta = document.getElementById('custom-css-editor');
|
||||
var hidden = document.getElementById('custom-css-hidden');
|
||||
hidden.value = buildTheme() + '\n\n' + (ta.value || '');
|
||||
}
|
||||
|
||||
// On load: the hidden field already holds the stored custom_css (from {{ custom_css }}).
|
||||
// Split it into the generated block + manual CSS and show only the manual CSS in the
|
||||
// editor. Any later change to a control or a keystroke rebuilds the hidden field.
|
||||
function loadEditor() {
|
||||
var ta = document.getElementById('custom-css-editor');
|
||||
var stored = document.getElementById('custom-css-hidden').value;
|
||||
var gen = buildTheme();
|
||||
var match = new RegExp('^' + gen.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).exec(stored);
|
||||
ta.value = match ? stored.slice(match[0].length) : stored;
|
||||
}
|
||||
|
||||
document.getElementById('custom-css-editor').addEventListener('input', function () {
|
||||
setHidden();
|
||||
});
|
||||
|
||||
// Apply the current state to the live preview DOM.
|
||||
function applyPreview() {
|
||||
var root = document.documentElement;
|
||||
root.style.setProperty('--color-accent', state.accent);
|
||||
root.style.setProperty('--color-link', state.accent);
|
||||
root.style.setProperty('--color-link-hover', shade(state.accent, -18));
|
||||
root.style.setProperty('--color-text', state.text);
|
||||
root.style.setProperty('--color-bg', state.background);
|
||||
root.style.setProperty('--font-stack', state.font);
|
||||
root.style.setProperty('--color-sidebar-bg', state.sidebar);
|
||||
|
||||
document.getElementById('preview-posts').style.gridTemplateColumns = 'repeat(' + state.posts + ', 1fr)';
|
||||
document.getElementById('preview-header').style.flexDirection = state.header === 'stacked' ? 'column' : 'row';
|
||||
document.getElementById('preview-header').style.alignItems = state.header === 'stacked' ? 'stretch' : 'center';
|
||||
var r = Math.round(Number(state.radius));
|
||||
['post-card', '.site-header', '#preview-logo'].forEach(function (sel) {
|
||||
var el = document.querySelector(sel);
|
||||
if (el) el.style.borderRadius = r + 'px';
|
||||
});
|
||||
|
||||
document.getElementById('theme-preview').classList.toggle('dark', state.dark);
|
||||
}
|
||||
|
||||
function shade(hex, pct) {
|
||||
var m = hex.replace('#', '');
|
||||
if (m.length === 3) m = m.split('').map(function (c) { return c + c; }).join('');
|
||||
var num = parseInt(m, 16);
|
||||
var r = Math.max(0, Math.min(255, ((num >> 16) & 255) + pct));
|
||||
var g = Math.max(0, Math.min(255, ((num >> 8) & 255) + pct));
|
||||
var b = Math.max(0, Math.min(255, (num & 255) + pct));
|
||||
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
||||
}
|
||||
|
||||
function lerpAlpha(hex, alpha) {
|
||||
var m = hex.replace('#', '');
|
||||
if (m.length === 3) m = m.split('').map(function (c) { return c + c; }).join('');
|
||||
var num = parseInt(m, 16);
|
||||
var r = (num >> 16) & 255, g = (num >> 8) & 255, b = num & 255;
|
||||
return 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')';
|
||||
}
|
||||
|
||||
function syncRadiusLabel() { document.getElementById('radius-val').textContent = state.radius + 'px'; }
|
||||
|
||||
function bindPair(pickerId, hexId) {
|
||||
var picker = document.getElementById(pickerId), hex = document.getElementById(hexId);
|
||||
picker.addEventListener('input', function () {
|
||||
state[pickerId.slice(2)] = picker.value;
|
||||
hex.value = picker.value;
|
||||
setHidden(); renderVars(); applyPreview();
|
||||
});
|
||||
hex.addEventListener('input', function () {
|
||||
var v = hex.value.trim().replace(/^#/, '');
|
||||
if (/^[\da-fA-F]{6}$/.test(v)) {
|
||||
state[pickerId.slice(2)] = '#' + v;
|
||||
picker.value = '#' + v;
|
||||
setHidden(); renderVars(); applyPreview();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function bind() {
|
||||
bindPair('t-accent', 't-accent-hex');
|
||||
bindPair('t-bg', 't-bg-hex');
|
||||
bindPair('t-text', 't-text-hex');
|
||||
bindPair('t-sidebar', 't-sidebar-hex');
|
||||
|
||||
['t-font', 't-posts', 't-header'].forEach(function (id) {
|
||||
document.getElementById(id).addEventListener('change', function () {
|
||||
state[id.slice(2)] = document.getElementById(id).value;
|
||||
setHidden(); renderVars(); applyPreview(); syncRadiusLabel();
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('t-radius').addEventListener('input', function () {
|
||||
state.radius = this.value;
|
||||
document.getElementById('radius-val').textContent = this.value + 'px';
|
||||
setHidden(); renderVars(); applyPreview();
|
||||
});
|
||||
|
||||
document.getElementById('t-dark').addEventListener('change', function () {
|
||||
state.dark = this.checked;
|
||||
setHidden(); renderVars(); applyPreview();
|
||||
});
|
||||
|
||||
// Reset theme controls (and the raw-CSS textarea's generated block) to defaults.
|
||||
document.getElementById('reset-theme').addEventListener('click', function () {
|
||||
var form = document.getElementById('appearance-form');
|
||||
var set = function (id, v) { var el = document.getElementById(id); if (el) el.value = v; };
|
||||
set('site-title', 'My Blog');
|
||||
set('site-tagline', 'Thoughts on tech, self-hosting and life.');
|
||||
set('t-accent', DEFAULTS.accent);
|
||||
set('t-bg', DEFAULTS.background);
|
||||
set('t-text', DEFAULTS.text);
|
||||
set('t-sidebar', DEFAULTS.sidebar);
|
||||
set('t-font', DEFAULTS.font);
|
||||
set('t-posts', DEFAULTS.posts);
|
||||
set('t-header', DEFAULTS.header);
|
||||
set('t-radius', DEFAULTS.radius);
|
||||
var dark = document.getElementById('t-dark'); if (dark) dark.checked = DEFAULTS.dark;
|
||||
// Clear any manual CSS the user typed, then rebuild the hidden field from defaults.
|
||||
document.getElementById('custom-css-editor').value = '';
|
||||
setHidden(); renderVars(); applyPreview();
|
||||
});
|
||||
}
|
||||
|
||||
bind();
|
||||
renderVars();
|
||||
loadEditor();
|
||||
applyPreview();
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,103 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
{# Routes that don't pass active_page (posts, comments, …) get their label
|
||||
from the endpoint, so every admin tab is named correctly. #}
|
||||
{% set page_label = (active_page or (request.endpoint or 'dashboard').rsplit('.', 1)[-1])|replace('_', ' ')|replace('-', ' ')|title %}
|
||||
<title>{{ page_label }} · {{ site_title }}</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/admin.css') }}">
|
||||
<!-- TinyMCE oxide skin (UI + content styles), served locally. -->
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='js/skins/ui/oxide/skin.min.css') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='js/skins/ui/oxide/content.min.css') }}">
|
||||
<!-- TinyMCE WYSIWYG editor (replaces the Quill/TipTap build). Loaded locally in <head>;
|
||||
it only initializes on pages containing a #body-editor element. Community edition,
|
||||
no license key → no tin.cloud validation; theme/skin assets are served from /static/js/. -->
|
||||
<!-- Absolute base is REQUIRED: this app is a subpath (/admin/*) and TinyMCE resolves its
|
||||
theme/skin assets against the document root, so a relative path would 404. An absolute
|
||||
base_url makes every asset resolve correctly regardless of subpath. Update host/port
|
||||
here if you ever redeploy elsewhere. -->
|
||||
{# Relative asset base (NOT absolute). Resolves against the PAGE origin, so tinymce assets
|
||||
follow whatever protocol/host loads the page — works behind reverse proxies (https://domain,
|
||||
http://IP, LAN host) without needing X-Forwarded-Proto or per-host edits. An absolute base
|
||||
would be forced to http(s) as Flask sees it internally and break Mixed Content on HTTPS. #}
|
||||
{# js_base has NO trailing slash; callers add the needed '/' themselves so paths stay clean #}
|
||||
{% set js_base = "/static/js" %}
|
||||
<script>
|
||||
window.tinyMCEPreInit = { base: '{{ js_base }}', suffix: '.min' };
|
||||
</script>
|
||||
<script src="{{ url_for('static', filename='js/tinymce.min.js') }}"></script>
|
||||
{% block head_extra %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<header class="admin-header">
|
||||
<div class="header-inner">
|
||||
<div class="site-logo"><a href="{{ url_for('admin.dashboard') }}">{{ site_title }}</a></div>
|
||||
<nav class="main-nav" aria-label="Admin navigation">
|
||||
<button type="button" aria-expanded="false" id="menuButton">Menu</button>
|
||||
<ul class="nav-menu" id="navMenu" role="menu">
|
||||
<li role="none"><a href="{{ url_for('admin.dashboard') }}" role="menuitem">Dashboard</a></li>
|
||||
<li role="none"><a href="{{ url_for('admin.posts') }}" role="menuitem">Posts</a></li>
|
||||
<li role="none"><a href="{{ url_for('admin.categories') }}" role="menuitem">Categories</a></li>
|
||||
<li role="none"><a href="{{ url_for('admin.albums') }}" role="menuitem">Albums</a></li>
|
||||
<li role="none"><a href="{{ url_for('admin.media_list') }}" role="menuitem">Media</a></li>
|
||||
<li role="none"><a href="{{ url_for('admin.comments') }}" role="menuitem">Comments{% if pending_comments %}<span class="nav-badge" title="{{ pending_comments }} awaiting moderation">{{ pending_comments }}</span>{% endif %}</a></li>
|
||||
<li role="none"><a href="{{ url_for('admin.analytics') }}" role="menuitem">Analytics</a></li>
|
||||
<li role="none"><a href="{{ url_for('admin.visitors') }}" role="menuitem">Visitors</a></li>
|
||||
<li role="none"><a href="{{ url_for('admin.import_export') }}" role="menuitem">Import/Export</a></li>
|
||||
<li role="none"><a href="{{ url_for('admin.admin_password') }}" role="menuitem">Password</a></li>
|
||||
<li role="none"><a href="{{ url_for('public.index') }}" role="menuitem">View site</a></li>
|
||||
<li role="none">
|
||||
<form method="post" action="{{ url_for('admin.admin_logout') }}" class="logout-form">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button type="submit" role="menuitem" class="link-button">Log out</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="admin-subnav">
|
||||
<a href="{{ url_for('admin.dashboard') }}" class="{% if active_page == 'dashboard' %}active{% endif %}">Dashboard</a>
|
||||
<a href="{{ url_for('admin.posts') }}" class="{% if active_page == 'posts' %}active{% endif %}">Posts</a>
|
||||
<a href="{{ url_for('admin.categories') }}" class="{% if active_page == 'categories' %}active{% endif %}">Categories</a>
|
||||
<a href="{{ url_for('admin.albums') }}" class="{% if active_page == 'albums' %}active{% endif %}">Albums</a>
|
||||
<a href="{{ url_for('admin.media_list') }}" class="{% if active_page == 'media' %}active{% endif %}">Media</a>
|
||||
<a href="{{ url_for('admin.comments') }}" class="{% if active_page == 'comments' %}active{% endif %}">Comments{% if pending_comments %}<span class="nav-badge">{{ pending_comments }}</span>{% endif %}</a>
|
||||
<a href="{{ url_for('admin.pages') }}" class="{% if active_page == 'pages' %}active{% endif %}">Pages</a>
|
||||
<a href="{{ url_for('admin.links') }}" class="{% if active_page == 'links' %}active{% endif %}">Links</a>
|
||||
<a href="{{ url_for('admin.appearance') }}" class="{% if active_page == 'appearance' %}active{% endif %}">Appearance</a>
|
||||
<a href="{{ url_for('admin.analytics') }}" class="{% if active_page == 'analytics' %}active{% endif %}">Analytics</a>
|
||||
<a href="{{ url_for('admin.visitors') }}" class="{% if active_page == 'visitors' %}active{% endif %}">Visitors</a>
|
||||
<a href="{{ url_for('admin.import_export') }}" class="{% if active_page == 'import-export' %}active{% endif %}">Import/Export</a>
|
||||
<a href="{{ url_for('admin.admin_password') }}" class="{% if active_page == 'password' %}active{% endif %}">Password</a>
|
||||
</div>
|
||||
|
||||
<div class="admin-wrap">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% for category, message in messages %}
|
||||
<div class="notice notice-{{ category }}">{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
{% block admin_content %}{% endblock %}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
var btn = document.getElementById("menuButton");
|
||||
var menu = document.getElementById("navMenu");
|
||||
if (btn && menu) {
|
||||
btn.addEventListener("click", function () {
|
||||
var open = menu.classList.toggle("open");
|
||||
btn.setAttribute("aria-expanded", String(open));
|
||||
});
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<!-- (Quill + turndown removed; TinyMCE is loaded in <head> and initializes
|
||||
only on pages containing a #body-editor element.) -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,51 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>Categories</h1>
|
||||
<div class="admin-actions">
|
||||
<a class="primary" href="{{ url_for('admin.category_new') }}">+ New category</a>
|
||||
</div>
|
||||
|
||||
{% if categories is not none %}
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr><th>Name</th><th>Slug</th><th style="width:120px;">Actions</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for slug, name in categories %}
|
||||
<tr class="category-row">
|
||||
<td>{{ name }}</td>
|
||||
<td><code>{{ slug }}</code></td>
|
||||
<td>
|
||||
{% if slug != 'general' %}
|
||||
<form method="post" action="{{ url_for('admin.category_delete', slug=slug) }}" style="display:inline;" onsubmit="return confirm('Delete this category?');">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button class="btn btn-danger" type="submit">Delete</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<span class="field-hint">Default — cannot be deleted</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="empty-state">No categories yet.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if categories is none %}
|
||||
<div class="admin-panel">
|
||||
<h2>Add a category</h2>
|
||||
<form method="post" action="{{ url_for('admin.category_new') }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<div class="form-group">
|
||||
<label for="name">Category name</label>
|
||||
<input type="text" id="name" name="name" placeholder="e.g. Technology" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Create category</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,99 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>Comments</h1>
|
||||
|
||||
<div class="comment-stats">
|
||||
<span class="term {% if counts.pending > 0 %}warn{% endif %}">{{ counts.pending }} pending</span>
|
||||
<span>{{ counts.approved }} approved</span>
|
||||
<span>{{ counts.rejected }} rejected</span>
|
||||
<span>{{ counts.spam }} spam</span>
|
||||
</div>
|
||||
|
||||
{% if comments or rejected or spam %}
|
||||
{% if comments %}
|
||||
<h2>Pending moderation</h2>
|
||||
<div class="comment-mod-list">
|
||||
{% for c in comments %}
|
||||
<div class="comment-block comment-pending">
|
||||
<div class="comment-meta">
|
||||
<span class="comment-author">{{ c.author }}</span>
|
||||
{% if c.email %}<span class="comment-email">{{ c.email }}</span>{% endif %}
|
||||
<time datetime="{{ c.created_at }}">{{ parse_date(c.created_at) }}</time>
|
||||
</div>
|
||||
<div class="comment-body">{{ render_markdown(c.body) }}</div>
|
||||
<div class="comment-actions">
|
||||
<form method="post" action="{{ url_for('admin.comment_approve', cid=c.id) }}" style="display:inline;">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button class="btn btn-sm btn-success" type="submit">Approve</button>
|
||||
</form>
|
||||
<form method="post" action="{{ url_for('admin.comment_reject', cid=c.id) }}" style="display:inline;">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button class="btn btn-sm" type="submit">Reject</button>
|
||||
</form>
|
||||
<form method="post" action="{{ url_for('admin.comment_spam', cid=c.id) }}" style="display:inline;">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button class="btn btn-sm btn-warning" type="submit">Spam</button>
|
||||
</form>
|
||||
<form method="post" action="{{ url_for('admin.comment_delete', cid=c.id) }}" style="display:inline;" onsubmit="return confirm('Delete this comment permanently?');">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button class="btn btn-sm btn-danger" type="submit">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if rejected %}
|
||||
<h2>Rejected comments</h2>
|
||||
<div class="comment-mod-list">
|
||||
{% for c in rejected %}
|
||||
<div class="comment-block comment-rejected">
|
||||
<div class="comment-meta">
|
||||
<span class="comment-author">{{ c.author }}</span>
|
||||
{% if c.email %}<span class="comment-email">{{ c.email }}</span>{% endif %}
|
||||
<time datetime="{{ c.created_at }}">{{ parse_date(c.created_at) }}</time>
|
||||
</div>
|
||||
<div class="comment-body">{{ render_markdown(c.body) }}</div>
|
||||
<div class="comment-actions">
|
||||
<form method="post" action="{{ url_for('admin.comment_unreject', cid=c.id) }}" style="display:inline;">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button class="btn btn-sm btn-success" type="submit">Un-reject</button>
|
||||
</form>
|
||||
<form method="post" action="{{ url_for('admin.comment_delete', cid=c.id) }}" style="display:inline;" onsubmit="return confirm('Delete this comment permanently?');">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button class="btn btn-sm btn-danger" type="submit">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if spam %}
|
||||
<h2>Spam comments</h2>
|
||||
<div class="comment-mod-list">
|
||||
{% for c in spam %}
|
||||
<div class="comment-block comment-spam">
|
||||
<div class="comment-meta">
|
||||
<span class="comment-author">{{ c.author }}</span>
|
||||
{% if c.email %}<span class="comment-email">{{ c.email }}</span>{% endif %}
|
||||
<time datetime="{{ c.created_at }}">{{ parse_date(c.created_at) }}</time>
|
||||
</div>
|
||||
<div class="comment-body">{{ render_markdown(c.body) }}</div>
|
||||
<div class="comment-actions">
|
||||
<form method="post" action="{{ url_for('admin.comment_delete', cid=c.id) }}" style="display:inline;" onsubmit="return confirm('Delete this comment permanently?');">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button class="btn btn-sm btn-danger" type="submit">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<p class="empty-state">No comments awaiting moderation.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,61 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>Dashboard</h1>
|
||||
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:20px;margin:24px 0;">
|
||||
<div class="admin-stat"><span class="num">{{ count }}</span><span class="label">Total posts</span></div>
|
||||
<div class="admin-stat"><span class="num">{{ published }}</span><span class="label">Published</span></div>
|
||||
<div class="admin-stat"><span class="num">{{ drafts }}</span><span class="label">Drafts</span></div>
|
||||
<a class="admin-stat" href="{{ url_for('admin.comments') }}" style="text-decoration:none;">
|
||||
<span class="num">{{ pending_comments }}</span><span class="label">Awaiting moderation</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Recent posts</h2>
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Status</th>
|
||||
<th>Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for p in posts[:5] %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('admin.post_edit', pid=p.id) }}">{{ p.title }}</a></td>
|
||||
<td>{% if p.status == 'published' %}<span class="term">Published</span>{% else %}Draft{% endif %}</td>
|
||||
<td>{{ parse_date(p.created_at) }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="3" class="empty-state">No posts yet.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Comments awaiting moderation</h2>
|
||||
{% if pending %}
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr><th>Author</th><th>Comment</th><th>Received</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for c in pending %}
|
||||
<tr>
|
||||
<td>{{ c.author }}</td>
|
||||
<td>{{ c.body[:120] }}{% if c.body|length > 120 %}…{% endif %}</td>
|
||||
<td>{{ parse_date(c.created_at) }}</td>
|
||||
<td><a class="btn" href="{{ url_for('admin.comments') }}">Review</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="empty-state">Nothing waiting for moderation.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,31 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>Import / Export</h1>
|
||||
<p class="muted">Move content to and from a WordPress site using the standard WXR (XML) format.</p>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Export this blog</h2>
|
||||
<p>Download everything as a <strong>.xml</strong> file that you can upload into a fresh WordPress site via its "Tools → Import → WordPress" screen. Posts, categories and comments are included; images are left as-is (see the note below).</p>
|
||||
<form id="export-form" method="post" action="{{ url_for('admin.import_export') }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<input type="hidden" name="export" value="1">
|
||||
<button type="submit" class="btn-primary">Download simple-blog-export.xml</button>
|
||||
</form>
|
||||
<p class="muted small">Note: images in the post HTML keep their original URLs, so re-upload them through WordPress's Media Library after importing, or pick the image-reupload option if you want this tool to pull them for you.</p>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Import from WordPress</h2>
|
||||
<p>Choose a WXR <strong>.xml</strong> file exported from a WordPress site. Published posts, their categories/tags, and comments are imported into Posts. Existing rows are never overwritten.</p>
|
||||
<form id="import-form" method="post" action="{{ url_for('admin.import_wxr_route') }}" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<div class="form-group">
|
||||
<label for="file">WXR file (.xml)</label>
|
||||
<input type="file" id="file" name="file" accept=".xml,application/xml">
|
||||
</div>
|
||||
<button type="submit" class="btn-primary">Import</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,53 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>Links</h1>
|
||||
<p class="field-hint">
|
||||
These appear in the “Links” panel in the site sidebar, in the order
|
||||
listed below. The panel stays hidden until at least one link is added.
|
||||
</p>
|
||||
|
||||
<form method="post" action="{{ url_for('admin.links') }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="link-label">Label</label>
|
||||
<input type="text" id="link-label" name="label" placeholder="GitHub" maxlength="80" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="link-url">URL</label>
|
||||
<input type="text" id="link-url" name="url" placeholder="https://github.com/you" maxlength="500" required>
|
||||
<span class="field-hint">A bare domain gets https:// added automatically.</span>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Add link</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Current links</h2>
|
||||
{% if links %}
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr><th>Label</th><th>URL</th><th style="width:120px;">Actions</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for link in links %}
|
||||
<tr>
|
||||
<td>{{ link.label }}</td>
|
||||
<td><a href="{{ link.url }}" target="_blank" rel="noopener noreferrer">{{ link.url }}</a></td>
|
||||
<td>
|
||||
<form method="post" action="{{ url_for('admin.link_delete', lid=link.id) }}" onsubmit="return confirm('Remove this link?');">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button type="submit" class="btn btn-danger btn-small">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="empty-state">No links yet — so the sidebar panel is currently hidden.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,124 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block title %}Media · {{ site_title }}{% endblock %}
|
||||
|
||||
{% block admin_content %}
|
||||
<h1>Media</h1>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Upload a photo</h2>
|
||||
<form id="media-upload-form" method="POST" action="{{ url_for('admin.upload') }}" enctype="multipart/form-data" class="stack">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<div class="form-group">
|
||||
<label for="media-photo-file">Photo file</label>
|
||||
<input type="file" id="media-photo-file" name="file" accept="image/*" multiple required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="media-photo-album">Add to album (optional)</label>
|
||||
<select id="media-photo-album" name="album">
|
||||
<option value="">— Leave ungrouped —</option>
|
||||
{% for a in albums %}
|
||||
<option value="{{ a.slug }}">{{ a.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Upload photo</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% if ungrouped %}
|
||||
<div class="admin-panel">
|
||||
<h2>Ungrouped photos ({{ ungrouped|length }})</h2>
|
||||
{% for m in ungrouped %}
|
||||
{{ _media_row(m, albums) }}
|
||||
{% else %}
|
||||
<p class="empty-state">No ungrouped photos.</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% for aid, rows in grouped.items() %}
|
||||
<div class="admin-panel">
|
||||
<h2>{{ album_names.get(aid, 'Album') }} ({{ rows|length }})</h2>
|
||||
{% for m in rows %}
|
||||
{{ _media_row(m, albums) }}
|
||||
{% else %}
|
||||
<p class="empty-state">No photos.</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="empty-state">No photos yet. Upload one from the Albums page or a post/page editor.</p>
|
||||
{% endfor %}
|
||||
|
||||
<script>
|
||||
// NOTE: one file per request, with FormData built from scratch. Cloning the
|
||||
// form (new FormData(form)) also re-sends the <input type="file"> parts, so
|
||||
// the server stored the selected photo twice.
|
||||
// NOTE: every upload is awaited before location.reload(). The old version
|
||||
// fired all the fetches and reloaded synchronously in the same tick, which
|
||||
// aborted the in-flight requests — the page came back with no new photos,
|
||||
// so uploads looked broken even though /admin/upload was healthy.
|
||||
(function () {
|
||||
var form = document.getElementById("media-upload-form");
|
||||
if (!form) return;
|
||||
form.addEventListener("submit", async function (e) {
|
||||
e.preventDefault();
|
||||
var fileInput = form.elements["media-photo-file"];
|
||||
var files = Array.prototype.slice.call(fileInput.files);
|
||||
if (!files.length) { alert("Choose one or more photos."); return; }
|
||||
var album = form.elements["media-photo-album"].value;
|
||||
var csrf = form.elements["csrf_token"].value;
|
||||
var btn = form.querySelector("button[type=submit]");
|
||||
btn.disabled = true;
|
||||
var ok = 0, failed = [];
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
btn.textContent = "Uploading " + (i + 1) + "/" + files.length + "...";
|
||||
var fd = new FormData();
|
||||
fd.append("csrf_token", csrf);
|
||||
if (album) fd.append("album", album);
|
||||
fd.append("file", files[i], files[i].name);
|
||||
try {
|
||||
var r = await fetch(form.action, { method: "POST", credentials: "same-origin", body: fd });
|
||||
if (!r.ok) throw new Error("HTTP " + r.status);
|
||||
await r.json();
|
||||
ok++;
|
||||
} catch (err) {
|
||||
failed.push(files[i].name + ": " + err.message);
|
||||
}
|
||||
}
|
||||
btn.disabled = false;
|
||||
btn.textContent = "Upload photo";
|
||||
if (failed.length) {
|
||||
alert(ok + " uploaded, " + failed.length + " failed:\n" + failed.join("\n"));
|
||||
} else {
|
||||
alert(ok + " photo" + (ok === 1 ? "" : "s") + " uploaded.");
|
||||
}
|
||||
location.reload();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% macro _media_row(m, albums) %}
|
||||
<div class="media-row">
|
||||
<img class="media-thumb" src="{{ m.thumb_url or m.url }}" data-src="{{ m.url }}" alt="" style="width:60px;height:60px;object-fit:cover;">
|
||||
<div class="media-info">
|
||||
<a href="{{ m.url }}" target="_blank" rel="noreferrer">{{ m.url }}</a>
|
||||
<small>{{ m.created_at or '' }}</small>
|
||||
</div>
|
||||
<div class="media-actions">
|
||||
<form method="POST" action="{{ url_for('admin.media_assign', mid=m.id) }}" style="display:inline;">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<select name="album_id" onchange="this.form.submit()">
|
||||
{% for a in albums %}
|
||||
<option value="{{ a.id }}">{{ a.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</form>
|
||||
<span class="field-hint">·</span>
|
||||
<form method="POST" action="{{ url_for('admin.media_remove', mid=m.id) }}" style="display:inline;" onsubmit="return confirm('Remove this photo permanently? The file will be deleted.');">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button class="btn btn-danger" type="submit">Remove</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
@@ -0,0 +1,84 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>{% if page %}Edit page{% else %}New page{% endif %}</h1>
|
||||
|
||||
<form method="post" action="{% if page %}{{ url_for('admin.page_edit', pid=page.id) }}{% else %}{{ url_for('admin.page_new') }}{% endif %}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="title">Title *</label>
|
||||
<input type="text" id="title" name="title" value="{{ (page or {}).get('title', '') if page else '' }}" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="slug">Slug</label>
|
||||
<input type="text" id="slug" name="slug" value="{{ (page or {}).get('slug', '') if page else '' }}" placeholder="auto-generated-from-title">
|
||||
<span class="field-hint">URL-friendly version of the title. Leave blank to auto-generate.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="published">Published</label>
|
||||
<input type="checkbox" id="published" name="published" {% if page %}checked{% endif %}>
|
||||
<span class="field-hint">{% if page %}Uncheck to hide this page from the navigation.{% else %}Live pages appear in the top nav.{% endif %}</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="content">Content <span class="field-hint">(Rich text editor — Markdown, links, images)</span></label>
|
||||
<!-- Hidden field holds the stored HTML. TinyMCE loads it into #page-editor
|
||||
on init and writes it back here on submit; the public pipeline passes
|
||||
stored HTML straight through (render_markdown/to_html detect it). -->
|
||||
<input type="hidden" id="content" name="content" value="{{ body_html|forceescape }}">
|
||||
<div id="page-editor" class="tinymce-editor"></div>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
<a class="btn" href="{{ url_for('admin.pages') }}">Cancel</a>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// TinyMCE: load stored HTML on init, write it back to #content on submit.
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var contentField = document.getElementById("content");
|
||||
try {
|
||||
tinymce.init({
|
||||
base_url: '{{ js_base }}',
|
||||
theme_url: '{{ js_base }}/themes/silver/theme.min.js',
|
||||
icons_url: '{{ js_base }}/icons/default/icons.min.js',
|
||||
model_url: '{{ js_base }}/models/dom/model.min.js',
|
||||
license_key: 'gpl',
|
||||
skin: 'oxide',
|
||||
content_css: '/static/js/skins/ui/oxide/content.min.css',
|
||||
selector: '#page-editor',
|
||||
init_instance_callback: function (editor) {
|
||||
editor.setContent(contentField ? contentField.value : '');
|
||||
},
|
||||
convert_urls: false,
|
||||
plugins: 'anchor autolink charmap codesample emoticons image link lists media searchreplace table visualblocks wordcount',
|
||||
toolbar: 'undo redo | blocks fontfamily fontsize | bold italic underline strikethrough | link image media table | align lineheight | numlist bullist indent outdent | emoticons charmap | removeformat',
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('[debug] page editor init FAILED:', e);
|
||||
}
|
||||
|
||||
// Write the WYSIWYG content back to the hidden #content field on submit.
|
||||
// A div-based editor does NOT save into a separate hidden field via its
|
||||
// default behaviour (TinyMCE would restore the div instead), so we must
|
||||
// bridge it explicitly — same pattern as post_edit.html's #body editor.
|
||||
// Same bug as post_edit.html: document.querySelector('form') returns the
|
||||
// logout form in the admin header, so the editor content was never copied
|
||||
// into #content and saved pages had an empty body.
|
||||
var form = contentField ? contentField.form : null;
|
||||
if (form) {
|
||||
form.addEventListener('submit', function () {
|
||||
var editor = tinymce.get('page-editor') || tinymce.activeEditor;
|
||||
if (editor && contentField) contentField.value = editor.getContent();
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,36 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<div class="page-head">
|
||||
<h1>Pages</h1>
|
||||
<a class="btn btn-primary" href="{{ url_for('admin.page_new') }}">New page</a>
|
||||
</div>
|
||||
|
||||
{% if pages is none %}
|
||||
<p class="empty-state">No pages yet. Create your first one.</p>
|
||||
{% else %}
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr><th>Title</th><th>Slug</th><th>Status</th><th>Order</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for p in pages %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('admin.page_edit', pid=p.id) }}">{{ p.title }}</a></td>
|
||||
<td><code>/p/{{ p.slug }}</code></td>
|
||||
<td>{% if p.published %}<span class="badge badge-live">Live</span>{% else %}<span class="badge badge-draft">Draft</span>{% endif %}</td>
|
||||
<td>{{ p.position }}</td>
|
||||
<td class="actions">
|
||||
<a class="btn btn-small" href="{{ url_for('admin.page_edit', pid=p.id) }}">Edit</a>
|
||||
<form method="post" action="{{ url_for('admin.page_delete', pid=p.id) }}" onsubmit="return confirm('Delete this page?');">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button type="submit" class="btn btn-danger btn-small">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,36 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel" style="max-width:520px;">
|
||||
<h1>Change password</h1>
|
||||
<p class="field-hint">
|
||||
The current password is required. Changing it signs out every other
|
||||
browser that is logged in; this session stays signed in.
|
||||
</p>
|
||||
<form method="post" action="{{ url_for('admin.admin_password') }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="current-password">Current password</label>
|
||||
<input type="password" id="current-password" name="current_password"
|
||||
autocomplete="current-password" maxlength="1024" required autofocus>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="new-password">New password</label>
|
||||
<input type="password" id="new-password" name="new_password"
|
||||
autocomplete="new-password" minlength="{{ min_length }}"
|
||||
maxlength="1024" required>
|
||||
<p class="field-hint">At least {{ min_length }} characters; well-known defaults are rejected.</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="confirm-password">Repeat new password</label>
|
||||
<input type="password" id="confirm-password" name="confirm_password"
|
||||
autocomplete="new-password" minlength="{{ min_length }}"
|
||||
maxlength="1024" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Update password</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,179 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>{% if post %}Edit post{% else %}New post{% endif %}</h1>
|
||||
<form method="post" action="{% if post %}{{ url_for('admin.post_edit', pid=post.id) }}{% else %}{{ url_for('admin.post_new') }}{% endif %}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="title">Title *</label>
|
||||
<input type="text" id="title" name="title" value="{{ (post or {}).get('title', '') if post else '' }}" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="slug">Slug</label>
|
||||
<input type="text" id="slug" name="slug" value="{{ (post or {}).get('slug', '') if post else '' }}" placeholder="auto-generated-from-title">
|
||||
<span class="field-hint">URL-friendly version of the title. Leave blank to auto-generate.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="author">Author</label>
|
||||
<input type="text" id="author" name="author" value="{{ (post or {}).get('author', 'editor') if post else '' }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="category">Category</label>
|
||||
<input type="text" id="category" name="category" value="{{ (post or {}).get('category', 'General') if post else '' }}" list="category-options">
|
||||
<datalist id="category-options">
|
||||
{% for slug, name in categories %}
|
||||
<option value="{{ name }}"></option>
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="excerpt">Excerpt</label>
|
||||
<input type="text" id="excerpt" name="excerpt" value="{{ (post or {}).get('excerpt', '') if post else '' }}" placeholder="Short summary shown on the homepage">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="tags">Tags</label>
|
||||
<input type="text" id="tags" name="tags" value="{{ (post or {}).get('tags', '') if post else '' }}" placeholder="ai, selfhost, tips">
|
||||
<span class="field-hint">Comma separated.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="body">Body <span class="field-hint">(Rich text editor)</span></label>
|
||||
<!-- Hidden field holds the stored HTML. TinyMCE loads it into #body-editor
|
||||
on init and writes it back here on submit; the public pipeline passes
|
||||
stored HTML straight through (render_markdown/to_html detect it). -->
|
||||
<!-- forceescape is REQUIRED: body_html is Markup, so Jinja would emit
|
||||
quotes unescaped and the first src="/..." would terminate the value
|
||||
attribute, truncating the stored body. -->
|
||||
<input type="hidden" id="body" name="body" value="{{ body_html|forceescape }}">
|
||||
<div id="body-editor" class="tinymce-editor"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="status">Status</label>
|
||||
<select id="status" name="status">
|
||||
<option value="published" {% if post and post.status == 'published' %}selected{% endif %}>Published</option>
|
||||
<option value="draft" {% if post and post.status == 'draft' %}selected{% endif %}>Draft</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="post_date">Post date</label>
|
||||
<input type="date" id="post_date" name="post_date"
|
||||
value="{{ post.created_at[:10] if post and post.created_at else request.form.get('post_date', '') }}">
|
||||
<span class="field-hint">Shown on the post and used for ordering and archive months. Pick an earlier date to backdate it; leave blank for today.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
{% if post %}<a class="btn" href="{{ preview_url(post) }}" target="_blank" rel="noreferrer">Preview</a>{% endif %}
|
||||
<a class="btn" href="{{ url_for('admin.posts') }}">Cancel</a>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// TinyMCE: load stored HTML on init, write it back to #body on submit,
|
||||
// and upload images to /admin/upload (multipart csrf_token form field).
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var bodyField = document.getElementById('body');
|
||||
console.log('[debug] editor init started; tinymce global defined:', !!(window.tinymce));
|
||||
try {
|
||||
tinymce.init({
|
||||
// Community edition — no license key → no tin.cloud validation, works on any domain.
|
||||
// Asset resolution uses TWO TinyMCE mechanisms (see static/tinymce.min.js):
|
||||
// * base_url → drives plugins/icons/skins/langs (built as baseURL + "/plugins/..." etc.)
|
||||
// * theme_url / model_url / icons_url → each asset's own URL, with a RELATIVE fallback
|
||||
// when unset. On this subpath app the fallback would resolve against /admin/ and 404,
|
||||
// so every non-base_url asset is given an explicit ABSOLUTE url.
|
||||
// js_base (defined in base.html from request.host) makes these match however the
|
||||
// app is reached — no hardcoded localhost, so it works on your LAN host too.
|
||||
base_url: '{{ js_base }}',
|
||||
theme_url: '{{ js_base }}/themes/silver/theme.min.js',
|
||||
icons_url: '{{ js_base }}/icons/default/icons.min.js',
|
||||
model_url: '{{ js_base }}/models/dom/model.min.js',
|
||||
// Community Edition — license_key: 'gpl' agrees to the open-source terms so the bundled
|
||||
// LicenseKeyManager plugin takes the 'use_gpl' path and does NOT request its own plugin
|
||||
// file (plugins/licensekeymanager/plugin.min.js), which we don't serve and which 404s.
|
||||
// NOTE: the config option is 'license_key' (underscore). TinyMCE does NOT read
|
||||
// camelCase 'licenseKey', so that value would be silently ignored and the editor would
|
||||
// be disabled. Free, works on ANY domain (no tiny.cloud validation, no Setup Partner bot).
|
||||
license_key: 'gpl',
|
||||
skin: 'oxide', // oxide SKIN provides BOTH the toolbar chrome AND content.min.css.
|
||||
// NOTE: do NOT pair silver theme here — the silver theme looks for its own
|
||||
// skins/content/silver/content.css (absent) and falls back to skins/content/default/...
|
||||
// which 404s. The oxide skin is self-contained, so no separate theme is needed.
|
||||
content_css: '/static/js/skins/ui/oxide/content.min.css',
|
||||
selector: '#body-editor',
|
||||
// NOTE: there is NO `initialData` option in TinyMCE (that's TipTap/
|
||||
// ProseMirror). It is silently ignored -> the editor always opened
|
||||
// empty, so editing an existing post showed no body. Set it explicitly
|
||||
// once the editor instance exists.
|
||||
init_instance_callback: function (editor) {
|
||||
editor.setContent(bodyField ? bodyField.value : '');
|
||||
},
|
||||
// Keep stored image URLs as written (/static/uploads/...). Without
|
||||
// this TinyMCE rewrites them relative to the CURRENT page (/admin/...),
|
||||
// so a body saved on the edit page stored '../../static/uploads/...'.
|
||||
convert_urls: false,
|
||||
plugins: 'anchor autolink charmap codesample emoticons image link lists media searchreplace table visualblocks wordcount',
|
||||
toolbar: 'undo redo | blocks fontfamily fontsize | bold italic underline strikethrough | link image media table | align lineheight | numlist bullist indent outdent | emoticons charmap | removeformat',
|
||||
// NOTE: TinyMCE 8 calls this as (blobInfo, progress) and awaits the
|
||||
// RETURNED PROMISE, which must resolve to the final URL string (or an
|
||||
// object with .url). The old v5 (blobInfo, success, failure) callback
|
||||
// form is gone: calling success(url) here hits the progress callback,
|
||||
// the promise resolves to undefined, and TinyMCE throws
|
||||
// "Cannot read properties of undefined (reading 'url')".
|
||||
images_upload_handler: function (blobInfo) {
|
||||
var f = blobInfo.blob();
|
||||
// NOTE: use the MIME SUBTYPE (index 1), not the category (index 0).
|
||||
// 'image/jpeg'.split('/')[0] === 'image' (matches no map key -> falls back to 'png'),
|
||||
// which labels a JPEG as .png and fails the server's PNG signature check (400).
|
||||
var type = (f.type || '').split('/')[1];
|
||||
var ext = { png: 'png', jpg: 'jpg', jpeg: 'jpg', gif: 'gif', webp: 'webp' }[type] || 'png';
|
||||
var fd = new FormData();
|
||||
fd.append('file', f, 'tiny-image.' + ext);
|
||||
var csrf = document.querySelector('[name="csrf_token"]');
|
||||
if (csrf) fd.append('csrf_token', csrf.value);
|
||||
return fetch('/admin/upload', { method: 'POST', body: fd })
|
||||
.then(function (r) {
|
||||
if (!r.ok) throw new Error('Upload failed: HTTP ' + r.status);
|
||||
return r.json();
|
||||
})
|
||||
.then(function (d) {
|
||||
if (!d || !d.url) throw new Error('Upload response had no url');
|
||||
return d.url;
|
||||
});
|
||||
},
|
||||
images_restricted_types: 'image/png,image/jpeg,image/gif,image/webp',
|
||||
});
|
||||
console.log('[debug] init returned; editors created:', tinymce.get().length, '| body-editor exists:', tinymce.get('body-editor') !== null);
|
||||
|
||||
// NOTE: bind to the editor's OWN form. document.querySelector('form')
|
||||
// returned the logout form in the admin header (first form in the DOM),
|
||||
// so this listener never ran for the post form: the editor's content was
|
||||
// never copied into #body and every NEW post saved an empty body.
|
||||
var form = bodyField ? bodyField.form : null;
|
||||
if (form) {
|
||||
form.addEventListener('submit', function () {
|
||||
// NOTE: tinymce.get() takes an ELEMENT ID, not a CSS selector.
|
||||
// tinymce.get('#body-editor') returns null -> .getContent() throws ->
|
||||
// the old silent catch left #body empty, so every save stored no body.
|
||||
var editor = tinymce.get('body-editor') || tinymce.activeEditor;
|
||||
if (editor && bodyField) bodyField.value = editor.getContent();
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[debug] editor init FAILED:', e);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,42 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>Posts</h1>
|
||||
<div class="admin-actions">
|
||||
<a class="primary" href="{{ url_for('admin.post_new') }}">+ New post</a>
|
||||
<a href="{{ url_for('admin.dashboard') }}">Dashboard</a>
|
||||
</div>
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Author</th>
|
||||
<th>Category</th>
|
||||
<th>Status</th>
|
||||
<th>Created</th>
|
||||
<th style="width:130px;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for p in posts %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('public.post', slug=p.slug) }}">{{ p.title }}</a></td>
|
||||
<td>{{ p.author }}</td>
|
||||
<td>{{ p.category }}</td>
|
||||
<td>{% if p.status == 'published' %}<span class="term">Published</span>{% else %}Draft{% endif %}</td>
|
||||
<td>{{ parse_date(p.created_at) }}</td>
|
||||
<td class="table-actions">
|
||||
<a class="btn" href="{{ url_for('admin.post_edit', pid=p.id) }}">Edit</a>
|
||||
<form method="post" action="{{ url_for('admin.post_delete', pid=p.id) }}" style="display:inline;" onsubmit="return confirm('Delete this post?');">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<button class="btn btn-danger" type="submit">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="6" class="empty-state">No posts. Create your first post to get started.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,38 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>Visitor history</h1>
|
||||
<table class="admin-table">
|
||||
<tbody>
|
||||
<tr><th>Visitor ID</th><td><code>{{ visitor.visitor_id }}</code></td></tr>
|
||||
<tr><th>Browser</th><td>{{ visitor.browser or "—" }}</td></tr>
|
||||
<tr><th>Operating system</th><td>{{ visitor.os or "—" }}</td></tr>
|
||||
<tr><th>Device</th><td>{{ visitor.device }}</td></tr>
|
||||
<tr><th>Location</th><td>{% if visitor.city or visitor.country %}{% if visitor.country_code %}<span class="location-flag">{{ visitor.country_code|country_flag }}</span> {% endif %}{{ visitor.city or "—" }}{% if visitor.region %}, {{ visitor.region }}{% endif %}{% if visitor.country %}, {{ visitor.country }}{% endif %}{% if visitor.latitude is not none %} <span class="muted">({{ "%.2f"|format(visitor.latitude) }}, {{ "%.2f"|format(visitor.longitude) }})</span>{% endif %}{% else %}—{% endif %}</td></tr>
|
||||
<tr><th>Source</th><td><span class="term">{{ visitor.source }}</span></td></tr>
|
||||
<tr><th>Referrer domain</th><td>{{ visitor.referrer_domain or "direct (no referrer)" }}</td></tr>
|
||||
<tr><th>Raw referrer</th><td>{{ visitor.referrer or "—" }}</td></tr>
|
||||
<tr><th>First seen</th><td>{{ parse_date(visitor.first_seen) }}</td></tr>
|
||||
<tr><th>Last seen</th><td>{{ parse_date(visitor.last_seen) }}</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel">
|
||||
<h2>Pages visited ({{ visits|length }})</h2>
|
||||
<table class="admin-table">
|
||||
<thead><tr><th>Page</th><th>Title</th><th>When</th></tr></thead>
|
||||
<tbody>
|
||||
{% for v in visits %}
|
||||
<tr>
|
||||
<td><code>{{ v.page_path }}</code></td>
|
||||
<td>{{ v.title or "(untitled)" }}</td>
|
||||
<td>{{ parse_date(v.timestamp) }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="3" class="empty-state">This visitor has not visited any page yet.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,86 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block admin_content %}
|
||||
<div class="admin-panel">
|
||||
<h1>Visitors</h1>
|
||||
<p class="muted">Every tracked visitor. Click a row to see the pages they visited.</p>
|
||||
<form method="get" action="{{ url_for('admin.visitors') }}" class="filter-form">
|
||||
<label>
|
||||
<span>Country</span>
|
||||
<select name="country" id="country-filter">
|
||||
<option value="">All countries</option>
|
||||
{% for c in countries %}
|
||||
<option value="{{ c.country_code }}" {% if c.country_code == selected_country %}selected{% endif %}>
|
||||
{{ c.country_code|country_flag }} {{ c.country }} ({{ c.c }})
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<span>City</span>
|
||||
<select name="city" id="city-filter">
|
||||
<option value="">All cities</option>
|
||||
{% for city in cities %}
|
||||
<option value="{{ city }}" {% if city == selected_city %}selected{% endif %}>{{ city }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
<noscript><button type="submit" class="btn">Filter</button></noscript>
|
||||
{% if selected_country or selected_city %}
|
||||
<a class="btn" href="{{ url_for('admin.visitors') }}">Clear filters</a>
|
||||
{% endif %}
|
||||
<span class="muted">{{ rows|length }} shown</span>
|
||||
</form>
|
||||
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Visitor ID</th>
|
||||
<th>Browser</th>
|
||||
<th>OS</th>
|
||||
<th>Device</th>
|
||||
<th>Location</th>
|
||||
<th>Source</th>
|
||||
<th>Referrer domain</th>
|
||||
<th>First seen</th>
|
||||
<th>Last seen</th>
|
||||
<th>Visits</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for r in rows %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('admin.visit_history', vid=r.visitor_id) }}"><code>{{ r.visitor_id }}</code></a></td>
|
||||
<td>{{ r.browser or "—" }}</td>
|
||||
<td>{{ r.os or "—" }}</td>
|
||||
<td>{{ r.device }}</td>
|
||||
<td>{% if r.city or r.country %}{% if r.country_code %}<span class="location-flag">{{ r.country_code|country_flag }}</span> {% endif %}{{ r.city or "—" }}{% if r.country %}<span class="muted">, {{ r.country }}</span>{% endif %}{% else %}—{% endif %}</td>
|
||||
<td><span class="term">{{ r.source }}</span></td>
|
||||
<td>{{ r.referrer_domain or "—" }}</td>
|
||||
<td>{{ parse_date(r.first_seen) }}</td>
|
||||
<td>{{ parse_date(r.last_seen) }}</td>
|
||||
<td>{{ r.visits }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="10" class="empty-state">No visitors match these filters.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
var country = document.getElementById("country-filter");
|
||||
var city = document.getElementById("city-filter");
|
||||
if (!country || !city) return;
|
||||
// Changing country resets the city, otherwise a city that no longer
|
||||
// belongs to the selection would keep filtering the table to zero rows.
|
||||
country.addEventListener("change", function () {
|
||||
city.value = "";
|
||||
country.form.submit();
|
||||
});
|
||||
city.addEventListener("change", function () {
|
||||
city.form.submit();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user