Skip to content

Made all notes available from nested subdirectories inside /data #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions flatnotes/flatnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

StemmingFoldingAnalyzer = StemmingAnalyzer() | CharsetFilter(accent_map)


class IndexSchema(SchemaClass):
filename = ID(unique=True, stored=True)
last_modified = DATETIME(stored=True, sortable=True)
Expand All @@ -43,8 +42,7 @@ def __init__(self, message="The specified title is invalid"):

class Note:
def __init__(
self, flatnotes: "Flatnotes", title: str, new: bool = False
) -> None:
self, flatnotes: "Flatnotes", title: str, new: bool = False) -> None:
self._flatnotes = flatnotes
self._title = title.strip()
if not self._is_valid_title(self._title):
Expand All @@ -56,7 +54,15 @@ def __init__(

@property
def filepath(self):
return os.path.join(self._flatnotes.dir, self.filename)
filepath = os.path.join(
self._flatnotes.dir, self._title + MARKDOWN_EXT)
dirlist = glob.glob(os.path.join(
self._flatnotes.dir, "**/*" + MARKDOWN_EXT),
recursive=True)
for file in dirlist:
if self.filename in file:
filepath = file
return filepath

@property
def filename(self):
Expand All @@ -76,8 +82,10 @@ def title(self, new_title):
new_title = new_title.strip()
if not self._is_valid_title(new_title):
raise InvalidTitleError
old_filepath = self.filepath
path = os.path.split(old_filepath)[0]
new_filepath = os.path.join(
self._flatnotes.dir, new_title + MARKDOWN_EXT
path, new_title + MARKDOWN_EXT
)
os.rename(self.filepath, new_filepath)
self._title = new_title
Expand Down Expand Up @@ -229,12 +237,13 @@ def _add_note_to_index(
def _get_notes(self) -> List[Note]:
"""Return a list containing a Note object for every file in the notes
directory."""
return [
Note(self, strip_ext(os.path.split(filepath)[1]))
for filepath in glob.glob(
os.path.join(self.dir, "*" + MARKDOWN_EXT)
)
]
notes = []
for filepath in glob.glob(os.path.join(self.dir, "**/*" + MARKDOWN_EXT), recursive=True):
name = strip_ext(os.path.split(filepath)[1])
name = str(name)
note = Note(self, name)
notes.append(note)
return notes

def update_index(self, clean: bool = False) -> None:
"""Synchronize the index with the notes directory.
Expand Down