fix set_tiddler_values to work with missing files and meta files

This commit is contained in:
Soren I. Bjornstad 2021-09-10 11:18:03 -05:00
parent a2ff251e74
commit ea02c1bd5a

View File

@ -444,8 +444,17 @@ def set_tiddler_values(mappings: Dict[str, str]) -> None:
for tiddler, new_text in mappings.items(): for tiddler, new_text in mappings.items():
tiddler_path = (Path(build_state['public_wiki_folder']) / "tiddlers" / tiddler) tiddler_path = (Path(build_state['public_wiki_folder']) / "tiddlers" / tiddler)
try:
with tiddler_path.open("r") as f: with tiddler_path.open("r") as f:
tiddler_lines = f.readlines() tiddler_lines = f.readlines()
except FileNotFoundError:
stop(f"File {tiddler_path} not found. "
f"(Did you forget to end the name with '.tid'?)")
if not str(tiddler_path).endswith('.tid'):
# will be a separate meta file, so the whole thing is the text field
first_blank_line_index = 0
else:
first_blank_line_index = next(idx first_blank_line_index = next(idx
for idx, value in enumerate(tiddler_lines) for idx, value in enumerate(tiddler_lines)
if not value.strip()) if not value.strip())