- Move all source files from mytoolkit/ to bin/ - Update entry point and build config in pyproject.toml - Add pillow and pypdf dependencies - Update README and .gitignore paths - Remove unused subprocess import in pdf.py - Clean up duplicate imports in pdf merge command
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
"""BibTeX utilities."""
|
|
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import click
|
|
|
|
from bin.config import config
|
|
from bin.utils import handle_errors, run_command
|
|
|
|
|
|
@click.group()
|
|
def bib():
|
|
"""BibTeX and bibliography commands."""
|
|
pass
|
|
|
|
|
|
@bib.command("to-markdown")
|
|
@click.argument("files", nargs=-1, required=True)
|
|
@click.option("--dry-run", "-n", is_flag=True, help="Show what would be done")
|
|
@handle_errors
|
|
def to_markdown(files, dry_run):
|
|
"""Convert BibTeX files to Markdown."""
|
|
for pattern in files:
|
|
for bib_file in Path(".").glob(pattern):
|
|
if bib_file.suffix.lower() != ".bib":
|
|
continue
|
|
output = bib_file.with_suffix(".md")
|
|
|
|
if dry_run:
|
|
click.echo(f"Would convert: {bib_file} -> {output}")
|
|
continue
|
|
|
|
click.echo(f"Converting: {bib_file} -> {output}")
|
|
content = bib_file.read_text()
|
|
md_content = f"# Bibliography\n\n```bibtex\n{content}\n```\n"
|
|
output.write_text(md_content)
|
|
|
|
|
|
@bib.command("cv-update")
|
|
@handle_errors
|
|
def cv_update():
|
|
"""Update CV bibliography using biber."""
|
|
cv_path_str = config.get("path_cv")
|
|
if cv_path_str:
|
|
cv_path = Path(cv_path_str).expanduser()
|
|
else:
|
|
# Fallback to hardcoded path
|
|
cv_path = Path.home() / "Documents/Personal/resume_cv/cv_lai_maintaining_latex/cv_lai_maintaining"
|
|
|
|
if not cv_path.exists():
|
|
click.echo(f"CV file not found: {cv_path}")
|
|
return
|
|
|
|
click.echo(f"Updating CV bibliography: {cv_path}")
|
|
run_command(["biber", str(cv_path)], check=False)
|