Exemplo n.º 1
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();
}
Exemplo n.º 2
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
  // }))
}
Exemplo n.º 3
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();
    });
};
 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")
                 }
             });
 }
Exemplo n.º 5
0
exports.init = (args) => {

  return Metalsmith(__dirname)
    .metadata({
      injectScript: args.injectScript || '',
      googleAnalyticsKey: 'UA-58254103-1',
      maquetteVersion: require('../package.json').version,
      // defaults, can be overridden per page
      liveEditors: false,
      liveEditorsVelocity: false,
      liveEditorsCss: false,
      workbench: false
    })
    .source('source')
    .destination('./build/website')
    .clean(true)
    .use(inPlace({
      engineOptions: {
        root: __dirname
      }
    }))
    .use(markdown())
    .use(layouts({
      engine: 'ejs',
      directory: 'layouts',
      engineOptions: {
        root: __dirname
      }
    }))
    .use(postcss({
      plugins: {
        'precss': {}
      }
    }));
};
Exemplo n.º 6
0
let createDocs = function(version) {
  Metalsmith(path.join(__dirname, 'dcos-docs'))
    .source(version)
    .use(markdown({
      smartypants: true,
      gfm: true,
      tables: true
    }))
    .use(nav)
    .use(layouts({
      pattern: '**/*.html',
      engine: 'jade',
      directory: path.join('..', 'layouts'),
      default: 'docs.jade'
    }))
    .use(jade({
      pretty: true
    }))
    .clean(false)
    .use(each(updatePaths))
    .destination(path.join('..', 'build', 'docs', version))
    .build((err) => {
      if (err) throw err
    })
}
Exemplo n.º 7
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!');
      }
    });
};
Exemplo n.º 8
0
 metalsmith: function (done) {
   metalsmith(join(__dirname, 'docs'))
     .metadata({ baseUri: argv.baseUri })
     .use(markdown())
     .use(templates('handlebars'))
     .build(done);
 },
