Skip to content

Instantly share code, notes, and snippets.

@DanielaValero
Created June 26, 2016 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielaValero/856852eb325e1b8898ace4ddde7fc5cc to your computer and use it in GitHub Desktop.
Save DanielaValero/856852eb325e1b8898ace4ddde7fc5cc to your computer and use it in GitHub Desktop.
import assemble from 'assemble';
import assembleConfig from '../config/assemble-config.js';
import markdownHelper from 'helper-markdown';
import helpers from 'handlebars-helpers';
import hbs from 'engine-handlebars';
import gutil from 'gulp-util';
import platformConfig from '../config/platform-config.js';
import yaml from 'js-yaml';
import fs from 'fs';
import collections from 'assemble-collections';
const paths = platformConfig.paths;
const app = assemble();
// Reads the data in the concatenated file and parses it as object
function parseData(options) {
const dataFile = `${options.data.dest}/${options.data.fileName}`;
const data = yaml.load(fs.readFileSync(dataFile)
.toString());
return data;
}
function loadCommon() {
app.engine('hbs', hbs);
app.helper('markdown', markdownHelper);
app.helpers(helpers());
app.use(collections());
app.on('error', (err) => {
gutil.log(err);
});
app.helper('log', (context) => {
gutil.log(context);
});
}
function load(options) {
loadCommon();
app.option('layout', assembleConfig.defaultLayout);
app.layouts(options.layouts);
app.partials(options.partials);
// This creates a collection in assemble
// it will be available for us to call as a function
// which argument's list is an object
app.create(options.collectionName);
app[options.collectionName](options.pages);
app.data('data', parseData(options));
}
function craft($, options) {
return app.toStream(options.collectionName)
.on('error', (err) => {
gutil.log(err);
})
.pipe($.newer(`${paths.tmp}/${options.collectionName}`))
.pipe($.plumber())
.pipe(app.renderFile())
.pipe($.extname())
.on('error', (err) => {
gutil.log(err);
})
.pipe($.size({
title: `html: ${options.collectionName}`,
}))
.pipe(app.dest(options.dest));
}
function loadDocumentation(cb) {
load(assembleConfig.documentation);
cb();
}
function craftDocumentation($) {
return craft($, assembleConfig.documentation);
}
export default {
craftDocumentation,
loadDocumentation,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment