"""Generate all devguide wiki SVG assets with one shared look: gradient cards, drawn line icons, phone-legible text.
Run: python3 images/generate.py (writes next to this script)
Rule of thumb: GitHub shows images ~358px wide on phones, so the smallest text should be
>= 11px * (canvas width / 358).
"""
import os
from html import escape as X
OUT = os.path.dirname(os.path.abspath(__file__))
FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif"
MONO = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"
# one accent per section; tiles and page strips share it so they pair visually
SECTION = {
'start': ('#2a0b4d', '#5b1aa8', '#8e3ff0'),
'protocol': ('#0b1a4a', '#1d4ed8', '#3b82f6'),
'build': ('#062a33', '#0e6f86', '#14a3b8'),
'relays': ('#3b1405', '#b4400c', '#ea7a23'),
'tools': ('#052e16', '#15803d', '#22c55e'),
'ideas': ('#3d0726', '#a3164f', '#e2457e'),
'resources': ('#1a1450', '#3f37c9', '#6d64f0'),
}
NIGHT = ('#0d0b1f', '#1e1648', '#4c1590')
def defs(stops, gid='bg'):
a, b, c = stops
return f'''
'''
# ---------- line icons, drawn in a ~64px box centred on 0,0 ----------
ICONS = {
'rocket': ''
'',
'braces': ''
'',
'cube': '',
'key': '',
'server': ''
'',
'terminal': '',
'graph': ''
'',
'lock': '',
'compass': '',
'phone': '',
'globe': '',
'pulse': '',
'rss': '',
'bulb': '',
'person': '',
'book': '',
'box': '',
'plug': '',
}
def icon(name, cx, cy, size=64, disc=True, color='#ffffff', sw=7):
"""A line icon centred at cx,cy, optionally on a translucent disc."""
s = size / 64
d = f'' if disc else ''
return (d + f'{ICONS[name]}')
def constellation(tx, ty, sc=1.0, op=.3):
return (f''
f''
f'')
def write(name, body):
open(os.path.join(OUT, name), 'w').write(body)
# ---------- banner: title left, a signed event card right, tagline full width ----------
code = [
('{', '#e6dafc'),
(' "kind": 1,', '#ffffff'),
(' "content": "hello",', '#6ee7b7'),
(' "sig": "a91f…"', '#fcd34d'),
('}', '#e6dafc'),
]
lines = ''.join(f'{X(t)}' for i, (t, c) in enumerate(code))
write('banner.svg', f'''
''')
# ---------- page header strips (1200x200 -> ~60px tall, ~20px text on phones) ----------
STRIPS = {
'Quick-Start': ('start', 'rocket', 'Hello, Nostr in 5 minutes'),
'Build-a-Client': ('start', 'phone', 'From hello world to a feed'),
'Glossary': ('resources', 'book', 'Nostr terms, decoded'),
'Protocol-Basics': ('protocol', 'braces', 'Events, kinds, filters, relays'),
'NIP-98': ('protocol', 'lock', 'HTTP auth with Nostr keys'),
'Libraries': ('build', 'cube', 'Pick a library'),
'Extensions': ('build', 'key', 'Signers & login'),
'Client-Implementations': ('build', 'phone', 'Open-source clients'),
'Relay-Implementations': ('relays', 'server', 'Relay software in 2026'),
'Tutorials': ('relays', 'rocket', 'Run a relay'),
'Reverse-Proxy': ('relays', 'plug', 'TLS & WebSockets'),
'Hosting': ('relays', 'globe', 'Where to host'),
'Relay-Explorers': ('relays', 'pulse', 'Watch the network'),
'NAK': ('tools', 'terminal', 'nak, the army knife'),
'Websocat': ('tools', 'terminal', 'Raw WebSockets'),
'Websocket-Test-Client': ('tools', 'globe', 'Poke relays in a browser'),
'Snippets': ('tools', 'braces', 'Copy-paste recipes'),
'RSS': ('tools', 'rss', 'RSS to Nostr'),
'Social-Graph': ('build', 'graph', 'The social graph'),
'Algorithms': ('ideas', 'bulb', 'Feeds & algorithms'),
'Strong-Set': ('ideas', 'graph', 'The strong set (2023)'),
'nosgraph': ('ideas', 'person', 'nosgraph (offline)'),
'Profile': ('build', 'person', 'Profile metadata'),
'hyper-nostr': ('ideas', 'box', 'hyper-nostr (archived)'),
'fonstr': ('tools', 'server', 'fonstr: a tiny relay'),
'Resources': ('resources', 'book', 'Docs & community'),
}
for page, (sec, ic, tag) in STRIPS.items():
fs = min(64, int(1360 / len(tag))) # keep long titles clear of the constellation
write(f'hdr-{page}.svg', f'''
''')
# ---------- home tiles (2 per row; ~170px wide on phones) ----------
TILES = {
'Build-a-Client': ('start', 'phone', 'Build a client', 'Login, feed, replies'),
'Protocol-Basics': ('protocol', 'braces', 'Protocol', 'Events, kinds, NIPs'),
'Libraries': ('build', 'cube', 'Libraries', 'JS, Rust, Go, Python…'),
'Extensions': ('build', 'key', 'Signers', 'NIP-07, 46, 55'),
'Relay-Implementations': ('relays', 'server', 'Relays', 'Run and pick one'),
'NAK': ('tools', 'terminal', 'Tools', 'nak, websocat, recipes'),
}
for page, (sec, ic, title, sub) in TILES.items():
write(f'tile-{page}.svg', f'''
''')
# ---------- call-to-action button ----------
write('btn-start.svg', f'''
''')
# ---------- shared diagram bits ----------
def pill(x, y, w, h, label, r=None, fs=23, mono=False):
r = h / 2 if r is None else r
cls = ' class="mono"' if mono else ''
return (f''
f'{label}')
def lab(y, t, x=32):
return f'{t}'
A = 'stroke="#e6dafc" stroke-width="3" fill="none" marker-end="url(#arr)"'
AG = 'stroke="#6ee7b7" stroke-width="3" fill="none" marker-end="url(#arrg)"'
# ---------- event anatomy (phone-first, stacked rows) ----------
ROWS = [
('id', 'sha256 of the serialized event', '#93c5fd'),
('pubkey', "author's key (hex)", '#ffffff'),
('created_at', 'unix seconds', '#ffffff'),
('kind', '1 note · 0 profile · 3 follows', '#fcd34d'),
('tags', '[["e", …], ["p", …]]', '#ffffff'),
('content', 'text, JSON or ciphertext', '#6ee7b7'),
('sig', 'schnorr signature over id', '#f9a8d4'),
]
ea = [f'''\n')
write('event-anatomy.svg', '\n '.join(ea))
# ---------- client <-> relay message flow ----------
mf = [f'''\n')
write('message-flow.svg', '\n '.join(mf))
print('ok')