fix: auto-include transkript/zusammenfassung siblings when copying index to Obsidian vault
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+13
-3
@@ -223,12 +223,22 @@ async def open_file(body: dict, user: dict = Depends(current_user)):
|
|||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
cfg = load_config()
|
cfg = load_config()
|
||||||
vault = cfg.get("obsidian", {}).get("vault", "").strip()
|
vault = cfg.get("obsidian", {}).get("vault", "").strip()
|
||||||
open_target = paths[0]
|
# If only the index was passed, also include sibling transkript/zusammenfassung
|
||||||
if vault and os.path.isdir(vault):
|
all_paths = list(paths)
|
||||||
for p in paths:
|
for p in paths:
|
||||||
|
if p.endswith("-index.md"):
|
||||||
|
base = p[: -len("-index.md")]
|
||||||
|
for suffix in ("-transkript.md", "-zusammenfassung.md"):
|
||||||
|
sibling = base + suffix
|
||||||
|
if os.path.exists(sibling) and sibling not in all_paths:
|
||||||
|
all_paths.append(sibling)
|
||||||
|
|
||||||
|
open_target = all_paths[0]
|
||||||
|
if vault and os.path.isdir(vault):
|
||||||
|
for p in all_paths:
|
||||||
dest = os.path.join(vault, os.path.basename(p))
|
dest = os.path.join(vault, os.path.basename(p))
|
||||||
shutil.copy2(p, dest)
|
shutil.copy2(p, dest)
|
||||||
open_target = os.path.join(vault, os.path.basename(paths[0]))
|
open_target = os.path.join(vault, os.path.basename(all_paths[0]))
|
||||||
uri = f"obsidian://open?path={quote(open_target, safe='/')}"
|
uri = f"obsidian://open?path={quote(open_target, safe='/')}"
|
||||||
obsidian_bin = shutil.which("obsidian") or "/usr/bin/obsidian"
|
obsidian_bin = shutil.which("obsidian") or "/usr/bin/obsidian"
|
||||||
subprocess.Popen([obsidian_bin, uri])
|
subprocess.Popen([obsidian_bin, uri])
|
||||||
|
|||||||
Reference in New Issue
Block a user