Exemplo n.º 9
0
module.exports = function (locations) {
  locations = locations || {}
  locations.base = locations.base || __dirname
  locations.source = locations.source || '../content/paginas'
  locations.destination = locations.destination || '../site/'

  return Metalsmith(locations.base)
  .clean(true)
  .source(locations.source)
  .destination(locations.destination)
  .concurrency(1000)
  .metadata(META)
  .use(ignore('.DS_Store'))
  .use(includes({ prefix: '!! incluye' }))
  .use(sections())
  .use(markdown())
  .use(directives(processors))
  .use(partial({ directory: './templates/partials', engine: 'handlebars' }))
  .use(layouts({
    pattern: '**/*.html',
    default: 'page.html', directory: 'templates', engine: 'handlebars' }))
  .use(permalinks({ relative: false }))
  .use(concat({ 'stylesheets/portada.css': { 'base': './stylesheets', 'files': ['portada.css', 'sections.css'] },
    'stylesheets/all.css': { 'base': './stylesheets', 'files': ['reset.css', 'fonts.css', 'sections.css', 'page.css', 'article.css'] }
  }))
  .use(assets({ source: './assets', destination: '.' }))
  .use(portada())
  .use(redirects({ file: 'redirects.txt' }))
}
Exemplo n.º 10
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));
}
Exemplo n.º 11
0
gulp.task('f', function () {
    const f = filter(['*', '!src/content']);
    return gulp
        .src(__.sass_src)
        .pipe(f)
        .pipe(metalsmith({
            // set Metalsmith's root directory, for example for locating templates, defaults to CWD
            root: __dirname,
            // files to exclude from the build
            ignore: [
                __.build_src + '/*.tmp',
                'io/*'
            ],
            // read frontmatter, defaults to true
            frontmatter: true,
            // Metalsmith plugins to use
            use: [
                metadata({
                    site: 'meta.json',
                    settings: 'settings.json'
                }),
                //gulpIgnore.include(condition),
                markdown(),
                collections({
                    articles: {
                        pattern: './content/articles/*.md',
                        sortBy: 'date',
                        reverse: 'True'
                    }
                    , news: {
                        pattern: './content/news/*.md',
                        sortBy: 'date',
                        reverse: 'True'
                    }
                    , books: {
                        pattern: './content/books/*.md',
                        sortBy: 'date',
                        reverse: 'True'
                    }
                }),
                permalinks({
                    pattern: ':collections:title'
                }),
                feed({collection: 'articles'}),
                layouts({
                    engine: 'jade',
                    moment: moment
                }),
                beautify()
            ],
            // Initial Metalsmith metadata:
            metadata: {
                site_title: 'Sample static site'
            }
        }))
        .resume();
});
Exemplo n.º 12
0
gulp.task('content', function () {
    console.log('... building content ...');

    // TODO : could just source content here
    return gulp.src(['./src/**', '!./src/io/**'])
        //.pipe(f)
        .pipe(metalsmith({
            // set Metalsmith's root directory, for example for locating templates, defaults to CWD
            root: __dirname,
            // files to exclude from the build
            ignore: [],
            // read frontmatter, defaults to true
            frontmatter: true,
            // Metalsmith plugins to use
            use: [
                //lens(),
                metadata({
                    site: 'meta.json',
                    settings: 'settings.json'
                }),
                date({key: 'dateBuilt'}),
                //gulpIgnore.include(condition),
                markdown(),
                collections({
                    articles: {
                        pattern: './content/articles/*.md',
                        sortBy: 'date',
                        reverse: 'True'
                    }
                    , news: {
                        pattern: './content/news/*.md',
                        sortBy: 'date',
                        reverse: 'True'
                    }
                    , books: {
                        pattern: './content/books/*.md',
                        sortBy: 'date',
                        reverse: 'True'
                    }
                }),
                permalinks({
                    pattern: ':collections:title'
                }),
                feed({collection: 'articles'}),
                layouts({
                    engine: 'jade',
                    moment: moment
                }),
                beautify()
            ],
            // Initial Metalsmith metadata:
            metadata: {
                site_title: 'Sample static site'
            }
        }))
        .pipe(gulp.dest(__.pub));
});
Exemplo n.º 13
0
 it('should skip excerpts with images', function(done) {
   Metalsmith('test/fixtures/first-paragraph-image')
     .use(markdown())
     .use(excerpt())
     .build(function(err, files) {
       if (err) return done(err);
       assert.equal('<p>This is the excerpt.</p>', files['index.html'].excerpt);
       done();
     });
 });
Exemplo n.º 14
0
 it('should convert excerpt files', function(done){
   Metalsmith('test/fixtures/basic')
     .use(markdown())
     .use(excerpt())
     .build(function(err, files){
       if (err) return done(err);
       assert.equal('<p>excerpt</p>', files['index.html'].excerpt);
       done();
     });
 });
Exemplo n.º 15
0
 it('should skip excerpts with leading whitespace', function(done) {
   Metalsmith('test/fixtures/indented-paragraph')
     .use(markdown())
     .use(excerpt())
     .build(function(err, files) {
       if (err) return done(err);
       assert.equal('<p>This is the excerpt.</p>', files['index.html'].excerpt);
       done();
     });
 });
Exemplo n.º 16
0
 it('should convert excerpt files with reference-style links', function(done) {
   Metalsmith('test/fixtures/reference-links')
     .use(markdown())
     .use(excerpt())
     .build(function(err, files) {
       if (err) return done(err);
       assert.equal('<p>This is <a href="http://example.com">a link</a>.</p>', files['index.html'].excerpt);
       done();
     });
 });
Exemplo n.º 17
0
 it('should parse headings from HTML', function(done){
   Metalsmith('test/fixture')
     .use(markdown())
     .use(headings({ selectors: ['h2'] }))
     .build(function(err, files){
       if (err) return done(err);
       assert.deepEqual(files['index.html'].headings, [
         { id: 'two-one', tag: 'h2', text: 'two one' },
         { id: 'two-two', tag: 'h2', text: 'two two' }
       ]);
       done();
     });
 });
