diff --git a/main.py b/main.py index bb80c64..2ba05f9 100644 --- a/main.py +++ b/main.py @@ -27,6 +27,7 @@ class OrgFile: file_id: str | None content: str mtime: float = 0.0 + pinned: bool = False ROOT_DIR = Path(__file__).resolve().parent @@ -78,6 +79,19 @@ def scan_org_files(base_dir: Path) -> list[OrgFile]: ) org_files.sort(key=lambda f: f.mtime, reverse=True) + + if os.environ.get("ORGWEB_PIN_TODAY_FILE", "").lower() in ("1", "true", "yes"): + today = datetime.now().strftime("%Y-%m-%d") + pinned = [] + rest = [] + for f in org_files: + if today in f.relative_path or today in f.title: + f.pinned = True + pinned.append(f) + else: + rest.append(f) + org_files = pinned + rest + return org_files @@ -470,7 +484,7 @@ _NOTE_TAKEN_RE = re.compile( ) -def extract_heading_data(content: str, heading_text: str) -> dict | None: +def extract_heading_data(content: str, heading_text: str, file_id: str = "") -> dict | None: """Find a heading in *content* by its text and extract webhook-ready data.""" lines = content.splitlines() target_idx: int | None = None @@ -551,7 +565,7 @@ def extract_heading_data(content: str, heading_text: str) -> dict | None: body_lines.append(sl) - emacs_id = properties.get("ID", "") + emacs_id = properties.get("ID", "") or file_id notes = _extract_notes(body_lines) return { @@ -641,11 +655,12 @@ def build_index_page( created_key = extract_created_sort_key(f.content) created_key_attr = "" if created_key is None else str(created_key) modified_ts = str(int(f.mtime)) + pin_icon = "\U0001F4CC " if f.pinned else "" nav_items.append( f"" - f"{safe_title}" + f"{pin_icon}{safe_title}" f"{safe_path}" "" ) @@ -707,6 +722,51 @@ def build_index_page( ) +def build_backlinks_page(org_files: Iterable[OrgFile], selected_path: str | None = None) -> str: + """Return a minimal standalone HTML page containing only the backlinks for a note.""" + org_files = list(org_files) + if not org_files: + items_html = "
No .org files found.
" + else: + selected = find_org_file(org_files, selected_path) or org_files[0] + backlinks = find_backlinks(org_files, selected.relative_path) + if backlinks: + backlink_items = [] + for source in backlinks: + safe_href = html.escape(note_href(source.relative_path, False), quote=True) + safe_title = html.escape(source.title) + safe_path = html.escape(source.relative_path) + full_title = html.escape(source.title, quote=True) + full_path = html.escape(source.relative_path, quote=True) + backlink_items.append( + f"" + f"{safe_title}" + f"{safe_path}" + "" + ) + items_html = "\n".join(backlink_items) + else: + items_html = "No notes link to this note yet.
" + + return ( + "\n\n\n" + " \n" + " \n" + "