@@ -30,54 +30,56 @@ export const makeTwigHandler = ({
3030 addImageSuffix ,
3131 ]
3232
33- return ( ) => subpipe ( ( stream ) => {
33+ return async ( ) => {
3434 // share twig logic for `twig-as-entrypoint` and `frontmatter-as-entrypoint` (collections)
3535 const extraLogic = {
3636 functions : undefined ,
3737 filters : undefined ,
3838 }
3939 if ( twig . logicLoader ) {
40- const logic = twig . logicLoader ( )
40+ const logic = await twig . logicLoader ( )
4141 if ( logic . functions ) {
4242 extraLogic . functions = logic . functions
4343 }
4444 if ( logic . filters ) {
4545 extraLogic . filters = logic . filters
4646 }
4747 }
48- return stream
49- . pipe ( twigGulp ( {
50- base : paths . html ,
51- extend : twig && twig . extend ,
52- functions : [
53- ...extendedTwigFunctions ,
54- ...( twig && twig . functions ? twig . functions : [ ] ) ,
55- ...( extraLogic . functions || [ ] ) ,
56- ] ,
57- filters : [
58- ...( twig && twig . filters ? twig . filters : [ ] ) ,
59- ...( extraLogic . filters || [ ] ) ,
60- ] ,
61- extname : twig && typeof twig . outputExtname !== 'undefined' ? twig . outputExtname : '.html' ,
62- cache : ! ! ( twig && twig . cache ) ,
63- debug : ! ! ( twig && twig . debug ) ,
64- trace : ! ! ( twig && twig . trace ) ,
65- } ) )
66- // middlewares after twig compilation
67- // middlewares for style injection
68- . pipe ( injectCSS ( {
69- paths, injectTag : cssInjectTag ,
70- failOnSize : process . env . NODE_ENV === 'production' ,
71- cssBuffer : cssBuffer ,
72- } ) )
73- // middlewares after CSS injection
74- . pipe ( cleanHtmlCss ( {
75- minifyHtml,
76- cleanInlineCSS,
77- cleanInlineCSSWhitelist,
78- } ) )
79- . pipe ( ampOptimizer ( ampOptimize ) )
80- } )
48+ return subpipe ( ( stream ) =>
49+ stream
50+ . pipe ( twigGulp ( {
51+ base : paths . html ,
52+ extend : twig && twig . extend ,
53+ functions : [
54+ ...extendedTwigFunctions ,
55+ ...( twig && twig . functions ? twig . functions : [ ] ) ,
56+ ...( extraLogic . functions || [ ] ) ,
57+ ] ,
58+ filters : [
59+ ...( twig && twig . filters ? twig . filters : [ ] ) ,
60+ ...( extraLogic . filters || [ ] ) ,
61+ ] ,
62+ extname : twig && typeof twig . outputExtname !== 'undefined' ? twig . outputExtname : '.html' ,
63+ cache : Boolean ( twig && twig . cache ) ,
64+ debug : Boolean ( twig && twig . debug ) ,
65+ trace : Boolean ( twig && twig . trace ) ,
66+ } ) )
67+ // middlewares after twig compilation
68+ // middlewares for style injection
69+ . pipe ( injectCSS ( {
70+ paths, injectTag : cssInjectTag ,
71+ failOnSize : process . env . NODE_ENV === 'production' ,
72+ cssBuffer : cssBuffer ,
73+ } ) )
74+ // middlewares after CSS injection
75+ . pipe ( cleanHtmlCss ( {
76+ minifyHtml,
77+ cleanInlineCSS,
78+ cleanInlineCSSWhitelist,
79+ } ) )
80+ . pipe ( ampOptimizer ( ampOptimize ) ) ,
81+ )
82+ }
8183}
8284
8385export const makeHtmlTask = (
@@ -94,31 +96,41 @@ export const makeHtmlTask = (
9496 const htmlTasks = [ ]
9597
9698 const twigHandler = makeTwigHandler ( { paths, twig, ...options } )
97- htmlTasks . push ( function pagesByTemplates ( ) {
98- return gulp . src ( paths . htmlPages + '/*.twig' )
99- . pipe ( twigDataHandler ( twig ) )
100- . pipe ( twigHandler ( ) )
101- . pipe ( gulp . dest ( paths . dist ) )
102- . pipe ( browsersync . stream ( ) )
103- } )
99+ htmlTasks . push (
100+ function pagesByTemplates ( ) {
101+ return new Promise ( async ( resolve , reject ) => {
102+ gulp . src ( paths . htmlPages + '/*.twig' )
103+ . pipe ( twigDataHandler ( twig ) )
104+ . pipe ( await twigHandler ( ) )
105+ . pipe ( gulp . dest ( paths . dist ) )
106+ . pipe ( browsersync . stream ( ) )
107+ . on ( 'finish' , resolve )
108+ . on ( 'error' , reject )
109+ } )
110+ } ,
111+ )
104112
105113 if ( collections && Array . isArray ( collections ) ) {
106114 collections . forEach ( collection => {
107115 htmlTasks . push (
108116 function pagesByFrontmatter ( ) {
109- return gulp . src ( collection . data )
110- . pipe ( twigMultiLoad (
111- {
112- ...twig ,
113- ...( collection . fmMap ? { fmMap : collection . fmMap } : { } ) ,
114- ...( collection . customMerge ? { customMerge : collection . customMerge } : { } ) ,
115- } ,
116- collection . tpl ,
117- ) )
118- . pipe ( twigHandler ( ) )
119- . pipe ( twigMultiSave ( collection . ext ) )
120- . pipe ( gulp . dest ( path . join ( paths . dist , collection . base ) ) )
121- . pipe ( browsersync . stream ( ) )
117+ return new Promise ( async ( resolve , reject ) => {
118+ gulp . src ( collection . data )
119+ . pipe ( twigMultiLoad (
120+ {
121+ ...twig ,
122+ ...( collection . fmMap ? { fmMap : collection . fmMap } : { } ) ,
123+ ...( collection . customMerge ? { customMerge : collection . customMerge } : { } ) ,
124+ } ,
125+ collection . tpl ,
126+ ) )
127+ . pipe ( await twigHandler ( ) )
128+ . pipe ( twigMultiSave ( collection . ext ) )
129+ . pipe ( gulp . dest ( path . join ( paths . dist , collection . base ) ) )
130+ . pipe ( browsersync . stream ( ) )
131+ . on ( 'finish' , resolve )
132+ . on ( 'error' , reject )
133+ } )
122134 } ,
123135 )
124136 } )
0 commit comments