Exemplo n.º 18
0
 it('should accept a string shorthand', function(done){
   Metalsmith('test/fixture')
     .use(markdown())
     .use(headings('h2'))
     .build(function(err, files){
       if (err) return done(err);
       assert.deepEqual(files['index.html'].headings, [
         { id: 'two-one', tag: 'h2', text: 'two one' },
         { id: 'two-two', tag: 'h2', text: 'two two' }
       ]);
       done();
     });
 });
Exemplo n.º 19
0
exports.html = cb => new Metalsmith(__dirname)
    // basic options
    .clean(false)
    .source(SOURCE_PATH)
    .destination(OUTPUT_PATH)

    // plugins
    .use(plugins.removeFiles({
        target: OUTPUT_PATH,
        extensions: CLEANUP_EXTENSIONS
    }))
    .use(plugins.metadata({
        destination: OUTPUT_PATH,
        tocData: require('./data/toc.json')
    }))
    .use(markdown({
        gfm: true,
        renderer: markedFactory(),
        smartypants: false,
        tables: true
    }))
    .use(plugins.configureSwig(swigViews, swigOptions))
    .use(headings({
        // use a single jQuery selector so we get all the headings in order
        selectors: [TOC_HEADINGS.join(', ')]
    }))
    .use(plugins.buildHeadingTree())
    .use(plugins.addTemplateName())
    .use(plugins.addJsdocTagMetadata())
    .use(plugins.adjustMetadata())
    .use(plugins.swig(swigOptions))
    .use(plugins.buildRedirects(require('./data/redirects.json')))
    .use(plugins.copyStaticFile({
        source: path.join(require.resolve('code-prettify'), '..', '..', 'loader', 'prettify.js'),
        destination: path.join(__dirname, 'scripts', 'prettify.js')
    }))
    /* eslint-disable camelcase */
    .use(beautify({
        css: false,
        html: {
            indent_char: ' ',
            indent_size: 2,
            // js-beautify ignores the value 0 because it's falsy
            max_preserve_newlines: 0.1
        },
        js: false
    }))

    // go!
    .build(cb);
Exemplo n.º 20
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'));
});
Exemplo n.º 21
0
  module.exports = function(userConfig) {
    var config = configurator(userConfig);

    baseJs(config);

    /* SETUP */
    var metalsmith = new Metalsmith(config.projectRoot);
    var branches = {
      things: config.thingFolderName + '/**/*.html',
      basicPage: '*.html'
    };

    for (var b in branches) {
      if (b) {
        config.whitelist.push('!' + branches[b]);
      }
    }

    /* DELEGATION */
    metalsmith
      .source(config.src)
      .destination(config.dest)
      .metadata(config.metadata)
      .use(ignore(config.blacklist))
      .use(markdown())
      .use(ignore(config.whitelist))
      .use(function(files, m, done) {
        copyAssets(config, done);
      });

    metalsmith.use(things({
      branch: branch(branches.things),
      name: config.thing,
      pageSize: config.pageSize,
      dest: config.thingsAbs,
      colorSalt: config.colorSalt,
      colorSalt2: config.colorSalt2
    }));
    metalsmith.use(basicPage({
      branch: branch(branches.basicPage),
      templates: config.templateFolder
    }));


    return metalsmith;
  };
Exemplo n.º 22
0
    authors: function(done) {
      if (lang === 'ja') {
        done();
        return;
      }

      metalsmith(__dirname + '/../')
        .clean(false)
        .source('./blog/authors/')
        .metadata(require('../config.js')(lang, isStaging))
        .destination('./out_en/blog/')
        .use(require('./helpers')())
        .use(branch('*.markdown')
          .use(markdown({
            gfm: true,
            tables: true,
            breaks: false,
            pedantic: false,
            sanitize: false,
            smartLists: true,
            smartypants: true
          }))
          .use(permalinks({
            pattern: ':id'
          }))
        )
        .use(function(files, metalsmith, done) {
          for (var path in files) {
            files[path].title = files[path].name;
          }
          done();
        })
        .use(layouts({
          engine: 'eco',
          directory: './src/layouts/',
          default: 'author.html.eco'
        }))
        .build(function(error) {
          if (error) {
            gutil.log('ERROR: ' + error);
          }
          done();
        });

   },
