@@ -9,9 +9,23 @@ import postcssrc from 'postcss-load-config'
99import posthtml from 'posthtml'
1010import posthtmlBaseURL from 'posthtml-base-url'
1111import { transform as sucraseTransform } from 'sucrase'
12- import { compile as templateCompile } from 'tempura '
12+ import Mustache from 'mustache '
1313import glob from 'tiny-glob'
1414
15+ const compileTemplate = ( layout ) => ( vars ) => Mustache . render ( layout , vars )
16+
17+ const htmlProcessor = async ( baseHTML , options ) => {
18+ return (
19+ await posthtml ( [
20+ posthtmlBaseURL ( {
21+ url : options . baseUrl ,
22+ allTags : true ,
23+ } ) ,
24+ htmlnano ( ) ,
25+ ] ) . process ( baseHTML )
26+ ) . html
27+ }
28+
1529const markdownTransfomer = ( options ) => ( {
1630 transform : async ( code , file ) => {
1731 const { frontmatter, content } = getFrontmatter ( code )
@@ -33,11 +47,11 @@ const markdownTransfomer = (options) => ({
3347 vars ,
3448 )
3549 : options . layoutTemplate
36-
3750 baseHTML = await layoutTemplate ( vars )
3851 } else if ( options . layoutTemplate ) {
3952 baseHTML = await options . layoutTemplate ( {
4053 content : sourceHTML ,
54+ ...vars ,
4155 } )
4256 }
4357 } else {
@@ -46,14 +60,7 @@ const markdownTransfomer = (options) => ({
4660 } )
4761 }
4862
49- const output = await posthtml ( [
50- posthtmlBaseURL ( {
51- url : options . baseUrl ,
52- allTags : true ,
53- } ) ,
54- htmlnano ( ) ,
55- ] ) . process ( baseHTML )
56- return output . html
63+ return htmlProcessor ( baseHTML , options )
5764 } ,
5865 ext : '.html' ,
5966} )
@@ -66,14 +73,7 @@ const htmlTranformer = (options) => ({
6673 content : code ,
6774 } )
6875 }
69- const output = await posthtml ( [
70- posthtmlBaseURL ( {
71- url : options . baseUrl ,
72- allTags : true ,
73- } ) ,
74- htmlnano ( ) ,
75- ] ) . process ( toCompile )
76- return output . html
76+ return htmlProcessor ( toCompile , options )
7777 } ,
7878 ext : '.html' ,
7979} )
@@ -130,17 +130,15 @@ export async function compile(basePath, distPath, options) {
130130 baseUrl : options . baseUrl ,
131131 jsxImportSource : options . jsxImportSource ,
132132 }
133- const layoutSource = options . layoutFile ?? join ( basePath , '_layout.hbs' )
133+ const layoutSource =
134+ options . layoutFile ?? join ( basePath , '_layout.mustache' )
134135 const layoutExists = await fs . promises
135136 . access ( layoutSource )
136137 . then ( ( _ ) => true )
137138 . catch ( ( _ ) => false )
138139 if ( layoutExists ) {
139- const templateContent = `
140- {{#expect content}}
141- ${ await fs . promises . readFile ( layoutSource , 'utf8' ) }
142- `
143- transformerOptions . layoutTemplate = templateCompile ( templateContent )
140+ const templateContent = `${ await fs . promises . readFile ( layoutSource , 'utf8' ) } `
141+ transformerOptions . layoutTemplate = compileTemplate ( templateContent )
144142 }
145143
146144 const files = (
@@ -152,7 +150,7 @@ ${await fs.promises.readFile(layoutSource, 'utf8')}
152150 ) . filter (
153151 ( d ) =>
154152 d != resolve ( layoutSource ) &&
155- ! d . endsWith ( '.hbs ' ) &&
153+ ! d . endsWith ( '.mustache ' ) &&
156154 ! d . startsWith ( resolve ( 'node_modules' ) ) &&
157155 ( distPath ? ! d . startsWith ( resolve ( distPath ) ) : true ) ,
158156 )
@@ -227,10 +225,7 @@ async function prepareFrontmatterTemplate(pathToFile, file, vars) {
227225 throw new Error ( `Invalid layout provided for file:${ file } ` )
228226 }
229227 const layout = await fs . promises . readFile ( pathToFile , 'utf8' )
230- const withExpects = `{{#expect ${ Object . keys ( vars ) . filter ( Boolean ) . join ( ', ' ) } }}
231- ${ layout } `
232-
233- return templateCompile ( withExpects )
228+ return compileTemplate ( layout )
234229}
235230
236231function getFrontmatter ( code ) {
0 commit comments