Editor: jump-to-section dropdown (parses /* banner */ comments)
This commit is contained in:
@@ -20,6 +20,7 @@ Config via env: FUELBOARD_REPO, TOKEN, PORT (default 8790).
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import secrets
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -76,6 +77,18 @@ def git_head() -> str:
|
||||
return git("log", "--oneline", "-1") or "no commits"
|
||||
|
||||
|
||||
def parse_sections(content: str) -> list:
|
||||
"""Find single-line comment banners like /* Stations tab */ so the
|
||||
editor can offer a jump-to-section dropdown. The multi-line header
|
||||
comment at the top never matches (it doesn't end with */ on one line)."""
|
||||
sections = []
|
||||
for i, line in enumerate(content.splitlines(), start=1):
|
||||
m = re.match(r"^/\* (.+) \*/$", line.strip())
|
||||
if m:
|
||||
sections.append({"name": m.group(1).strip(), "line": i})
|
||||
return sections
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Build job (runs in a background thread so the phone doesn't wait on it)
|
||||
# --------------------------------------------------------------------------
|
||||
@@ -212,7 +225,8 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self._json(404, {"error": f"missing {STRINGS_FILE}"})
|
||||
return
|
||||
self._json(200, {"content": content, "dirty": git_dirty_files(),
|
||||
"head": git_head(), "repo": str(REPO)})
|
||||
"head": git_head(), "repo": str(REPO),
|
||||
"sections": parse_sections(content)})
|
||||
return
|
||||
if self.path.startswith("/job/"):
|
||||
if not self._authorized():
|
||||
|
||||
Reference in New Issue
Block a user