mirror of
https://github.com/Ascyii/typstar.git
synced 2026-01-01 13:34:24 -05:00
fix(anki): correct preamble in force scan
This commit is contained in:
@@ -98,7 +98,7 @@ class FlashcardParser:
|
|||||||
cards.append(card)
|
cards.append(card)
|
||||||
return cards
|
return cards
|
||||||
|
|
||||||
def parse_directory(self, scan_dir, force_scan: Path = None):
|
def parse_directory(self, root_dir: Path, force_scan: Path = None):
|
||||||
single_file = None
|
single_file = None
|
||||||
is_force_scan = force_scan is not None
|
is_force_scan = force_scan is not None
|
||||||
if is_force_scan:
|
if is_force_scan:
|
||||||
@@ -107,6 +107,8 @@ class FlashcardParser:
|
|||||||
scan_dir = force_scan.parent
|
scan_dir = force_scan.parent
|
||||||
else:
|
else:
|
||||||
scan_dir = force_scan
|
scan_dir = force_scan
|
||||||
|
else:
|
||||||
|
scan_dir = root_dir
|
||||||
|
|
||||||
print(f"Parsing flashcards in {scan_dir if single_file is None else single_file} ...", flush=True)
|
print(f"Parsing flashcards in {scan_dir if single_file is None else single_file} ...", flush=True)
|
||||||
preambles = {}
|
preambles = {}
|
||||||
@@ -114,16 +116,18 @@ class FlashcardParser:
|
|||||||
|
|
||||||
@cache
|
@cache
|
||||||
def get_preamble(path: Path) -> str | None:
|
def get_preamble(path: Path) -> str | None:
|
||||||
while path != scan_dir.parent:
|
while path != root_dir.parent:
|
||||||
if preamble := preambles.get(path):
|
if preamble := preambles.get(path):
|
||||||
return preamble
|
return preamble
|
||||||
path = path.parent
|
path = path.parent
|
||||||
|
|
||||||
for file in sorted(glob.glob(f"{scan_dir}/**/**.typ", include_hidden=True, recursive=True)):
|
for file in sorted(glob.glob(f"{root_dir}/**/.anki.typ", include_hidden=True, recursive=True)):
|
||||||
file = Path(file)
|
file = Path(file)
|
||||||
if file.name == ".anki.typ":
|
if file.name == ".anki.typ":
|
||||||
preambles[file.parent] = file.read_text(encoding="utf-8")
|
preambles[file.parent] = file.read_text(encoding="utf-8")
|
||||||
continue
|
|
||||||
|
for file in sorted(glob.glob(f"{scan_dir}/**/**.typ", recursive=True)):
|
||||||
|
file = Path(file)
|
||||||
if single_file is not None and file != single_file:
|
if single_file is not None and file != single_file:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user