Esempio n. 1
0
module.exports = function (metalsmith) {

  return metalsmith
  .use(metadata({
    me: sepify("data/me.yaml"),
    conf: sepify("data/env/" + env + "/conf.yaml")
  }))
  .use(define({
    now: Date.now()
  }))
  .use(collections({
    blogs: {
      pattern: 'blog/*.md',
      // sortBy: 'date',
      // reverse: true
    }
  }))
  .use(templates({
    engine: "handlebars",
    inPlace: true
  }))
  .use(markdown())
  .use(permalinks())
  .use(templates({
    default: "default.hbs",
    directory: "templates",
    engine: "handlebars"
  }))
  // .use(watch({
  //   // <script src="http://localhost:35729/livereload.js"></script>
  //   livereload: true
  // }))
}
Esempio n. 2
0
module.exports = function metalSmith() {

  // Debug Helper. Type {{ debug }} to log current context.
  Handlebars.registerHelper("debug", function(optionalValue) {
    console.log("Current Context");
    console.log("====================");
    console.log(this);
    if (optionalValue) {
      console.log("Value");
      console.log("====================");
      console.log(optionalValue);
    }
  });

  // Helper to add logical operaters to the if condition
  Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
    switch (operator) {
      case '==':
        return (v1 == v2) ? options.fn(this) : options.inverse(this);
      case '===':
        return (v1 === v2) ? options.fn(this) : options.inverse(this);
      case '<':
        return (v1 < v2) ? options.fn(this) : options.inverse(this);
      case '<=':
        return (v1 <= v2) ? options.fn(this) : options.inverse(this);
      case '>':
        return (v1 > v2) ? options.fn(this) : options.inverse(this);
      case '>=':
        return (v1 >= v2) ? options.fn(this) : options.inverse(this);
      case '&&':
        return (v1 && v2) ? options.fn(this) : options.inverse(this);
      case '||':
        return (v1 || v2) ? options.fn(this) : options.inverse(this);
      default:
        return options.inverse(this);
    }
  });

  // Register all partials in `template/partials`
  _.each(fs.readdirSync('templates/partials'),function(file) {
    var name = file.split(".")[0];
    var contents = fs.readFileSync(__dirname+"/templates/partials/"+file).toString();
    Handlebars.registerPartial(name, contents);
  });

  Metalsmith(__dirname)
    .use(markdown())
    .use(templates('handlebars'))
    .use(sass({
      outputDir: 'css/'
    }))
    .destination('./dist') 
    .build(function(err, files) {
      if (err) {
        console.log(err);
      } else {
        console.log('Forged!');
      }
    });
};
Esempio n. 3
0
function forge() {
  new Metalsmith(__dirname)
    .metadata({
      siteTitle: 'erickbrower\'s blog',
      headline: 'erickbrower',
      tagline: 'I write code. A lot.',
      author: 'Erick Brower <*****@*****.**>',
      description: 'My personal blog. @erickbrower'
    })
    .source('./src')
    .destination('./public')
    .use(ignore('drafts/*'))
    .use(plugins.bodyParser)
    .use(plugins.dateFormatter)
    .use(collections({
      posts: {
        pattern: 'content/posts/*.md',
        sortBy: 'date',
        reverse: true
      },
      pages: {
        pattern: 'content/pages/*.md',
        sortBy: 'title'
      }
    }))
    .use(markdown())
    .use(permalinks(':collection/:title'))
    .use(templates('handlebars'))
    .use(plugins.lunrIndexer)
    .use(plugins.jsonWriter)
    .build();
}
 setup: function(){
   return Metalsmith(__dirname)
         .use(drafts())
         .use(tags({
             handle: 'tags',
             path:'topics/:tag.html',
             template: 'tag.hbt',
             sortBy: "date",
             reverse : true
         }))
         .use(markdown())
         .use(collections({
             articles: {
               pattern: './published/*.md',
               sortBy: 'date',
               reverse: true
             }
           }))
         .use(permalinks('posts/:title'))
         .use(templates('handlebars'))
         .use(assets({
             source: './assets',
             destination: './assets'
           }))
         .destination('./build')
         .build(function(err, files) {
                 if (err) {
                   console.log(err)
                   throw err;
                 } else{
                   console.log("Build was successful")
                 }
             });
 }
Esempio n. 5
0
var build = function (cb) {
  metalsmith(__dirname)
    .use(date())
    .use(collections({
      posts: {
        pattern: 'posts/*.md',
        sortBy: 'date',
        reverse: true
      }
    }))
    .use(markdown())
    .use(permalinks({
      pattern: ':title'
    }))
    .use(templates({
      engine: 'swig',
      directory: 'templates'
    }))
    .source('contents')
    .destination('build')
    .build(function(err) {
      if (err) throw err;
      cb();
    });
};
Esempio n. 6
0
/**
 * Build a template.
 * TODO: move to module.
 *
 * @param {String} tn
 * @api private
 */
function buildTemplate(tn) {
  assert('string' == typeof tn, 'TemplateName should be a string');

  var outDir = 'index' == tn ? '' : tn;

  var metalPipe = gulpsmith()
    .use(highlight())
    .use(markdown({
      smartypants: true,
      gfm: true
    }))
    .use(templates({
      engine: 'mustache',
      directory: 'content/' + tn
    }));

  function parseFile(file) {
    assign(file, {template: 'index.html'});
    delete file.frontMatter;
  }

  gulp
    .src(docs[tn])
    .pipe(frontMatter()).on('data', parseFile)
    .pipe(metalPipe)
    .pipe(gulp.dest('./build/' + outDir));
}
Esempio n. 7
0
 metalsmith: function (done) {
   metalsmith(join(__dirname, 'docs'))
     .metadata({ baseUri: argv.baseUri })
     .use(markdown())
     .use(templates('handlebars'))
     .build(done);
 },
Esempio n. 8
0
// build docs
function buildDocs(done, dev) {
  var site_url = siteUrl;
  if (dev) {
    site_url = siteUrlDev;
  }

  Metalsmith(__dirname)
    .source(paths.docs_generated)
    .destination(paths.target_docs)

    // do not remove files already in the target directory
    .clean(false)

    // define global variables for templates
    .use(define({
      "site_url": site_url
    }))

    // apply templates
    .use(templates({
      engine: "swig",
      directory: paths.templates,
      pattern: "**/*.html"
    }))

    // build site
    .build(done);
}
Esempio n. 9
0
    it('should generate multiple files from the results of the collection prismic query using a custom linkResolver and a custom htmlSerializer', function(done){
        Metalsmith('test/fixtures/collection-linkResolver-htmlSerializer')
            .use(prismic({
                "url": "http://lesbonneschoses.prismic.io/api",
                "linkResolver": function (ctx, doc) {
                    if (doc.isBroken) return false;
                    return '/' + doc.type + '/' + doc.slug + (ctx.maybeRef ? '?ref=' + ctx.maybeRef : '');
                },
                "htmlSerializer": function( elem, content ) {
                    if (elem.type == "heading1") {
                        return '<h1 class="test-h1-class">' + content + '</h1>';
                    }
                }
            }))
            // use Handlebars templating engine to insert content
            .use(templates({
                "engine": "handlebars"
            }))

            .build(function(err){
                if (err) return done(err);
                equal('test/fixtures/collection-linkResolver-htmlSerializer/expected', 'test/fixtures/collection-linkResolver-htmlSerializer/build');
                done();
            });
    });
Esempio n. 10
0
gulp.task('smith', function () {
  var defered = q.defer();

  MetalSmith(__dirname)
    .use(ignore(['**/_*.scss', '**/.**.**.swp', '**/.DS*']))
    .use(previewIndexes())
    .use(url())
    .use(tree())
    .use(collection({
      templates: 'templates/**/index.html'
    }))
    .use(sass({
      outputStyle: "expanded"
    }))
    .use(autoprefixer())
    .use(templates({
      engine: 'handlebars',
      directory: 'layouts'
    }))
    .destination(tmp)
    .build(function () {
      return defered.resolve.apply(defered, arguments);
    });

  return defered.promise;
});
Esempio n. 11
0
gulp.task('build:docs', function() {

  var sortComponents = new Sort(config.docs.sort.components);

  return gulp.src(config.docs.all.src)
    .pipe(frontMatter()).on('data', function(file) {
      _.assign(file, file.frontMatter);
      delete file.frontMatter;
    })
    .pipe(gulpsmith()
      .use(define({
        pkg: require('../../package.json')
      }))
      .use(collections({
        pages: {
          sortBy: 'menu',
          reverse: false
        },
        components: {
          pattern: '*-component.html',
          sortBy: function(a, b) {
            return sortComponents.sort.call(sortComponents, a, b);
          }
        },
        javascript: {
          pattern: '*-javascript.html'
        },
        examples: {} // empty pattern because the pages are tagged with collection attribute in YAML front matter
      }))
      .use(metalsmithPaths())
      .use(metalsmithPrism())
      .use(metalsmithMock())
      .use(metalsmithMarkdown())
      .use(templates({
        engine: 'handlebars',
        directory: config.docs.templates.src
      }))
      .on('error', console.log.bind(console))
    )
    // only include full pages and ignore page snippets in dest build folder
    .pipe(filter(['*', '!**/*-component.html', '!**/*-javascript.html']))
    .pipe(gulpif(config.args.verbose, using({prefix: 'build:docs [dest] using'})))
    .pipe(rename(function(file) {
      if (!/\.hbs/.test(file.extname)) {
        return;
      }
      file.extname = '.html';
    }))
    .pipe(gulp.dest(config.docs.dest))
    .pipe(reload({stream: true}));

});
 it('should create tag page with post lists according to template and sorted by date decreasing', function(done) {
   Metalsmith('test/fixtures')
     .use(tags({
       handle: 'tags',
       path: 'topics/:tag.html',
       template: './tag.hbt',
       sortBy: 'date',
       reverse: true
     }))
     .use(templates(templateConfig))
     .build(function(err){
       if (err) return done(err);
       equal('test/fixtures/expected/no-pagination/topics', 'test/fixtures/build/topics');
       done();
     });
 });
Esempio n. 13
0
gulp.task('build:html', function () {
	return gulp.src(['./pages/**/*.md', './config.yaml'])
		.pipe(frontMatter().on('data', function (file) {
			_.assign(file, file.frontMatter);
			delete file.frontMatter;
		}))
		.pipe(gulpsmith()
			.use(metadata({
				config: 'config.yaml'
			}))
			.use(collections({
				projects: {
					pattern: 'projects/*.md'
				}
			}))
			.use(updateProjectsFromGithub({
				clientId: process.env.UPDATE_PROJECTS_FROM_GITHUB_CLIENT_ID,
				secret: process.env.UPDATE_PROJECTS_FROM_GITHUB_SECRET,
				sortBy: 'stars',
				reverse: true
			}))
			.use(markdown())
			.use(permalinks())
			.use(templates({
				engine: 'jade',
				stringify: function(obj) {
					var cache = [];
					var str = JSON.stringify(obj, function(key, value) {
						if (typeof value === 'object' && value !== null) {
							if (cache.indexOf(value) !== -1) {
								// Circular reference found, discard key
								return;
							}
							// Store value in our collection
							cache.push(value);
						}
						return value;
					});
					cache = null; // Enable garbage collection
					return str;
				}
			}))
		)
		.pipe(debug({title: 'build:html'}))
		.pipe(livereload())
		.pipe(gulp.dest('./dist'));
});
Esempio n. 14
0
function plugins(khaos) {
  var fns = [];

  /**
   * Template the file names.
   *
   * @param {Object} files
   * @param {Metalsmith} metalsmith
   */

  fns.push(function(files, metalsmith){
    var metadata = metalsmith.metadata();
    var filenames = extend({}, files);
    for (var file in filenames) {
      var data = files[file];
      var fn = handlebars.compile(file);
      var clone = extend({}, data, metadata);
      var str = fn(clone);
      var i = file.indexOf('{{');
      delete files[file];
      if (str == file.slice(0, i)) continue;
      files[str] = data;
    }
  });

  /**
   * Template the file contents.
   *
   * @param {Object} files
   * @param {Metalsmith} metalsmith
   */

  fns.push(templates({
    engine: 'handlebars',
    helpers: khaos.helpers(),
    inPlace: true,
    pattern: '!*.hbs'
  }));

  /**
   * Return.
   */

  return fns;
}
Esempio n. 15
0
    it.skip('should not allow more than one query to be a collection prismic query', function(done){
        Metalsmith('test/fixtures/collection-invalid')
            .use(prismic({
                "url": "http://lesbonneschoses.prismic.io/api"
            }))

            //.use (log())

            // use Handlebars templating engine to insert content
            .use(templates({
                "engine": "handlebars"
            }))

            .build(function(err){
                if (err) return done(err);
                done();
            });
    });
