From d1b09b7cfd68409bbcbed6bdd86a26c070c92ad5 Mon Sep 17 00:00:00 2001 From: sebtlm Date: Thu, 2 Nov 2023 19:32:08 +0100 Subject: [PATCH] ADD support for ignoring some vault files with a .zoraignore file --- convert.py | 7 ++++++- utils.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/convert.py b/convert.py index b41ac171..7ecf5f30 100644 --- a/convert.py +++ b/convert.py @@ -10,6 +10,8 @@ raw_dir, site_dir, write_settings, + get_ignore_list, + filter_obsidian_files ) if __name__ == "__main__": @@ -25,7 +27,10 @@ section_count = 0 all_paths = list(sorted(raw_dir.glob("**/*"))) - + # Filter files found in an optional .zolaignore file + ignore_list = get_ignore_list() + if len(ignore_list) > 0: + all_paths = list(filter(filter_obsidian_files(ignore_list), all_paths)) for path in [raw_dir, *all_paths]: doc_path = DocPath(path) if doc_path.is_file: diff --git a/utils.py b/utils.py index 4f644c33..75199d8f 100644 --- a/utils.py +++ b/utils.py @@ -491,3 +491,20 @@ def write_settings(): ] ) ) + + +def get_ignore_list(): + ignore_file = site_dir.parent.parent / ".zolaignore" + ignore_list = [] + if ignore_file.exists(): + print("found ignore file, processing...") + with open(ignore_file, encoding="utf-8") as f: + for line in f: + print("ignoring " + line) + ignore_list.append(line.rstrip()) + return ignore_list + print("No ignore file found.") + return [] + +def filter_obsidian_files(ignore_list): + return lambda a: next(filter(lambda x: a.match(x), ignore_list), None) is None \ No newline at end of file