import juice from "juice" ; import WebsiteGenerator from "../website" ; import JSONUtils from "../../json" ; import Templating from "../../templating" ; import Promise from "../../utils/promise" ; param { Output } output param { string } type return { string } function getPDFTemplate ( output , type ) { const filePath = `pdf_${ type }.html` ; const outputRoot = output . getRoot ( ) ; const engine = WebsiteGenerator . createTemplateEngine ( output , filePath ) ; const context = JSONUtils . encodeOutput ( output ) ; context . page = { num : "_PAGENUM_" , title : "_SECTION_" , } ; return ( Templating . renderFile ( engine , `ebook/${ filePath }` , context ) . then ( ( tplOut ) => { return Promise . nfcall ( juice . juiceResources , tplOut . getContent ( ) , { webResources : { relativeTo : outputRoot , } , } ) ; } ) . then ( ( tplOut ) => tplOut . replace ( /\n/g , " " ) ) ) ; } export default getPDFTemplate ;