From a759853f087e4fec852b03eaef67e81b78f540c3 Mon Sep 17 00:00:00 2001 From: Bauke Date: Tue, 19 Mar 2024 14:20:42 +0100 Subject: [PATCH] Use sys.inputs to pass variables via the CLI. --- .gitignore | 1 - Makefile.toml | 19 +++++++++++++++---- compile-cv.zsh | 22 ---------------------- main.typ | 5 ++++- 4 files changed, 19 insertions(+), 28 deletions(-) delete mode 100755 compile-cv.zsh diff --git a/.gitignore b/.gitignore index 5a8f3c7..9bdb3b1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ .vscode/ build/ data/ -cv.typ diff --git a/Makefile.toml b/Makefile.toml index 67cb28d..b87884d 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,3 +1,7 @@ +[env] +CV_INCLUDE_LINKS = { condition = { env_not_set = ["CV_INCLUDE_LINKS"] }, value = "true" } +CV_VERSION = { condition = { env_not_set = ["CV_VERSION"] }, value = "2024-03-01" } + # Shorthand to compile all the languages at once. [tasks.build] clear = true @@ -5,12 +9,12 @@ dependencies = ["build-en", "build-nl"] # Compile using the English locale. [tasks.build-en] -env = { CV_LANG="en" } +env = { CV_LANG = "en" } extend = "compile" # Compile using the Dutch locale. [tasks.build-nl] -env = { CV_LANG="nl" } +env = { CV_LANG = "nl" } extend = "compile" # Clean the repository by removing the build directory. @@ -23,7 +27,14 @@ args = ["trash", "build"] [tasks.compile] clear = true dependencies = ["ensure-build-dir"] -script = "./compile-cv.zsh" +command = "typst" +args = [ + "compile", "main.typ", + "--input", "language=${CV_LANG}", + "--input", "include_links=${CV_INCLUDE_LINKS}", + "--input", "version=${CV_VERSION}", + "build/CV-Bauke-${CV_LANG}.pdf", +] # Ensure that the build directory exists. [tasks.ensure-build-dir] @@ -36,4 +47,4 @@ args = ["-p", "build"] [tasks.watch] clear = true command = "watchexec" -args = ["-e", "toml,typ", "-i", "cv.typ", "--no-vcs-ignore", "makers build"] +args = ["-e", "toml,typ", "--no-vcs-ignore", "makers build"] diff --git a/compile-cv.zsh b/compile-cv.zsh deleted file mode 100755 index 1ede394..0000000 --- a/compile-cv.zsh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env zsh - -# There's currently no way in Typst to provide values from the CLI in some way -# so until the next version lands and https://github.com/typst/typst/pull/2894 -# becomes available, a script that renders a template has to be it for now. - -# Define options based on environment variables or use default values. -include_links=${CV_INCLUDE_LINKS:-"true"} -language=${CV_LANG:-"en"} -version="2024-03-01" - -typst_template="#import \"main.typ\": cv - -#cv( - include_links: $include_links, - language: \"$language\", - version: \"$version\", -)" - -echo $typst_template > cv.typ - -typst compile cv.typ "build/CV-Bauke-$CV_LANG.pdf" diff --git a/main.typ b/main.typ index a4c95dd..1530ac5 100644 --- a/main.typ +++ b/main.typ @@ -5,7 +5,10 @@ #import "./utilities/content-to-string.typ": content_to_string #import "./utilities/localize.typ": localize -#let cv(include_links: true, language: "", version: "") = { +#{ + let (include_links, language, version) = sys.inputs + let include_links = include_links == "true" + if language == "" { panic("No language option specified.") }