From 55785d50c387cca580e69b1c3c43020b419f852c Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Fri, 17 Nov 2023 14:47:06 -0800 Subject: [PATCH] Use title, when present, as root ancestor of entries instead of file path --- src/khoj/processor/org_mode/org_to_entries.py | 2 +- src/khoj/processor/org_mode/orgnode.py | 18 +++++++++++++----- tests/test_orgnode.py | 12 ++++++------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/khoj/processor/org_mode/org_to_entries.py b/src/khoj/processor/org_mode/org_to_entries.py index c84ab48f..e42b7498 100644 --- a/src/khoj/processor/org_mode/org_to_entries.py +++ b/src/khoj/processor/org_mode/org_to_entries.py @@ -110,7 +110,7 @@ class OrgToEntries(TextToEntries): compiled = heading if state.verbose > 2: - logger.debug(f"Title: {parsed_entry.heading}") + logger.debug(f"Title: {heading}") if parsed_entry.tags: tags_str = " ".join(parsed_entry.tags) diff --git a/src/khoj/processor/org_mode/orgnode.py b/src/khoj/processor/org_mode/orgnode.py index 68508666..28f55c17 100644 --- a/src/khoj/processor/org_mode/orgnode.py +++ b/src/khoj/processor/org_mode/orgnode.py @@ -80,7 +80,7 @@ def makelist(file, filename): } # populated from #+SEQ_TODO line level = "" heading = "" - ancestor_headings = [f"{filename}"] + ancestor_headings = [] bodytext = "" introtext = "" tags = list() # set of all tags in headline @@ -257,6 +257,9 @@ def makelist(file, filename): n.priority = priority_search.group(1) n.heading = priority_search.group(2) + # Prefix filepath/title to ancestors + n.ancestors = [file_title] + n.ancestors + # Set SOURCE property to a file+heading based org-mode link to the entry if n.level == 0: n.properties["LINE"] = f"file:{normalize_filename(filename)}::0" @@ -295,15 +298,20 @@ class Orgnode(object): self._logbook = list() # List of clock-in, clock-out tuples representing logbook entries self._ancestor_headings = ancestor_headings.copy() - # Look for priority in headline and transfer to prty field - @property - def ancestors(self): + def ancestors(self) -> List[str]: """ - Return the Heading text of the node without the TODO tag + Return the ancestor headings of the node """ return self._ancestor_headings + @ancestors.setter + def ancestors(self, new_ancestors): + """ + Update the ancestor headings of the node + """ + self._ancestor_headings = new_ancestors + @property def heading(self): """ diff --git a/tests/test_orgnode.py b/tests/test_orgnode.py index 4ef12661..157763e2 100644 --- a/tests/test_orgnode.py +++ b/tests/test_orgnode.py @@ -262,7 +262,7 @@ Body Line 1""" assert entries[0].closed == "" assert entries[0].scheduled == "" assert entries[0].deadline == "" - assert entries[0].ancestors == [] + assert entries[0].ancestors == ["test"] # ---------------------------------------------------------------------------------------------------- @@ -287,7 +287,7 @@ Body Line 1 assert entries[0].closed == "" assert entries[0].scheduled == "" assert entries[0].deadline == "" - assert entries[0].ancestors == [] + assert entries[0].ancestors == ["title1 title2"] # ---------------------------------------------------------------------------------------------------- @@ -308,10 +308,10 @@ entry body assert len(entries) == 2 assert entries[0].heading == "Title" assert entries[0].body == "intro body\n" - assert entries[0].ancestors == [] + assert entries[0].ancestors == ["Title"] assert entries[1].heading == "Entry Heading" assert entries[1].body == "entry body\n\n" - assert entries[1].ancestors == [f"{orgfile}"] + assert entries[1].ancestors == ["Title"] # ---------------------------------------------------------------------------------------------------- @@ -332,10 +332,10 @@ entry body assert len(entries) == 2 assert entries[0].heading == "Title1 Title2" assert entries[0].body == "intro body\n" - assert entries[0].ancestors == [] + assert entries[0].ancestors == ["Title1 Title2"] assert entries[1].heading == "Entry Heading" assert entries[1].body == "entry body\n\n" - assert entries[1].ancestors == [f"{orgfile}"] + assert entries[0].ancestors == ["Title1 Title2"] # ----------------------------------------------------------------------------------------------------