Gulp plugin for all in one static site building.
Last updated a month ago by akilio .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install gulp-site 
SYNC missed versions from official npm registry.


Gulp plugin for all in one static site building.

Main features:

  • generate pages from sitemap
  • compile pages with Handlebars using layouts, partials and external data
  • compile and minify styles with SASS
  • compile and minify scripts with Webpack
  • generate favicon and minify images
  • generate sitemap.xml and robots.txt


We recommend using yarn insted of npm.

yarn add gulp-site


First time site generation:

mkdir my-new-site && cd my-new-site
yarn init
yarn add gulp-site

Add to package.json scripts section:

"scripts": {
    "setup": "site init && site generate",
    "custom": "site create",
    "start": "site default",
    "build": "site build --production",
    "generate": "site generate",
    "favicon": "site favicon",
    "catalog": "site catalog"

And generate site base files and directories:

yarn setup
yarn start



You can configure gulp-site builder with config.yml

# Your project's server will run on localhost:xxxx at this port
PORT: 8000
# Your site production web-root, available in templates, but for dev will be replaced with http://localhost:<port>
ORIGIN: https://test.test

  # Additional disallow paths for generating robots.txt
    - /assets/

# Autoprefixer will make sure your CSS works with these browsers
  - "last 2 versions"
  - "ie >= 9"
  - "ios >= 7"
  - "android >= 4.4"

# Settings for UnCSS
  enabled: true # false by default, has known UNCSS bug with js execution
    - !!js/regexp ^\.is-.*

# Include this styles and scripts in all pages
  root: # will set this to {{cdn}} variable with production build
    - <script src="" integrity="sha256-36hEPcG8mKookfvUVvEqRkpdYV1unP6wvxIqbgdeVhk=" crossorigin="anonymous"></script>
    - <link rel="stylesheet" href="" integrity="sha256-vK3UTo/8wHbaUn+dTQD0X6dzidqc5l7gczvH+Bnowwk=" crossorigin="anonymous" />

# All path must be relative to your working dir
  dist: dist # destination path
  logo: src/assets/img/logo.png # at least 260x260px image or svg for favicon generation
  sitemap: src/sitemap.yml # source file for generating site pages
  pages: src/pages # site pages in .html, .json or .yaml files
  layouts: src/layouts # .html, .hbs or .handlebars layouts
	partials: src/partials # .html, .hbs or .handlebars partials
	public: src/public # this files will be copied to the root of destination
	assets: src/assets # images, styles, scripts and other required files
    data: src/data # .json, .yaml files containing data for templates
    helpers: src/helpers # .js files with helpers
    sass: [] # this paths will be available for import in your scss files
    entries: ['/js/app.js'] # scripts entry files
    styles: ['/scss/app.scss'] # styles entry files

All configuration options you can see in settings.js file in module folder.

Building blocks


Page can be defined with .html, .yml or .json file. HTML files can contain YAML Front Matter:

layout: default
url: /contact
title: Contact page
index: true
<h1>Contact page</h1>

In YAML format this will look as:

layout: default
url: /contact
title: Contact page
index: true
body: <h1>Contact page</h1>

In .yml and .json files you can define body as map of partials, where key is partial name and value data passed to partial exclusively:

	"layout": "default",
	"url": "/contact",
	"title": "Contact page",
	"index": true,
	"body": {
		"widget_map": {
			"link": "<link to my map>"
		"feedback_form": {
			"title": "Contact us!"

This body will be generated in template like this:

{{#with body.widget_map}}
	{{> widget_map}}
{{#with body.feedback_form}}
	{{> feedback_form}}

Page attributes

layout: — name of the layout file used for this page url: — page will be available by this url, for example /contact will create file at contact/index.html title: — page head title, in the default layout placed in <title>{{title}}</title> description: — page head description tag keywords: — page head keywords tag index: — boolean type, declare page indexation, indexed page (index: true) will be available in sitemap.xml with date of last file changing. Not indexed page (index: false) will de dissallowed in robots.txt og: — open graph data, used in meta.html partial provided by gulp-site. Read about it in partials. cdn: — contain js and css array properties with scripts and styles available only on this page


Layout files can have the extension .html, .hbs, or .handlebars. Default layout provided:

{{#wrap 'html5' this}}
  {{> body}}

You can customise layout by calling next command:

yarn custom layout:default

And default layout will be copied to the src/layouts/default.html All layouts have a special Handlebars partial called body which contains the contents of the page.

<!-- Header up here -->
{{> body}}
<!-- Footer down here -->


Partial files can have the extension .html, .hbs, or .handlebars. Each will be registered as a Handlebars partial which can be accessed using the name of the file. (The path to the file doesn't matter—only the name of the file itself is used.)

<!-- Renders partials/header.html -->
{{> header}}

Gulp-site provide partial {{> meta}} for meta tags generation:

<meta name="description" content="{{description}}" />
<meta name="keywords" content="{{keywords}}" />
<link rel="canonical" href="{{site.domain}}{{url}}"/>

<link rel='shortcut icon' type='image/x-icon' href='/favicon.ico'>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">

{{#if theme}}
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="{{theme.safari_tab_color}}">
<meta name="msapplication-TileColor" content="{{theme.msapp_color}}">
<meta name="theme-color" content="{{theme.color}}">

{{#if og}}
<meta property="og:type" content="{{#if og.type}}{{og.type}}{{else}}website{{/if}}" />
<meta property="og:site_name" content="{{og.site_name}}" />
<meta property="og:image:width" content="{{#if og.image_width}}{{og.image_width}}{{else}}795{{/if}}">
<meta property="og:image:height" content="{{#if og.image_wheight}}{{og.image_height}}{{else}}200{{/if}}">
<meta property="og:url" content="{{settings.origin}}">
<meta property="og:image" content="{{settings.origin}}/{{og.image}}">
<meta property="og:title" content="{{#if og.image_width}}{{og.title}}{{else}}{{title}}{{/if}}">
<meta property="og:description" content="{{#if og.image_width}}{{og.description}}{{else}}{{description}}{{/if}}">

{{#unless index}}
<meta name="robots" content="noindex, nofollow"/>

partial: wrapper

Is a special type of partials for wrapping around your code. For example html5 wrapper is contain next code:

<!doctype html>
<html class="no-js" lang="{{site.language}}">
    {{#if site.tagID}}
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= ''+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','{{site.tagID}}');</script> <!-- End Google Tag Manager -->
    {{> meta}}
    {{#if css}}
      {{#each css}}

    <link rel="stylesheet" href="{{cdn}}css/app.css?{{timestamp}}">
  {{#if site.tagID}}
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="{{site.tagID}}"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  {{#if js}}
    {{#each js}}
  <script src="{{cdn}}js/app.js?{{timestamp}}"></script>

Is is like a layout, but replace {{> body}} with {{{child}}} tag.

<!-- Wrapper start up here -->
<!-- Wrapper end down here -->


Handlebars helpers are .js files which export a function via module.exports. The name used to register the helper is the same as the name of the file.

For example, a file named content.js that exports this function would add a Handlebars helper called {{content}}.

module.exports = function(text, options) {
  return `<p>${text}</p>`

Argument options contain all data, or fn function with child elements with helper block call:


And content.js will be:

module.exports = function(text, options) {
  return '<p>' + options.fn( + '</p>';

In this context available Handlebars property if you need listing of partials or call .compile function.

Provided default next helpers: {{#code 'html'}} ... {{/code}} — highlight code examples with selected language using highlight.js {{getData 'site.tagID'}} — get data by path from the root {{getPage 'contact'}} — return page object with all data {{getPage 'contact' 'body.feedback_form'}} — return data from selected page by path {{ifEqual 'a' 'b'}} ... {{else}} ... {{/ifEqual}} — if the values are equal, content inside of the helper. If not, the content inside the {{else}} block {{#markdown}} ... {{/markdown}} — render markdown formated text to html {{repeat 3}} ... {{/repeat}} — repeate n times content inside of the helper {{#wrap 'partial_name'}} ... {{/wrap}} — use selected partial for wraping content inside tags. Partial used in wrap must contain {{{child}}} tag, rendered in root context. {{#wrap 'partial_name' withData}} ... {{/wrap}} — Partial used in wrap rendered in withData context., if withData not set used global context. For current context set this.


Data can be formatted as JSON (.json) or YAML (.yml). Within a template, the data is stored within a variable with the same name as the file it came from.

For example, a file named contact.json with key/value pairs such as the following:

    "name": "John Doe",
    "email": "",
    "phone": "555-1212"

Could be used to output the value of John Doe within a template using the Handlebars syntax of {{}}.

Data can also be inserted into the page itself with a Front Matter template at the top of the .html file or defined in .yml or .json fields of page file.

Lastly, the reserved page variable is added to every page template as it renders. It contains the name of the page being rendered, without the extension.

When generating initial setup will be provided site.yml file:

name: new site

about: short description
description: full description


Property tagID used for Google Tag Manager code placement in the default layout provided by gulp-site.

data catalog

Site data can be readed from /data/<catalog-name>/index.{yml,json,js} files. This files can be filled manual or generated by command yarn catalog --name <catalog-name>. This command output catalog data file with directory tree of this catalog.

By default output will be looked like this:

      - url: /folder1/1.jpg
        preview: /folder1/1@s.jpg
    videos: []
          - url: /folder2/subfolder1/1.jpg
            preview: /folder2/subfolder1/1@s.jpg

By default catalog generator copy media files to /src/public/content/<catalog-name> folder, for images also make a preview with size 120x120px.

You can configure output by add settings.yml file on any level of catalog and this options will be applied to this folder.

Available options: prefix - string prepended the folder name in result index.yml file. flatItems - do not place child items in items key, each of child will be placed on the folder root level. dataTemplate - object fields appended to result folder object. Work as template with ${keyname} style (warning: filled one by one by declaration order). Available two default variable: ${itemDirName}, ${parentDirName}. subSettings - settings applied to the each subfolders. If subfolder has own settings file this one merged with this options, but own subdolder settings has priority.

Current Tags

  • 0.4.7                                ...           latest (a month ago)

19 Versions

  • 0.4.7                                ...           a month ago
  • 0.4.6                                ...           a month ago
  • 0.4.5                                ...           a month ago
  • 0.4.4                                ...           2 months ago
  • 0.4.3                                ...           3 months ago
  • 0.4.1                                ...           3 months ago
  • 0.4.0                                ...           3 months ago
  • 0.3.2                                ...           3 months ago
  • 0.3.1                                ...           9 months ago
  • 0.3.0                                ...           9 months ago
  • 0.2.1                                ...           9 months ago
  • 0.1.7                                ...           a year ago
  • 0.1.6                                ...           a year ago
  • 0.1.5                                ...           a year ago
  • 0.1.4                                ...           a year ago
  • 0.1.3                                ...           a year ago
  • 0.1.2                                ...           a year ago
  • 0.1.1                                ...           a year ago
  • 0.1.0                                ...           a year ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 17
Dependencies (48)
Dev Dependencies (0)
Dependents (1)

Copyright 2014 - 2016 © |