Exemplo n.º 23
0
  it('unnecessary paragraph wrappers around image tag', (done) => {
    metalsmith('test/fixture')
    .use(markdown())
    .build((err, files) => {
      if (err) {
        return done(err);
      }

      const content = files['index.html'].contents.toString().trim();

      content.split('\n').forEach((markup, key) => {
        assert.notEqual(markup, expected[key]);
        assert.equal(markup, `<p>${expected[key]}</p>`);
      });

      return done();
    });
  });
Exemplo n.º 24
0
  it('should remove paragraph tags from HTML', (done) => {
    metalsmith('test/fixture')
    .use(markdown())
    .use(tagcleaner())
    .build((err, files) => {
      if (err) {
        return done(err);
      }

      const content = files['index.html'].contents.toString().trim();

      content.split('\n').forEach((markup, key) => {
        assert.equal(markup, expected[key]);
      });

      return done();
    });
  });
Exemplo n.º 25
0
 gulp.task('metalsmith-docs', function() {
   return gulp.src([
     config.assets + 'components/**/*.swig',
     config.assets + 'docs/**/*.md',
     config.assets + 'data/**/*.json'
   ])
     .pipe($.plumber({errorHandler: errorAlert}))
     .pipe($.metalsmith({
       use: [
         markdown({ langPrefix: 'language-' }),
         collections(config.metalsmith.plugins.collections),
         function(files, metalsmith, done){
           for (var file in files) {
             if (files[file].collection == 'atoms' || files[file].collection == 'molecules' || files[file].collection == 'organisms') {
               delete files[file];
             }
             if (path.extname(file) === '.json') {
               var key = path.basename(file, '.json');
               metadatas[key] = JSON.parse(files[file].contents.toString());
               delete files[file];
             }
           }
           done();
         },
         define({
           data: metadatas
         }),
         contentful({
           accessToken : contentful_key
         }),
         layouts(config.metalsmith.plugins.layouts),
         function(files, metalsmith, done){
           // Clean dirty front-matter comment
           for (var file in files) {
             files[file].contents = new Buffer(files[file].contents.toString().replace(/---[\s\S]*?---/g, ''));
           }
           done();
         },
         permalinks(config.metalsmith.plugins.permalinks),
         sitemap('http://hopitalrivierachablais.ch')
       ]
     }))
     .pipe(gulp.dest(config.metalsmith.dist));
 });
Exemplo n.º 26
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); }
    });
};
Exemplo n.º 27
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();
    });
  },
Exemplo n.º 28
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();
  });

});
Exemplo n.º 29
0
  grunt.registerTask('metalsmith', 'Build site', function () {
    const highlights = require('metalsmith-metallic');
    const inPlace = require('metalsmith-in-place');
    const layouts = require('metalsmith-layouts');
    const markdown = require('metalsmith-markdown');
    const metadata = require('metalsmith-metadata');
    const Metalsmith = require('metalsmith');
    const nodeVersion = process.version;

    let done = this.async();

    const m = Metalsmith(__dirname);
    m.metadata({
      nodeVersion
    });
    m.use(metadata({
      plugins: 'plugins.json',
      examples: 'examples.json'
    }));
    m.use(inPlace({
      engine: 'swig',
      pattern: '**/*.md'
    }));
    m.use(highlights());
    m.use(markdown({
      smartypants: true,
      smartLists: true
    }));
    m.use(layouts({
      engine: 'swig',
      directory: process.cwd()
    }));
    m.build((err) => {
      if (err) {
        /* eslint no-console: 0 */
        console.log('Error: ' + err);
        return done(false);
      }
      return done();
    });
  });
Exemplo n.º 30
0
function build(){
  metal(__dirname)
    .source('./src')
    .use(markdown({
      smartypants: true,
      gfm: true,
      tables: true,
      highlight: highlighter()
    }))
  // .use(my_plugin({a:1,b:2}))
    .use(inPlace({ engine: 'handlebars' }))
    .use(layouts({
      engine: 'handlebars',
      directory: 'templates',
      partials: 'partials'
    }))
    .destination('./build')
    .build(function (e) {
      if (e) console.log(e)
    })
}