Esempio n. 16
0
    it('should handle slice fragments', function(done){
        Metalsmith('test/fixtures/slices')
            .use(prismic({
                "url": "http://api-test.prismic.io/api"
            }))

            //.use (log())

            // use Handlebars templating engine to insert content
            .use(templates({
                "engine": "handlebars"
            }))

            .build(function(err){
                if (err) return done(err);
                equal('test/fixtures/slices/expected', 'test/fixtures/slices/build');
                done();
            });
    });
Esempio n. 17
0
    it('should override pageSize and retrieve all documents with allPages option', function(done){
        Metalsmith('test/fixtures/appPages')
            .use(prismic({
                "url": "http://lesbonneschoses.prismic.io/api"
            }))

            //.use (log())

            // use Handlebars templating engine to insert content
            .use(templates({
                "engine": "handlebars"
            }))

            .build(function(err){
                if (err) return done(err);
                equal('test/fixtures/appPages/expected', 'test/fixtures/appPages/build');
                done();
            });
    });
Esempio n. 18
0
    it('should retrieve max number of documents specified by pageSize', function(done){
        Metalsmith('test/fixtures/pageSize')
            .use(prismic({
                "url": "http://lesbonneschoses.prismic.io/api"
            }))

            //.use (log())

            // use Handlebars templating engine to insert content
            .use(templates({
                "engine": "handlebars"
            }))

            .build(function(err){
                if (err) return done(err);
                equal('test/fixtures/pageSize/expected', 'test/fixtures/pageSize/build');
                done();
            });
    });
Esempio n. 19
0
    it('should handle fetch link content', function(done){
        Metalsmith('test/fixtures/fetchLinks')
            .use(prismic({
                "url": "http://lesbonneschoses.prismic.io/api"
            }))

            //.use (log())

            // use Handlebars templating engine to insert content
            .use(templates({
                "engine": "handlebars"
            }))

            .build(function(err){
                if (err) return done(err);
                equal('test/fixtures/fetchLinks/expected', 'test/fixtures/fetchLinks/build');
                done();
            });
    });
Esempio n. 20
0
module.exports = function metalSmith(){
  return Metalsmith(__dirname)
    .use(drafts())
    .use(collections({
      pages: {
        pattern: 'content/pages/*.md'
      },
      blog: {
          pattern: 'content/blog/*.md',
          sortBy: 'date',
          reverse: true
      },
      projects: {
          pattern: 'content/projects/*.md',
          sortBy: 'position'
      },
      projets: {
          pattern: 'content/projets/*.md',
          sortBy: 'position'
      }
    }))
    .use(include())
    .use(markdown({
      "gfm": true
        }
      ))
    .use(excerpts())
    .use(stylus())
    .use(permalinks({
       pattern: ':lang/:collection/:title',
       relative: false
    }))
    .use(templates({
        engine: 'jade',
        moment: moment
        }))
    // .use(inspect())
    .destination('./build')
    .build(function(err,files){
      if (err){ console.log(err); }
    });
};
Esempio n. 21
0
    it('should render release ref', function(done){
        Metalsmith('test/fixtures/preview')
            .use(prismic({
                "url": "http://lesbonneschoses.prismic.io/api",
                "release": "UlfoxUnM08QWYXdk"  // New SF Shop release
            }))

            // .use (log())

            // use Handlebars templating engine to insert content
            .use(templates({
                "engine": "handlebars"
            }))

            .build(function(err){
                if (err) return done(err);
                equal('test/fixtures/preview/expected', 'test/fixtures/preview/build');
                done();
            });
    });
