This commit is contained in:
@@ -399,20 +399,30 @@ def list_pages() -> list[dict[str, Any]]:
|
||||
pages = []
|
||||
org_paths = []
|
||||
if ROOT.exists():
|
||||
for path in ROOT.rglob("*.org"):
|
||||
rel_parts = path.relative_to(ROOT).parts
|
||||
if any(part in EXCLUDED_CONTENT_DIR_NAMES for part in rel_parts):
|
||||
continue
|
||||
org_paths.append(path)
|
||||
md_paths = list(LIMA_DIR.rglob("*.md")) if LIMA_DIR.exists() else []
|
||||
try:
|
||||
for path in ROOT.rglob("*.org"):
|
||||
try:
|
||||
rel_parts = path.relative_to(ROOT).parts
|
||||
except ValueError:
|
||||
continue
|
||||
if any(part in EXCLUDED_CONTENT_DIR_NAMES for part in rel_parts):
|
||||
continue
|
||||
org_paths.append(path)
|
||||
except OSError:
|
||||
org_paths = []
|
||||
try:
|
||||
md_paths = list(LIMA_DIR.rglob("*.md")) if LIMA_DIR.exists() else []
|
||||
except OSError:
|
||||
md_paths = []
|
||||
for path in sorted(org_paths + md_paths):
|
||||
if path.name in GENERATED_CONTENT_NAMES or "sync-conflict" in path.name:
|
||||
continue
|
||||
try:
|
||||
page = read_page(path)
|
||||
except UnicodeDecodeError:
|
||||
parsed = parse_org_datetime(page.date)
|
||||
timestamp = parsed.timestamp() if parsed else path.stat().st_mtime
|
||||
except (OSError, UnicodeDecodeError, ValueError):
|
||||
continue
|
||||
parsed = parse_org_datetime(page.date)
|
||||
pages.append(
|
||||
{
|
||||
"path": page.path,
|
||||
@@ -422,7 +432,7 @@ def list_pages() -> list[dict[str, Any]]:
|
||||
"tags": page.tags,
|
||||
"date": page.date,
|
||||
"format": page.format,
|
||||
"timestamp": parsed.timestamp() if parsed else path.stat().st_mtime,
|
||||
"timestamp": timestamp,
|
||||
}
|
||||
)
|
||||
return sorted(pages, key=lambda item: item["timestamp"], reverse=True)
|
||||
@@ -850,7 +860,12 @@ APP_HTML = r"""<!doctype html>
|
||||
|
||||
async function api(path, options = {}) {
|
||||
const res = await fetch(path, { headers: { "Content-Type": "application/json" }, ...options });
|
||||
const data = await res.json();
|
||||
let data = null;
|
||||
try {
|
||||
data = await res.clone().json();
|
||||
} catch (_err) {
|
||||
data = { error: await res.text().catch(() => "") };
|
||||
}
|
||||
if (!res.ok) throw new Error(data.error || "Request failed");
|
||||
return data;
|
||||
}
|
||||
@@ -1014,13 +1029,23 @@ APP_HTML = r"""<!doctype html>
|
||||
state.pages = await api("/api/pages");
|
||||
renderPages();
|
||||
} catch (err) {
|
||||
pagesBox.innerHTML = `<div class="queue-item"><span>${html(err.message)}</span></div>`;
|
||||
if (state.pages.length) {
|
||||
renderPages();
|
||||
saveMessage.textContent = `Could not refresh file list: ${err.message}`;
|
||||
} else {
|
||||
pagesBox.innerHTML = `<div class="queue-item"><span>${html(err.message)}</span></div>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshBuild() {
|
||||
state.build = await api("/api/build");
|
||||
renderStatus();
|
||||
try {
|
||||
state.build = await api("/api/build");
|
||||
renderStatus();
|
||||
} catch (err) {
|
||||
statusBox.className = "status fail";
|
||||
statusBox.textContent = `Could not refresh build status: ${err.message}`;
|
||||
}
|
||||
await refreshPages();
|
||||
}
|
||||
|
||||
@@ -1323,7 +1348,10 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.wfile.write(body)
|
||||
return
|
||||
if parsed.path == "/api/pages":
|
||||
self.send_json(list_pages())
|
||||
try:
|
||||
self.send_json(list_pages())
|
||||
except Exception as exc:
|
||||
self.send_json({"error": str(exc)}, HTTPStatus.INTERNAL_SERVER_ERROR)
|
||||
return
|
||||
if parsed.path == "/api/page":
|
||||
query = parse_qs(parsed.query)
|
||||
|
||||
Reference in New Issue
Block a user