@@ -6,6 +6,12 @@ import { deleteFile, errorRefiner } from "./src/utils";
66import { z } from "zod" ;
77
88const TypeOfFileSchema = z . enum ( [ "PDF" , "TEX" ] ) ;
9+ const TemplateSchema = z . enum ( [ "default" , "cjk" ] ) ;
10+
11+ const templatePaths : Record < z . infer < typeof TemplateSchema > , string > = {
12+ default : "./templates/default.latex" ,
13+ cjk : "./templates/cjk.latex" ,
14+ } ;
915
1016export const schema = z . array (
1117 z . object ( {
@@ -15,6 +21,7 @@ export const schema = z.array(
1521 markdown : z . string ( ) ,
1622 implicitFigures : z . boolean ( ) . optional ( ) ,
1723 variables : z . record ( z . string ( ) , z . string ( ) ) . optional ( ) ,
24+ template : TemplateSchema . optional ( ) ,
1825 } )
1926) ;
2027
@@ -150,13 +157,14 @@ export const handler = async function (
150157 const implicitFigures = eachRequestData . implicitFigures ;
151158 const variableArgs = Object . entries ( eachRequestData . variables ?? { } )
152159 . map ( ( [ k , v ] ) => `--variable=${ k } :${ v } ` ) ;
160+ const templatePath = templatePaths [ eachRequestData . template ?? "default" ] ;
153161
154162 switch ( eachRequestData . typeOfFile ) {
155163 case "PDF" :
156164 const filenamePDF = `${ eachRequestData . fileName } .pdf` ;
157165 const localPathPDF = `/tmp/${ filenamePDF } ` ;
158166 const generatePDFResult = await generateFile (
159- [ "--pdf-engine=xelatex" , `--template=./template.latex ` , ...variableArgs ] ,
167+ [ "--pdf-engine=xelatex" , `--template=${ templatePath } ` , ...variableArgs ] ,
160168 localPathPDF ,
161169 markdown ,
162170 implicitFigures
@@ -173,7 +181,7 @@ export const handler = async function (
173181 const filenameTEX = `${ eachRequestData . fileName } .tex` ;
174182 const localPathTEX = `/tmp/${ filenameTEX } ` ;
175183 await generateFile (
176- [ `--template=./template.latex ` , ...variableArgs ] ,
184+ [ `--template=${ templatePath } ` , ...variableArgs ] ,
177185 localPathTEX ,
178186 markdown ,
179187 implicitFigures
0 commit comments