Esempio n. 22
0
  function (done) {
    var ms = metalsmith(config('docs.basepath'))
      .source(config('docs.source'))
      .destination(config('docs.destination'))
      .use(metalsmithMarkdown({
        sanitize: false
      }))
      .use(metalsmithTemplates(config('docs.templateEngine')));

    if (cmd.watch) {
      ms.use(metalsmithWatch());
    }

    ms.build(function (err) {
      if (err) {
        throw err;
      }
      done();
    });
  },
Esempio n. 23
0
module.exports = gulp.task('metalsmith', function(cb) {

  var m = Metalsmith(__dirname);
  m.source('../content');

  m.use(metadata(metadata));

  m.use(collections({
    mainStory: {
      pattern: 'story/home/*.md',
      sortBy: 'flow'
    }
    // gridGallery: {
    //   pattern: 'collections/grid-gallery/*.md'
    // }
  }));

  m.use(excerpts());

  m.use(markdown({
    gfm: true,
    tables: true,
    breaks: true,
    smartLists: true,
    smartypants: true
  }));

  m.use(permalinks());

  m.use(templates({
    engine: 'handlebars',
    directory: '../templates'
  }));

  m.destination('../build');
  m.build(function(err) {
    if (err) return console.error(err);
    cb();
  });

});
Esempio n. 24
0
    it('should generate links with the custom linkResolver', function(done){
        Metalsmith('test/fixtures/linkResolver')
            .use(prismic({
                "url": "http://lesbonneschoses.prismic.io/api",
                "linkResolver": function (ctx, doc) {
                    if (doc.isBroken) return false;
                    return '/' + doc.type + '/' + doc.slug + (ctx.maybeRef ? '?ref=' + ctx.maybeRef : '');
                }
            }))

            //.use (log())

            // use Handlebars templating engine to insert content
            .use(templates({
                "engine": "handlebars"
            }))

            .build(function(err){
                if (err) return done(err);
                equal('test/fixtures/linkResolver/expected', 'test/fixtures/linkResolver/build');
                done();
            });
    });
Esempio n. 25
0
    it('should generate multiple files from the results of the collection prismic query', function(done){
        Metalsmith('test/fixtures/collection')
            .use(prismic({
                "url": "http://lesbonneschoses.prismic.io/api",
                "linkResolver": function (ctx, doc) {
                    if (doc.isBroken) return false;
                    return '/' + doc.type + '/' + doc.id.toLowerCase() + '/' + doc.slug + (ctx.maybeRef ? '?ref=' + ctx.maybeRef : '');
                }
            }))

            //.use (log())

            // use Handlebars templating engine to insert content
            .use(templates({
                "engine": "handlebars"
            }))

            .build(function(err){
                if (err) return done(err);
                equal('test/fixtures/collection/expected', 'test/fixtures/collection/build');
                done();
            });
    });
Esempio n. 26
0
/**
 * Helper.
 *
 * Invoke Metalsmith.
 */
