feat(mycv): add mycv build/open commands with --lang-en option
- build: generate CV PDF from cv-zh.md / cv-en.md via Typst cv template - open: open generated PDF with default application - --lang-en flag switches between Chinese and English CV
This commit is contained in:
@@ -12,6 +12,7 @@ from bin.commands.ssh import ssh_cmd
|
|||||||
from bin.commands.git import git_cmd
|
from bin.commands.git import git_cmd
|
||||||
from bin.commands.server import server_cmd
|
from bin.commands.server import server_cmd
|
||||||
from bin.commands.webpage import webpage_cmd
|
from bin.commands.webpage import webpage_cmd
|
||||||
|
from bin.commands.mycv import mycv_cmd
|
||||||
from bin.commands.mail import mail
|
from bin.commands.mail import mail
|
||||||
from bin.commands.self_mgmt import update_cmd, uninstall_cmd
|
from bin.commands.self_mgmt import update_cmd, uninstall_cmd
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ cli.add_command(ssh_cmd)
|
|||||||
cli.add_command(git_cmd)
|
cli.add_command(git_cmd)
|
||||||
cli.add_command(server_cmd)
|
cli.add_command(server_cmd)
|
||||||
cli.add_command(webpage_cmd)
|
cli.add_command(webpage_cmd)
|
||||||
|
cli.add_command(mycv_cmd)
|
||||||
cli.add_command(mail)
|
cli.add_command(mail)
|
||||||
cli.add_command(update_cmd)
|
cli.add_command(update_cmd)
|
||||||
cli.add_command(uninstall_cmd)
|
cli.add_command(uninstall_cmd)
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
"""CV build and open utilities."""
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from bin.md_to_pdf import build_pdf
|
||||||
|
|
||||||
|
|
||||||
|
_CV_DIR = (
|
||||||
|
Path.home()
|
||||||
|
/ "Library"
|
||||||
|
/ "Mobile Documents"
|
||||||
|
/ "iCloud~md~obsidian"
|
||||||
|
/ "Documents"
|
||||||
|
/ "myacademia"
|
||||||
|
/ "00-cv"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _src(lang_en: bool) -> Path:
|
||||||
|
return _CV_DIR / ("cv-en.md" if lang_en else "cv-zh.md")
|
||||||
|
|
||||||
|
|
||||||
|
def _pdf(lang_en: bool) -> Path:
|
||||||
|
return _CV_DIR / ("cv-en.pdf" if lang_en else "cv-zh.pdf")
|
||||||
|
|
||||||
|
|
||||||
|
@click.group(name="mycv")
|
||||||
|
def mycv_cmd():
|
||||||
|
"""Build and open CV PDFs."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@mycv_cmd.command("build")
|
||||||
|
@click.option("--lang-en", is_flag=True, help="Build English CV (default: Chinese)")
|
||||||
|
def mycv_build(lang_en):
|
||||||
|
"""Build CV PDF from markdown using the cv Typst template."""
|
||||||
|
src = _src(lang_en)
|
||||||
|
out = _pdf(lang_en)
|
||||||
|
|
||||||
|
if not src.exists():
|
||||||
|
click.secho(f"CV source not found: {src}", fg="red")
|
||||||
|
raise click.Abort()
|
||||||
|
|
||||||
|
click.secho(f"Building {'English' if lang_en else 'Chinese'} CV ...", fg="cyan")
|
||||||
|
build_pdf("cv", [src], out, bookmark_depth=2)
|
||||||
|
click.secho(f"CV generated: {out}", fg="green")
|
||||||
|
|
||||||
|
|
||||||
|
@mycv_cmd.command("open")
|
||||||
|
@click.option("--lang-en", is_flag=True, help="Open English CV (default: Chinese)")
|
||||||
|
def mycv_open(lang_en):
|
||||||
|
"""Open the CV PDF with the default application."""
|
||||||
|
pdf = _pdf(lang_en)
|
||||||
|
|
||||||
|
if not pdf.exists():
|
||||||
|
click.secho(f"PDF not found: {pdf}", fg="red")
|
||||||
|
click.secho("Run 'mytoolkit mycv build' first.", fg="yellow")
|
||||||
|
raise click.Abort()
|
||||||
|
|
||||||
|
subprocess.run(["open", str(pdf)], check=False)
|
||||||
Reference in New Issue
Block a user