1- // A generated module for Quarto functions
1+ // A Dagger module for authoring, rendering, and publishing Quarto projects.
22//
3- // This module has been generated via dagger init and serves as a reference to
4- // basic module structure as you get started with Dagger.
5- //
6- // Two functions have been pre-created. You can modify, delete, or add to them,
7- // as needed. They demonstrate usage of arguments and return types using simple
8- // echo and grep commands. The functions can be called from the dagger CLI or
9- // from one of the SDKs.
10- //
11- // The first line in this comment block is a short description line and the
12- // rest is a long description with more detail on the module's purpose or usage,
13- // if appropriate. All modules should have a short description.
3+ // This module provides tools to render Quarto documents, books, websites,
4+ // install custom Quarto extensions, and manage LaTeX packages via TeX Live.
145package main
156
167import (
@@ -19,11 +10,11 @@ import (
1910)
2011
2112const (
22- defaultImageRepository = "ghcr.io/quarto-dev/quarto"
13+ defaultImageRepository = "ghcr.io/quarto-dev/quarto:latest "
2314 tlmgrUpdateURL = "https://mirror.ctan.org/systems/texlive/tlnet/update-tlmgr-latest.sh"
2415)
2516
26- // Quarto is a module for running Quarto
17+ // Quarto provides functions for running and compiling Quarto projects.
2718type Quarto struct {
2819 // +private
2920 Image string
@@ -35,15 +26,15 @@ type Quarto struct {
3526 Ctr * dagger.Container
3627}
3728
38- // New creates a new instance of the Quarto struct
29+ // New creates a new instance of the Quarto module.
3930func New (
4031 // Custom image reference in "repository:tag" format to use as a base container.
4132 // +optional
4233 image string ,
43- // List of extensions to add to the container .
34+ // List of Quarto extensions to install (e.g. "quarto-ext/lightbox") .
4435 // +optional
4536 extensions []string ,
46- // List of optional LaTeX packages to install.
37+ // List of optional LaTeX packages to install via tlmgr (requires a TeX-enabled image like quarto-full) .
4738 // +optional
4839 latexPackages []string ,
4940) * Quarto {
@@ -54,7 +45,7 @@ func New(
5445 }
5546}
5647
57- // Container returns the underlying Dagger container
48+ // container returns the underlying Dagger container, lazily initialized.
5849func (m * Quarto ) container () * dagger.Container {
5950 if m .Ctr != nil {
6051 return m .Ctr
@@ -67,20 +58,19 @@ func (m *Quarto) container() *dagger.Container {
6758
6859 ctr := dag .Container ().From (image )
6960
70- if strings . Contains ( image , "quarto-full" ) {
71- // Update tlmgr
61+ // Only update tlmgr and install packages if LaTeX packages are explicitly requested
62+ if len ( m . LatexPackages ) > 0 {
7263 ctr = ctr .WithExec ([]string {
7364 "sh" , "-c" ,
7465 "curl -fsSL " + tlmgrUpdateURL + " -o update-tlmgr-latest.sh && sh update-tlmgr-latest.sh -- --update" ,
7566 })
7667
77- // Install specified LaTeX packages
78- for _ , pkg := range m .LatexPackages {
79- ctr = ctr .WithExec ([]string {"tlmgr" , "install" , pkg })
80- }
68+ // Install all packages in a single command layer
69+ installCmd := append ([]string {"tlmgr" , "install" }, m .LatexPackages ... )
70+ ctr = ctr .WithExec (installCmd )
8171 }
8272
83- // Add Quarto extensions
73+ // Install Quarto extensions
8474 for _ , ext := range m .Extensions {
8575 ctr = ctr .WithExec ([]string {"quarto" , "add" , "--no-prompt" , ext })
8676 }
@@ -89,35 +79,41 @@ func (m *Quarto) container() *dagger.Container {
8979 return m .Ctr
9080}
9181
92- // Build runs the quarto render command exporting to a directory
82+ // Build compiles the Quarto project and returns the exported output directory.
9383func (m * Quarto ) Build (
94- // source directory.
84+ // Source directory of the Quarto project .
9585 source * dagger.Directory ,
86+ // Output directory name relative to source (e.g. "_output", "_site", "_book").
87+ // +default="_output"
88+ // +optional
89+ outputDir string ,
9690) * dagger.Directory {
91+ workdir := "/work"
92+ outPath := workdir + "/" + strings .TrimPrefix (outputDir , "/" )
93+
9794 return m .container ().
98- WithDirectory ("/tmp" , source ).
99- WithWorkdir ("/tmp" ).
100- WithExec ([]string {"quarto" , "render" }).Directory ("/tmp/_output" )
95+ WithMountedDirectory (workdir , source ).
96+ WithWorkdir (workdir ).
97+ WithExec ([]string {"quarto" , "render" }).
98+ Directory (outPath )
10199}
102100
103- // Render runs the quarto render command
101+ // Render runs the quarto render command and returns the container.
104102func (m * Quarto ) Render (
105- // source directory.
103+ // Source directory of the Quarto project .
106104 source * dagger.Directory ,
107105) * dagger.Container {
108106 return m .container ().
109- WithDirectory ("/tmp " , source ).
110- WithWorkdir ("/tmp " ).
107+ WithMountedDirectory ("/work " , source ).
108+ WithWorkdir ("/work " ).
111109 WithExec ([]string {"quarto" , "render" })
112110}
113111
114- // Cli runs the quarto cli
112+ // Cli executes an arbitrary command in the Quarto container.
115113func (m * Quarto ) Cli (
116- // commands to run
114+ // Command string to execute (e.g. "quarto --version" or "quarto check").
117115 args string ,
118116) * dagger.Container {
119- parsedArgs := strings .Split (args , " " )
120-
121117 return m .container ().
122- WithExec (parsedArgs )
118+ WithExec ([] string { "sh" , "-c" , args } )
123119}
0 commit comments