function metalsmith(options, done) {
    Metalsmith(root)
        .destination(options.destination || 'build')
        .use(metadata({
            meta: options.meta || 'meta.yaml'
        }))
        .use(sass({
            outputStyle: 'compressed',
            includePaths: eggshell.includePaths,
            outputDir: 'assets/css'
        }))
        .use(collections(docs))
        .use(collectionMeta)
        .use(markdown({
            gfm: true,
            highlight: function(code, lang) {
                if (lang) return highlight.highlight(lang, code).value;
                return highlight.highlightAuto(code).value;
            }
        }))
        .use(permalinks({
            pattern: ':collection/:title'
        }))
        .use(buildId)
        .use(promote)
        .use(templates('jade'))
        .use(ignore([
            '**/_*',
            '*.yaml'
        ]))
        .use(beautify({
            js: false,
            css: false
        }))
        // .use(_debug)
        .build(done);
}
Esempio n. 27
0
  .use(feed({
    collection: 'posts',
    destination: 'rss/rss.xml',
    postDescription: function(file) {
      return file.contents;
    }
  }))

  /**
   * Render pages
   */
  .use(templates({
    engine: 'handlebars',
    directory: 'templates',
    partials: {
      nav: 'partials/nav',
      archive: 'partials/archive',
      header: 'partials/header',
      footer: 'partials/footer'
    }
  }))

  /**
   * Build sitemap
   */
  .use(sitemap({
    output: 'sitemap.xml',
    hostname: info.url
  }))

  /**
   * Create robots.txt
Esempio n. 28
0
  }))
  .use(permalinks({
    pattern: ':page'
  }))
  .use(sass({
    outputDir: 'assets/styles',
    outputStyle: 'compressed'
  }))
  .use(assets({
    source: './src/assets/components',
    destination: './assets/components'
  }))
  .use(renderContents())
  .use(templates({
    engine: 'swig',
    partials: {
      drawer: 'partials/drawer',
      footer: 'partials/footer',
      install: 'partials/install',
      header: 'partials/header',
      meta: 'partials/meta'
    }
  }))
  .use(autoprefixer())
  .destination('dist')
  .build(function(err, files) {
    if (err) {
      throw err;
    }
  });
Esempio n. 29
0
.use(filemetadata([
  {pattern: 'posts/*.md', metadata: {
    type: 'post',
    template: 'post.hbs'
  }}
]))
.use(collections({
  posts: {
    pattern: 'posts/*.md',
    sortBy: 'date',
    reverse: true
  }
}))
.use(markdown({
  smartypants: true,
  gfm: true,
  tables: true,
  highlight: function(code) {
    return require('highlight.js').highlightAuto(code).value;
  }
}))
.use(strippedExceprts({
  strip: true
}))
.use(permalinks({
  pattern: ':date/:title/'
}))
.use(templates('handlebars'))
.build(function(err) {
  if(err) throw err;
});
Esempio n. 30
0
    site: function(done) {
      metalsmith(__dirname + '/../')
        .clean(false)
        .source('./src/documents_' + lang)
        .metadata(require('../config.js')(lang, isStaging))
        .use(draft())
        .use(require('./helpers')())
        .use(require('./import-api-docs')(lang))
        .use(require('./patterns-collection')(lang))
        .use(collections({
          components: {
            sortBy: 'name'
          },
          objects: {
            sortBy: 'name'
          },
          guides: {
            sortBy: 'name'
          }
        }))
        .use(function(files, metalsmith, done) {
          setImmediate(done);

          var dict = {};
          for (var path in files) {
            var file = files[path];
            if (file.componentCategory) {
              file.componentCategory.split(/, */).forEach(function(category) {
                if (!dict[category]) {
                  dict[category] = [];
                }
                dict[category].push(file);
              });
            }
          }
          metalsmith.metadata().componentCategoryDict = sortObject(dict);
        })
        .use(templates({engine: 'eco', inPlace: true}))
        .use(require('./autotoc')())
        .use(function(files, metalsmith, done) {
          setImmediate(done);

          var cssFile = files['reference/css.html'];
          var cssToc = cssFile.toc;
          delete cssFile.toc;

          metalsmith.metadata().cssToc = cssToc;
        })
        .use(currentPath())
        .use(branch('!robots.txt')
          .use(layouts({
            engine: 'eco', 
            directory: './src/layouts/',
            default: 'default.html.eco'
          }))
        )
        .use(assets({source: './src/files'}))
        .use(require('./css-transform')(lang))
        .use(redirect({
          '/components.html' : '/reference/javascript.html',
          '/guide/components.html' : '/reference/javascript.html'
        }))
        .use(branch('*.html').use(currentPath()))
        .use(function(files, metalsmith, done) {
          setImmediate(done);

          for (var file in files) {
            if (file.match(/\.html$/)) {
              files[file].path = file;
            }
          }
        })
        .use(branch('robots.txt').use(templates({
          inPlace: true, engine: 'eco'
        })))
        .use(sitemap({
          ignoreFiles: [/\.gitignore/],
          output: 'sitemap.xml',
          hostname: 'http://' + (isStaging ? 's.' : '') + (lang === 'ja' ? 'ja.' : '') + 'onsen.io',
          defaults: {
            priority: 0.5
          }
        }))
        .destination('./out_' + lang)
        .build(function(error) {
          if (error) {
            gutil.log('ERROR: ' + error);
            if (error.stack) {
              gutil.log(error.stack);
            }
          }

          browserSync.reload();
          gutil.log('Generated into \'./out_' + lang + '\'');
          done();
        });

    },