deanpowers commited on
Commit
4aa6fdf
Β·
1 Parent(s): 81b26de

Blog: public /blog pages + /admin/blog writing desk (Markdown in GCS, auto sitemap, Article JSON-LD)

Browse files
CHANGELOG.md CHANGED
@@ -30,6 +30,13 @@ All notable changes to Blind Monkeys. Format loosely follows
30
  and `/api/bot-pnl` return real data, `scan.blindmonkeys.org/summary` 200.
31
 
32
  ### Added
 
 
 
 
 
 
 
33
  - **Admin SOPs page** (`/admin/sops`, also answers to `/admin/SOPs` and
34
  `/admin/SOP's`) β€” admin-gated runbook page with an architecture quick map and
35
  collapsible steps. **SOP #1: Restore blindmonkeys.org from Google Cloud** β€”
 
30
  and `/api/bot-pnl` return real data, `scan.blindmonkeys.org/summary` 200.
31
 
32
  ### Added
33
+ - **Blog** β€” public articles at `/blog/` + `/blog/<slug>` with a writing desk at
34
+ `/admin/blog` (admin-gated; linked from the Admin home tools grid β€” no navbar
35
+ changes). Posts are Markdown, stored as `blog/<slug>.json` in the data bucket,
36
+ so publishing needs no redeploy. Published posts are appended to the sitemap
37
+ automatically (sitemap.xml is now generated dynamically), and post pages
38
+ carry Article JSON-LD + OpenGraph metadata for indexing. Draft/publish
39
+ toggle, edit, and delete via `/api/admin/blog/*` (admin-gated).
40
  - **Admin SOPs page** (`/admin/sops`, also answers to `/admin/SOPs` and
41
  `/admin/SOP's`) β€” admin-gated runbook page with an architecture quick map and
42
  collapsible steps. **SOP #1: Restore blindmonkeys.org from Google Cloud** β€”
local_app.py CHANGED
@@ -3,7 +3,9 @@ load_dotenv()
3
 
4
  import os
5
  import json
 
6
  import requests
 
7
  from flask import Flask, jsonify, send_file, request, send_from_directory, Response
8
  from flask_cors import CORS
9
  from datetime import datetime, timedelta, timezone
@@ -94,7 +96,7 @@ CORS(app, resources={r"/*": {"origins": "*"}})
94
  # most recent copy is served instead of a 502.
95
  import base64
96
  import hashlib
97
- from modules.storage import load_bytes, save_bytes
98
 
99
  PROXY_CACHE_TTL = 120 # seconds a fresh response is served as-is
100
  PROXY_CACHE_STALE = 6 * 3600 # max age served in-memory on upstream failure
@@ -298,12 +300,15 @@ PUBLIC_PATHS_EXACT = (
298
  '/contact',
299
  '/faq',
300
  '/faq/',
 
 
301
  '/api/contact',
302
  )
303
 
304
 
305
 
306
  PUBLIC_PATHS_PREFIX = (
 
307
  '/api/whoami',
308
  '/api/prices',
309
  '/api/bot-history',
@@ -1936,7 +1941,134 @@ def robots_txt():
1936
 
1937
  @app.route('/sitemap.xml')
1938
  def sitemap_xml():
1939
- return send_from_directory('static', 'sitemap.xml', mimetype='application/xml')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1940
 
1941
  @app.route('/llms.txt')
1942
  def llms_txt():
 
3
 
4
  import os
5
  import json
6
+ import re
7
  import requests
8
+ import markdown as _markdown
9
  from flask import Flask, jsonify, send_file, request, send_from_directory, Response
10
  from flask_cors import CORS
11
  from datetime import datetime, timedelta, timezone
 
96
  # most recent copy is served instead of a 502.
97
  import base64
98
  import hashlib
99
+ from modules.storage import load_bytes, save_bytes, load_json, save_json, delete_bytes, list_prefix
100
 
101
  PROXY_CACHE_TTL = 120 # seconds a fresh response is served as-is
102
  PROXY_CACHE_STALE = 6 * 3600 # max age served in-memory on upstream failure
 
300
  '/contact',
301
  '/faq',
302
  '/faq/',
303
+ '/blog',
304
+ '/blog/',
305
  '/api/contact',
306
  )
307
 
308
 
309
 
310
  PUBLIC_PATHS_PREFIX = (
311
+ '/blog/',
312
  '/api/whoami',
313
  '/api/prices',
314
  '/api/bot-history',
 
1941
 
1942
  @app.route('/sitemap.xml')
1943
  def sitemap_xml():
1944
+ """Static sitemap plus live blog post URLs (kept in sync with /admin/blog)."""
1945
+ try:
1946
+ with open(os.path.join('static', 'sitemap.xml'), encoding='utf-8') as f:
1947
+ xml = f.read()
1948
+ except Exception:
1949
+ xml = ('<?xml version="1.0" encoding="UTF-8"?>'
1950
+ '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>')
1951
+ if '</urlset>' not in xml:
1952
+ xml += '</urlset>'
1953
+ extra = [' <url><loc>https://blindmonkeys.org/blog/</loc><priority>0.7</priority></url>']
1954
+ for p in _blog_posts(published_only=True):
1955
+ loc = 'https://blindmonkeys.org/blog/' + str(p.get('slug') or '')
1956
+ extra.append(' <url><loc>' + loc + '</loc><priority>0.6</priority></url>')
1957
+ xml = xml.replace('</urlset>', '\n' + '\n'.join(extra) + '\n</urlset>')
1958
+ return Response(xml, mimetype='application/xml')
1959
+
1960
+
1961
+ # ===================================================================
1962
+ # Blog β€” public posts (written via /admin/blog, stored in the data bucket)
1963
+ # ===================================================================
1964
+ BLOG_PREFIX = 'blog/'
1965
+
1966
+
1967
+ def _blog_slug_ok(slug):
1968
+ """Slugs are lowercase letters/digits/hyphens, 1-80 chars."""
1969
+ return bool(re.match(r'^[a-z0-9-]{1,80}$', slug or ''))
1970
+
1971
+
1972
+ def _blog_posts(published_only=False):
1973
+ """All blog posts, newest first. Each post is blog/<slug>.json in the
1974
+ data bucket: {slug, title, summary, date, published, body(markdown)}."""
1975
+ posts = []
1976
+ for name in list_prefix(BLOG_PREFIX):
1977
+ if not name.endswith('.json'):
1978
+ continue
1979
+ p = load_json(name, default=None)
1980
+ if not isinstance(p, dict):
1981
+ continue
1982
+ p.setdefault('slug', name[len(BLOG_PREFIX):-len('.json')])
1983
+ posts.append(p)
1984
+ posts.sort(key=lambda p: str(p.get('date') or ''), reverse=True)
1985
+ if published_only:
1986
+ posts = [p for p in posts if p.get('published')]
1987
+ return posts
1988
+
1989
+
1990
+ @app.route('/blog')
1991
+ @app.route('/blog/')
1992
+ def blog_index_page():
1993
+ posts = _blog_posts(published_only=True)
1994
+ return render_template('blog_index.html', posts=posts)
1995
+
1996
+
1997
+ @app.route('/blog/<slug>')
1998
+ def blog_post_page(slug):
1999
+ slug = (slug or '').lower().strip()
2000
+ if not _blog_slug_ok(slug):
2001
+ return render_template('blog_post.html', post=None, body_html=None), 404
2002
+ p = load_json(BLOG_PREFIX + slug + '.json', default=None)
2003
+ if not p or not p.get('published'):
2004
+ return render_template('blog_post.html', post=None, body_html=None), 404
2005
+ body_html = _markdown.markdown(
2006
+ str(p.get('body') or ''), extensions=['fenced_code', 'tables'])
2007
+ return render_template('blog_post.html', post=p, body_html=body_html)
2008
+
2009
+
2010
+ @app.route('/admin/blog')
2011
+ def admin_blog_page():
2012
+ u = current_user()
2013
+ if not u or u.get('role') != 'admin':
2014
+ return redirect('/login?next=/admin/blog'), 302
2015
+ return render_template('admin_blog.html')
2016
+
2017
+
2018
+ def _blog_admin_gate():
2019
+ u = current_user()
2020
+ if not u or u.get('role') != 'admin':
2021
+ return jsonify({'error': 'login required'}), 401
2022
+ return None
2023
+
2024
+
2025
+ @app.route('/api/admin/blog/list')
2026
+ def api_blog_list():
2027
+ g = _blog_admin_gate()
2028
+ if g:
2029
+ return g
2030
+ posts = _blog_posts()
2031
+ for p in posts:
2032
+ p['body'] = str(p.get('body') or '')
2033
+ return jsonify({'posts': posts})
2034
+
2035
+
2036
+ @app.route('/api/admin/blog/save', methods=['POST'])
2037
+ def api_blog_save():
2038
+ g = _blog_admin_gate()
2039
+ if g:
2040
+ return g
2041
+ d = request.get_json(silent=True) or {}
2042
+ slug = str(d.get('slug') or '').lower().strip()
2043
+ title = str(d.get('title') or '').strip()
2044
+ body = str(d.get('body') or '')
2045
+ if not title or not body.strip():
2046
+ return jsonify({'error': 'title and body are required'}), 400
2047
+ if not _blog_slug_ok(slug):
2048
+ return jsonify({'error': 'slug must be lowercase letters, digits, and hyphens (1-80 chars)'}), 400
2049
+ post = {
2050
+ 'slug': slug,
2051
+ 'title': title,
2052
+ 'summary': str(d.get('summary') or '').strip(),
2053
+ 'date': str(d.get('date') or datetime.now(timezone.utc).date().isoformat()),
2054
+ 'published': bool(d.get('published')),
2055
+ 'body': body,
2056
+ }
2057
+ save_json(BLOG_PREFIX + slug + '.json', post)
2058
+ return jsonify({'status': 'ok', 'post': post})
2059
+
2060
+
2061
+ @app.route('/api/admin/blog/delete', methods=['POST'])
2062
+ def api_blog_delete():
2063
+ g = _blog_admin_gate()
2064
+ if g:
2065
+ return g
2066
+ d = request.get_json(silent=True) or {}
2067
+ slug = str(d.get('slug') or '').lower().strip()
2068
+ if not _blog_slug_ok(slug):
2069
+ return jsonify({'error': 'bad slug'}), 400
2070
+ ok = delete_bytes(BLOG_PREFIX + slug + '.json')
2071
+ return jsonify({'status': 'ok' if ok else 'not-found'})
2072
 
2073
  @app.route('/llms.txt')
2074
  def llms_txt():
modules/storage.py CHANGED
@@ -123,3 +123,42 @@ def append_text(name, line):
123
  """Append a line to a text file (reads, appends, writes back)."""
124
  existing = load_text(name, "")
125
  return save_text(name, existing + line)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  """Append a line to a text file (reads, appends, writes back)."""
124
  existing = load_text(name, "")
125
  return save_text(name, existing + line)
126
+
127
+
128
+ def delete_bytes(name):
129
+ """Delete file/blob `name`. Returns True on success."""
130
+ name = _normalize(name)
131
+ if _is_gcs():
132
+ try:
133
+ _get_bucket().blob(name).delete()
134
+ return True
135
+ except Exception as e:
136
+ print("STORAGE delete failed for " + name + ": " + str(e))
137
+ return False
138
+ else:
139
+ try:
140
+ if os.path.isfile(name):
141
+ os.remove(name)
142
+ return True
143
+ except Exception as e:
144
+ print("STORAGE delete failed for " + name + ": " + str(e))
145
+ return False
146
+
147
+
148
+ def list_prefix(prefix):
149
+ """Return all object names under `prefix` (GCS blobs or local files)."""
150
+ prefix = _normalize(prefix)
151
+ if _is_gcs():
152
+ try:
153
+ return [b.name for b in _get_bucket().list_blobs(prefix=prefix)]
154
+ except Exception as e:
155
+ print("STORAGE list failed for " + prefix + ": " + str(e))
156
+ return []
157
+ try:
158
+ out = []
159
+ for root, _dirs, files in os.walk(prefix):
160
+ for f in files:
161
+ out.append(os.path.join(root, f).replace(os.sep, "/"))
162
+ return out
163
+ except Exception:
164
+ return []
requirements.txt CHANGED
@@ -6,3 +6,4 @@ requests==2.32.5
6
  gunicorn==23.0.0
7
  google-cloud-storage==2.18.2
8
  google-cloud-scheduler>=2.13.0
 
 
6
  gunicorn==23.0.0
7
  google-cloud-storage==2.18.2
8
  google-cloud-scheduler>=2.13.0
9
+ Markdown>=3.6
templates/admin_blog.html ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Blog β€” Admin</title>
7
+ <link rel="stylesheet" href="/css/nav.css?v=4">
8
+ <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
9
+ <style>
10
+ * { box-sizing: border-box; }
11
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; margin: 0; }
12
+ .page-content { max-width: 900px; margin: 0 auto; padding: 32px 20px; }
13
+ h1 { font-size: 24px; margin: 0 0 4px; }
14
+ .sub { color: #8b949e; font-size: 14px; margin-bottom: 24px; }
15
+ h2 { font-size: 14px; color: #f0b90b; margin: 0 0 16px; letter-spacing: 1px; text-transform: uppercase; }
16
+ .card { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 20px; margin-bottom: 20px; }
17
+ .field { margin-bottom: 14px; }
18
+ .field label { display: block; color: #8b949e; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
19
+ .field input, .field textarea { width: 100%; padding: 9px 12px; border-radius: 6px; border: 1px solid #30363d; background: #0d1117; color: #e6edf3; font-size: 13px; font-family: inherit; }
20
+ .field input:focus, .field textarea:focus { outline: none; border-color: #f0b90b; }
21
+ .field textarea { font-family: 'SF Mono', Monaco, monospace; font-size: 12.5px; line-height: 1.6; resize: vertical; }
22
+ .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
23
+ .row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 14px; }
24
+ .btn { padding: 10px 20px; border-radius: 8px; font-size: 13px; font-weight: 700; cursor: pointer; border: 1px solid #30363d; background: transparent; color: #8b949e; font-family: inherit; margin-right: 8px; }
25
+ .btn:hover { border-color: #f0b90b; color: #f0b90b; }
26
+ .btn-primary { background: #f0b90b; border: none; color: #0b0e11; }
27
+ .btn-primary:hover { background: #ffca28; color: #0b0e11; }
28
+ .btn-danger:hover { border-color: #f87171; color: #f87171; }
29
+ table { width: 100%; border-collapse: collapse; }
30
+ th { text-align: left; padding: 10px 8px; color: #8b949e; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid #30363d; }
31
+ td { padding: 12px 8px; border-bottom: 1px solid #21262d; font-size: 13px; vertical-align: middle; }
32
+ tr:last-child td { border-bottom: none; }
33
+ .badge { display: inline-block; padding: 3px 10px; border-radius: 6px; font-size: 10px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; }
34
+ .badge-published { background: #1a3a1a; color: #4ade80; border: 1px solid #4ade80; }
35
+ .badge-draft { background: #3a2a1a; color: #f0b90b; border: 1px solid #f0b90b; }
36
+ .mono { font-family: 'SF Mono', Monaco, monospace; font-size: 12px; color: #8b949e; }
37
+ .link { color: #58a6ff; text-decoration: none; }
38
+ .link:hover { color: #f0b90b; }
39
+ .empty { color: #8b949e; font-size: 14px; padding: 16px 0; text-align: center; }
40
+ .err { color: #f87171; font-size: 12.5px; margin-top: 10px; display: none; }
41
+ .err.show { display: block; }
42
+ .ok-msg { color: #4ade80; font-size: 12.5px; margin-top: 10px; display: none; }
43
+ .ok-msg.show { display: block; }
44
+ .hint { color: #484f58; font-size: 11px; margin-top: 4px; }
45
+ .checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
46
+ .checkbox-row input { width: 16px; height: 16px; }
47
+ .checkbox-row label { color: #c9d1d9; font-size: 13px; text-transform: none; letter-spacing: 0; margin: 0; }
48
+ </style>
49
+ </head>
50
+ <body>
51
+ <nav class="nav-bar">
52
+ <div class="nav-brand">πŸ™ˆ Blind Monkeys</div>
53
+ <div class="nav-links">
54
+ <a href="/admin" class="nav-link">πŸ› οΈ Admin</a>
55
+ <a href="/" class="nav-link">🏠 Home</a>
56
+ </div>
57
+ </nav>
58
+
59
+ <div class="page-content">
60
+ <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">β€Ί</span><a href="/admin">Admin</a><span class="bc-sep">β€Ί</span><span class="bc-current">Blog</span></div>
61
+ <h1>πŸ“ Blog</h1>
62
+ <div class="sub">Write and publish articles. Published posts appear at <span class="mono">/blog/</span> (public, indexed) and are added to the sitemap automatically.</div>
63
+
64
+ <div class="card">
65
+ <h2 id="form-title">New Post</h2>
66
+ <div class="row3">
67
+ <div class="field">
68
+ <label>Title</label>
69
+ <input id="f-title" placeholder="Why I publish my trading bot's results publicly">
70
+ </div>
71
+ <div class="field">
72
+ <label>Slug</label>
73
+ <input id="f-slug" placeholder="auto-from-title" class="mono">
74
+ <div class="hint">URL: /blog/&lt;slug&gt; β€” lowercase, digits, hyphens</div>
75
+ </div>
76
+ <div class="field">
77
+ <label>Date</label>
78
+ <input id="f-date" type="date">
79
+ </div>
80
+ </div>
81
+ <div class="field">
82
+ <label>Summary (meta description β€” 1 or 2 sentences)</label>
83
+ <input id="f-summary" placeholder="What the reader will learn from this post.">
84
+ </div>
85
+ <div class="field">
86
+ <label>Body (Markdown)</label>
87
+ <textarea id="f-body" rows="18" placeholder="# Heading&#10;&#10;Write in **Markdown**. Supports `code`, fenced code blocks, tables, lists, and blockquotes."></textarea>
88
+ </div>
89
+ <div class="checkbox-row">
90
+ <input type="checkbox" id="f-published">
91
+ <label for="f-published">Published (visible on /blog/ and in the sitemap)</label>
92
+ </div>
93
+ <div style="margin-top:18px;">
94
+ <button class="btn btn-primary" id="btn-save">Save</button>
95
+ <button class="btn" id="btn-new">New Post</button>
96
+ <button class="btn btn-danger" id="btn-delete" style="display:none;">Delete</button>
97
+ </div>
98
+ <div class="err" id="err"></div>
99
+ <div class="ok-msg" id="okmsg"></div>
100
+ </div>
101
+
102
+ <div class="card">
103
+ <h2>Posts</h2>
104
+ <div id="posts-wrap"><div class="empty">Loading…</div></div>
105
+ </div>
106
+ </div>
107
+
108
+ <script>
109
+ var editing = null;
110
+ function $(id) { return document.getElementById(id); }
111
+ function slugify(s) {
112
+ return s.toLowerCase().trim()
113
+ .replace(/[^a-z0-9\s-]/g, '')
114
+ .replace(/[\s_]+/g, '-')
115
+ .replace(/-+/g, '-')
116
+ .slice(0, 80);
117
+ }
118
+ function setMsg(ok, text) {
119
+ var e = $('err'), m = $('okmsg');
120
+ e.classList.remove('show'); m.classList.remove('show');
121
+ if (ok) { m.textContent = text; m.classList.add('show'); }
122
+ else { e.textContent = text; e.classList.add('show'); }
123
+ setTimeout(function () { e.classList.remove('show'); m.classList.remove('show'); }, 4000);
124
+ }
125
+ function loadList() {
126
+ fetch('/api/admin/blog/list').then(function (r) { return r.json(); }).then(function (d) {
127
+ var wrap = $('posts-wrap');
128
+ var posts = d.posts || [];
129
+ if (!posts.length) { wrap.innerHTML = '<div class="empty">No posts yet.</div>'; return; }
130
+ var html = '<table><thead><tr><th>Title</th><th>Slug</th><th>Date</th><th>Status</th><th></th></tr></thead><tbody>';
131
+ posts.forEach(function (p) {
132
+ html += '<tr>'
133
+ + '<td style="font-weight:700;">' + escapeHtml(p.title) + '</td>'
134
+ + '<td class="mono">' + escapeHtml(p.slug) + '</td>'
135
+ + '<td class="mono">' + escapeHtml(p.date || '') + '</td>'
136
+ + '<td>' + (p.published ? '<span class="badge badge-published">Published</span>' : '<span class="badge badge-draft">Draft</span>') + '</td>'
137
+ + '<td style="text-align:right;">'
138
+ + '<button class="btn" onclick="editPost(\'' + p.slug + '\')">Edit</button>'
139
+ + (p.published ? ' <a class="link" href="/blog/' + p.slug + '" target="_blank" rel="noopener">view</a>' : '')
140
+ + '</td></tr>';
141
+ });
142
+ wrap.innerHTML = html + '</tbody></table>';
143
+ window._posts = posts;
144
+ }).catch(function () { $('posts-wrap').innerHTML = '<div class="empty">Could not load posts.</div>'; });
145
+ }
146
+ function escapeHtml(s) {
147
+ return String(s || '').replace(/[&<>"']/g, function (c) {
148
+ return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c];
149
+ });
150
+ }
151
+ function editPost(slug) {
152
+ var p = (window._posts || []).find(function (x) { return x.slug === slug; });
153
+ if (!p) return;
154
+ editing = slug;
155
+ $('form-title').textContent = 'Edit Post';
156
+ $('f-title').value = p.title || '';
157
+ $('f-slug').value = p.slug || '';
158
+ $('f-date').value = p.date || '';
159
+ $('f-summary').value = p.summary || '';
160
+ $('f-body').value = p.body || '';
161
+ $('f-published').checked = !!p.published;
162
+ $('btn-delete').style.display = '';
163
+ window.scrollTo({ top: 0, behavior: 'smooth' });
164
+ }
165
+ function resetForm() {
166
+ editing = null;
167
+ $('form-title').textContent = 'New Post';
168
+ ['f-title', 'f-slug', 'f-summary', 'f-body'].forEach(function (id) { $(id).value = ''; });
169
+ $('f-date').value = new Date().toISOString().slice(0, 10);
170
+ $('f-published').checked = false;
171
+ $('btn-delete').style.display = 'none';
172
+ setMsg(true, '');
173
+ }
174
+ $('f-title').addEventListener('input', function () {
175
+ if (!editing) $('f-slug').value = slugify(this.value);
176
+ });
177
+ $('btn-save').addEventListener('click', function () {
178
+ var payload = {
179
+ slug: slugify($('f-slug').value || $('f-title').value),
180
+ title: $('f-title').value.trim(),
181
+ date: $('f-date').value,
182
+ summary: $('f-summary').value.trim(),
183
+ body: $('f-body').value,
184
+ published: $('f-published').checked
185
+ };
186
+ fetch('/api/admin/blog/save', {
187
+ method: 'POST',
188
+ headers: { 'Content-Type': 'application/json' },
189
+ body: JSON.stringify(payload)
190
+ }).then(function (r) { return r.json(); }).then(function (d) {
191
+ if (d.status === 'ok') {
192
+ setMsg(true, 'Saved β€” ' + (payload.published ? 'live at /blog/' + payload.slug : 'saved as draft'));
193
+ editing = payload.slug;
194
+ $('form-title').textContent = 'Edit Post';
195
+ $('btn-delete').style.display = '';
196
+ loadList();
197
+ } else {
198
+ setMsg(false, d.error || 'Save failed');
199
+ }
200
+ }).catch(function () { setMsg(false, 'Save failed β€” network error'); });
201
+ });
202
+ $('btn-new').addEventListener('click', resetForm);
203
+ $('btn-delete').addEventListener('click', function () {
204
+ if (!editing) return;
205
+ if (!confirm('Delete post "' + editing + '"? This cannot be undone.')) return;
206
+ fetch('/api/admin/blog/delete', {
207
+ method: 'POST',
208
+ headers: { 'Content-Type': 'application/json' },
209
+ body: JSON.stringify({ slug: editing })
210
+ }).then(function (r) { return r.json(); }).then(function (d) {
211
+ if (d.status === 'ok') { resetForm(); setMsg(true, 'Deleted'); loadList(); }
212
+ else setMsg(false, d.error || 'Delete failed');
213
+ });
214
+ });
215
+ resetForm();
216
+ loadList();
217
+ </script>
218
+ </body>
219
+ </html>
templates/admin_home.html CHANGED
@@ -38,6 +38,7 @@
38
  <a class="tool" href="/admin/alerts"><div class="ico">πŸ””</div><div class="t">Coin Alerts</div><div class="d">Manage price and event alert rules.</div></a>
39
  <a class="tool" href="/admin/users"><div class="ico">πŸ‘₯</div><div class="t">Users</div><div class="d">Approve registrations, manage roles and accounts.</div></a>
40
  <a class="tool" href="/admin/sops"><div class="ico">πŸ“‹</div><div class="t">SOPs</div><div class="d">Runbooks: restore the site, roll back deploys, recover bucket data.</div></a>
 
41
  </div>
42
  </div>
43
  <script src="/css/nav.js?v=14"></script>
 
38
  <a class="tool" href="/admin/alerts"><div class="ico">πŸ””</div><div class="t">Coin Alerts</div><div class="d">Manage price and event alert rules.</div></a>
39
  <a class="tool" href="/admin/users"><div class="ico">πŸ‘₯</div><div class="t">Users</div><div class="d">Approve registrations, manage roles and accounts.</div></a>
40
  <a class="tool" href="/admin/sops"><div class="ico">πŸ“‹</div><div class="t">SOPs</div><div class="d">Runbooks: restore the site, roll back deploys, recover bucket data.</div></a>
41
+ <a class="tool" href="/admin/blog"><div class="ico">πŸ“</div><div class="t">Blog</div><div class="d">Write and publish articles at /blog (public, indexed, in the sitemap).</div></a>
42
  </div>
43
  </div>
44
  <script src="/css/nav.js?v=14"></script>
templates/blog_index.html ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Blog β€” Blind Monkeys</title>
7
+ <meta name="description" content="Essays and engineering notes from building Blind Monkeys: transparent crypto scanning, automated trading, and running production systems on Google Cloud.">
8
+ <link rel="stylesheet" href="/css/nav.css?v=4">
9
+ <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
10
+ <style>
11
+ * { box-sizing: border-box; }
12
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; margin: 0; }
13
+ .page-content { max-width: 760px; margin: 0 auto; padding: 32px 20px; }
14
+ h1 { font-size: 26px; margin: 0 0 6px; }
15
+ .tagline { color: #8b949e; font-size: 14.5px; margin: 0 0 28px; }
16
+ .post { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 20px 22px; margin-bottom: 16px; }
17
+ .post h2 { margin: 0 0 6px; font-size: 19px; line-height: 1.35; }
18
+ .post h2 a { color: #e6edf3; text-decoration: none; }
19
+ .post h2 a:hover { color: #f0b90b; }
20
+ .post .date { color: #8b949e; font-size: 12.5px; margin-bottom: 8px; font-family: 'SF Mono', Monaco, monospace; }
21
+ .post p { color: #c9d1d9; font-size: 14px; line-height: 1.65; margin: 0; }
22
+ .empty { color: #8b949e; text-align: center; padding: 48px 0; font-size: 15px; }
23
+ .breadcrumbs { font-size: 12.5px; margin-bottom: 18px; }
24
+ .breadcrumbs a { color: #8b949e; text-decoration: none; }
25
+ .breadcrumbs a:hover { color: #f0b90b; }
26
+ .breadcrumbs .bc-sep { margin: 0 6px; color: #484f58; }
27
+ .breadcrumbs .bc-current { color: #e6edf3; }
28
+ </style>
29
+ </head>
30
+ <body>
31
+ <nav class="nav-bar">
32
+ <div class="nav-brand">πŸ™ˆ Blind Monkeys</div>
33
+ <div class="nav-links">
34
+ <a href="/" class="nav-link">🏠 Home</a>
35
+ <a href="/scan/" class="nav-link">πŸ” Scan</a>
36
+ <a href="/settings/" class="nav-link">βš™οΈ Settings</a>
37
+ </div>
38
+ </nav>
39
+
40
+ <div class="page-content">
41
+ <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">β€Ί</span><span class="bc-current">Blog</span></div>
42
+ <h1>πŸ“– Blind Monkeys Blog</h1>
43
+ <p class="tagline">Essays and engineering notes from building a transparent crypto trading platform.</p>
44
+
45
+ {% if posts %}
46
+ {% for p in posts %}
47
+ <div class="post">
48
+ <h2><a href="/blog/{{ p.slug }}">{{ p.title }}</a></h2>
49
+ <div class="date">{{ p.date }}</div>
50
+ {% if p.summary %}<p>{{ p.summary }}</p>{% endif %}
51
+ </div>
52
+ {% endfor %}
53
+ {% else %}
54
+ <div class="empty">No posts yet β€” the first one is being written.</div>
55
+ {% endif %}
56
+ </div>
57
+ <script src="/css/nav.js?v=14"></script>
58
+ </body>
59
+ </html>
templates/blog_post.html ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>{% if post %}{{ post.title }} β€” Blind Monkeys{% else %}Post not found β€” Blind Monkeys{% endif %}</title>
7
+ {% if post and post.summary %}<meta name="description" content="{{ post.summary }}">{% endif %}
8
+ {% if post %}
9
+ <meta property="og:type" content="article">
10
+ <meta property="og:title" content="{{ post.title }}">
11
+ {% if post.summary %}<meta property="og:description" content="{{ post.summary }}">{% endif %}
12
+ <meta property="og:url" content="https://blindmonkeys.org/blog/{{ post.slug }}">
13
+ <script type="application/ld+json">
14
+ {
15
+ "@context": "https://schema.org",
16
+ "@type": "Article",
17
+ "headline": {{ post.title | tojson }},
18
+ {% if post.summary %}"description": {{ post.summary | tojson }},{% endif %}
19
+ "datePublished": "{{ post.date }}",
20
+ "url": "https://blindmonkeys.org/blog/{{ post.slug }}",
21
+ "author": { "@type": "Person", "name": "Dean Powers" },
22
+ "publisher": { "@type": "Organization", "name": "Blind Monkeys", "url": "https://blindmonkeys.org" }
23
+ }
24
+ </script>
25
+ {% endif %}
26
+ <link rel="stylesheet" href="/css/nav.css?v=4">
27
+ <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
28
+ <style>
29
+ * { box-sizing: border-box; }
30
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; margin: 0; }
31
+ .page-content { max-width: 760px; margin: 0 auto; padding: 32px 20px; }
32
+ h1 { font-size: 28px; line-height: 1.3; margin: 0 0 10px; }
33
+ .date { color: #8b949e; font-size: 13px; font-family: 'SF Mono', Monaco, monospace; margin-bottom: 26px; }
34
+ .article { font-size: 15.5px; line-height: 1.75; color: #c9d1d9; }
35
+ .article h1, .article h2, .article h3 { color: #e6edf3; line-height: 1.35; margin-top: 1.6em; }
36
+ .article h1 { font-size: 22px; } .article h2 { font-size: 19px; } .article h3 { font-size: 16.5px; }
37
+ .article a { color: #f0b90b; }
38
+ .article code { background: #161b22; border: 1px solid #30363d; border-radius: 5px; padding: 1px 6px; font-size: 13px; font-family: 'SF Mono', Monaco, monospace; color: #7ee787; }
39
+ .article pre { background: #161b22; border: 1px solid #30363d; border-radius: 10px; padding: 14px 16px; overflow-x: auto; }
40
+ .article pre code { background: none; border: none; padding: 0; }
41
+ .article blockquote { border-left: 3px solid #f0b90b; margin: 1.2em 0; padding: 4px 16px; color: #8b949e; background: #161b22; border-radius: 0 8px 8px 0; }
42
+ .article ul, .article ol { padding-left: 24px; }
43
+ .article li { margin-bottom: 6px; }
44
+ .article table { border-collapse: collapse; width: 100%; font-size: 14px; }
45
+ .article th, .article td { border: 1px solid #30363d; padding: 8px 12px; text-align: left; }
46
+ .article th { background: #1e2329; color: #f0b90b; font-size: 12.5px; text-transform: uppercase; letter-spacing: .5px; }
47
+ .back { display: inline-block; margin-top: 36px; color: #8b949e; font-size: 13.5px; text-decoration: none; }
48
+ .back:hover { color: #f0b90b; }
49
+ .notfound { text-align: center; padding: 80px 0; }
50
+ .notfound .big { font-size: 44px; margin-bottom: 12px; }
51
+ .notfound p { color: #8b949e; }
52
+ .notfound a { color: #f0b90b; text-decoration: none; }
53
+ .breadcrumbs { font-size: 12.5px; margin-bottom: 18px; }
54
+ .breadcrumbs a { color: #8b949e; text-decoration: none; }
55
+ .breadcrumbs a:hover { color: #f0b90b; }
56
+ .breadcrumbs .bc-sep { margin: 0 6px; color: #484f58; }
57
+ .breadcrumbs .bc-current { color: #e6edf3; }
58
+ </style>
59
+ </head>
60
+ <body>
61
+ <nav class="nav-bar">
62
+ <div class="nav-brand">πŸ™ˆ Blind Monkeys</div>
63
+ <div class="nav-links">
64
+ <a href="/" class="nav-link">🏠 Home</a>
65
+ <a href="/scan/" class="nav-link">πŸ” Scan</a>
66
+ <a href="/settings/" class="nav-link">βš™οΈ Settings</a>
67
+ </div>
68
+ </nav>
69
+
70
+ <div class="page-content">
71
+ {% if post %}
72
+ <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">β€Ί</span><a href="/blog/">Blog</a><span class="bc-sep">β€Ί</span><span class="bc-current">{{ post.title }}</span></div>
73
+ <h1>{{ post.title }}</h1>
74
+ <div class="date">{{ post.date }}</div>
75
+ <div class="article">
76
+ {{ body_html | safe }}
77
+ </div>
78
+ <a class="back" href="/blog/">← Back to all posts</a>
79
+ {% else %}
80
+ <div class="notfound">
81
+ <div class="big">πŸ™ˆ</div>
82
+ <p>This post doesn't exist (or isn't published).</p>
83
+ <p><a href="/blog/">← Back to the blog</a></p>
84
+ </div>
85
+ {% endif %}
86
+ </div>
87
+ <script src="/css/nav.js?v=14"></script>
88
+ </body>
89
+ </html>