0.19.0 • Published 1 month ago

@hidoo/gulp-task-build-html-handlebars v0.19.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

@hidoo/gulp-task-build-html-handlebars

Task that build html by handlebars for gulp.

Installation

$ npm install --save-dev gulp@next @hidoo/gulp-task-build-html-handlebars

Usage

import { task } from 'gulp';
import buildHtml from '@hidoo/gulp-task-build-html-handlebars';

task(
  'html',
  buildHtml({
    src: '/path/to/html/*.hbs',
    dest: '/path/to/dest'
  })
);

API

buildHtml

return html build task by handlebars

Parameters

Examples

import { task } from 'gulp';
import buildHtml from '@hidoo/gulp-task-build-html-handlebars';

task(
  'html',
  buildHtml({
    name: 'html:main',
    src: '/path/to/html/*.hbs',
    dest: '/path/to/dest',
    extname: '.php',
    partials: '/path/to/html/partials/*.hbs',
    layouts: '/path/to/html/layouts/*.hbs',
    helpers: '/path/to/html/helpers/*.js',
    data: '/path/to/html/data/*.{json,yaml}',
    compress: {
      htmlmin: {
        caseSensitive: true,
        collapseWhitespace: true,
        conservativeCollapse: true,
        preserveLineBreaks: true,
        ignoreCustomFragments: [
          // php start end tags
          /<\?[\s\S]*?\?>/,
          // cms tags
          /<\/?mt:?[\s\S]*?>/i,
          /<\$mt:?[\s\S]*?\$>/i
        ]
      }
    },
    onFilesParsed: (context) => context,
    onFrontMatterParsed: (context) => context,
    verbose: false
  })
);

Returns Function[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)

Template API

Builtin Helpers

See @hidoo/handlebars-helpers.

Template context

global:

nameexampledescription
NODE_ENV{{#is NODE_ENV 'production'}}...{{/is}}string of process.env.NODE_ENV
compress{{#if compress}}...{{/if}}value of options.compress
pages{{#each pages}}...{{/each}}array of Front Matter for all pages

path (when file is subdir/index.hbs):

nameexampledescription
path.depth{{path.depth}} => ../depth of file from options.src
path.relative{{path.relative}} => subdir/index.htmlrelative path of file from options.src
path.basename{{path.basename}} => index.htmlbasename of file
path.extname{{path.extname}} => .htmlextname of file

Test

$ pnpm test

License

MIT

1.0.0-alpha.1

1 month ago

1.0.0-alpha.0

3 months ago

0.19.0

3 years ago

0.18.0

3 years ago

0.17.0

3 years ago

0.16.0

3 years ago

0.15.0

4 years ago

0.14.1

4 years ago

0.14.0

4 years ago

0.13.0

5 years ago

0.12.0

5 years ago

0.11.0

5 years ago

0.10.0

5 years ago

0.9.0

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago