Initial commit: simpleblog

This commit is contained in:
2026-11-14 17:05:01 +00:00
commit 31c4580da4
91 changed files with 53494 additions and 0 deletions
+187
View File
@@ -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 "&mdash;" }}</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 %}