Ejemplo n.º 1
0
// build command that runs metalsmith
function build(mode, callback) {
  Metalsmith(__dirname)
    .source('./content')
    .destination('./build')
    .use(json({
      "source_path": "./json/"
    }))
    .use(collections({
       "projects": {},
       "updates": {},       
    }))
    .use(permalinks({
       pattern: ':title',
       relative: false
     }))
    // .use(algolia())
    .use(mingo())
    .use(inplace('nunjucks'))
    .use(layouts('nunjucks'))
    .use(when((mode === 'dev'), // run the watch plugin only in dev mode
      watch({
        paths: {
          "${source}/**/*.*": true,
          "layouts/**/*": "**/*"
        },
        livereload: false,
      })
    ))
    .build(function(err){
      if (err){
        throw err;
      }
      callback();
    });
}
  it('renders multiple feeds', async function() {
    const metalsmith = Metalsmith('test/fixtures/many_posts')
      .metadata({site})
      .use(
        collections({
          posts1: 'post1*.html',
          posts2: 'post2*.html'
        })
      )
      .use(
        feed({
          collection: 'posts1',
          destination: 'rss1.xml'
        })
      )
      .use(
        feed({
          collection: 'posts2',
          destination: 'rss2.xml'
        })
      );

    const files = await build(metalsmith);

    const rss1 = await parse(files, 'rss1.xml');
    assert(rss1['channel'][0].item.length > 0);

    const rss2 = await parse(files, 'rss2.xml');
    assert(rss2['channel'][0].item.length > 0);
  });
 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")
                 }
             });
 }
Ejemplo n.º 4
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;
});
Ejemplo n.º 5
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
  // }))
}
Ejemplo n.º 6
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();
}
Ejemplo n.º 7
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();
    });
};
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();
});
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));
});
Ejemplo n.º 10
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}));

});
Ejemplo n.º 11
0
 it("should leave private files in collections for private scope", function(done) {
     var metalsmith = Metalsmith('test/fixtures/basic');
     metalsmith
     .use(collections({
         articles: {}
     }))
     .use(collectionScoping({scope: 'private'}))
     .build(function(err) {
         var m = metalsmith.metadata();
         assert.equal(m.collections.articles.length, 2);
         assert.equal(m.articles.length,2);
         done();
     });
 });
Ejemplo n.º 12
0
 it("should not remove metadata when removing private files from collections", function(done) {
     var metalsmith = Metalsmith('test/fixtures/basic');
     metalsmith
     .use(collections({
         articles: {
             metadata: { foo: 'bar' }
         }
     }))
     .use(collectionScoping({scope: 'private'}))
     .build(function(err) {
         var m = metalsmith.metadata();
         assert.equal(m.collections.articles.metadata.foo, 'bar');
         assert.equal(m.articles.metadata.foo, 'bar');
         done();
     });
 });
Ejemplo n.º 13
0
    it('should do a deep copy of the file', function(done) {
      var m = metalsmith('test/fixtures/simple');

      m.use(copy({
        pattern: '*.md',
        extension: '.text'
      })).use(collections({
        articles: {
          pattern: "*.md"
        }
      })).build(function(err) {
        if (err) return done(err);
        assert(m.metadata().articles.length == 1, 'changes made to original file were incorrectly propogated to copy');
        done();
      });
    });
  it('complains without a site_url', async function() {
    const metalsmith = Metalsmith('test/fixtures/simple')
      .use(collections({posts: '*.html'}))
      .use(
        feed({
          collection: 'posts'
        })
      );

    try {
      await metalsmith.buildAsPromised();
    } catch (e) {
      var err = e;
    }
    assert(err);
  });
Ejemplo n.º 15
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'));
});
Ejemplo n.º 16
0
 it("should add 'private' metadata for files in private collections", function(done) {
     var metalsmith = Metalsmith('test/fixtures/basic');
     metalsmith
     .use(collections({
         articles: {},
         secrets: {
             metadata: { private: true }
         }
     }))
     .use(collectionScoping({propagate: true}))
     .build(function(err, files) {
         assert.equal(files['three.md'].private, true);
         assert.equal(files['four.md'].private, true);
         assert.equal(files['one.md'].private, undefined);
         assert.equal(files['five.md'].private, undefined);
         done();
     });
 });
    it('can add custom_elements for podcasts', async function() {
      const makeFeaturedImage = file => {
        if (!file.featuredImage) {
          return null;
        }
        return [
          {
            'media:image': [
              {
                _attr: {
                  url: `http://example.com${file.featuredImage}`,
                  medium: 'image'
                }
              }
            ]
          }
        ];
      };

      const metalsmith = Metalsmith('test/fixtures/complex')
        .metadata({site})
        .use(collections({posts: '*.html'}))
        .use(
          feed({
            collection: 'posts',
            preprocess: file => ({
              ...file,
              custom_elements: makeFeaturedImage(file)
            })
          })
        );

      const {postWithMeta, postWithoutMeta} = await parseComplexFixtures(
        await build(metalsmith)
      );

      assert.equal(
        postWithMeta['media:image'][0]['$']['url'],
        'http://example.com/foo.jpg'
      );
      assert.equal(postWithMeta['media:image'][0]['$']['medium'], 'image');

      assert.equal(postWithoutMeta['media:image'], undefined);
    });
Ejemplo n.º 18
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));
 });
module.exports = function build(callback){
  // read playlists upon every build
  var playlists = {};
  config.collections.forEach(function(collection){
    // playlists
    var collectionFolder = [config.lessonRoot, config.sourceFolder, collection].join("/");
    playlists[collection] = getPlaylists(collectionFolder);
  });
  // make it available in layout
  defineOptions.playlists = playlists;

  // do the building
  Metalsmith(config.lessonRoot)
  .source(config.sourceFolder)
  .clean(false) // do not delete files, allow gulp tasks in parallel
  .use(ignore(ignoreOptions))
  .use(ignoreIndexedFalse)
  .use(paths())
  // set layout for exercises
  .use(setMetadata(metadataOptions))
  // add relative(path) for use in layouts
  .use(relative())
  // create collections for index
  .use(collections(collectionOptions))
  // add file.link metadata (files are .md here)
  .use(filepath())
  // remove lessons *after* we have necessary metadata
  .use(ignore(['**', '!**/index.md']))
  .use(tools.removeExternal)
  // convert markdown to html
  .use(md)
  // globals for use in layouts
  .use(define(defineOptions))
  // apply layouts
  .use(layouts(layoutOptions))
  //build
  .destination('build')
  .build(function(err){
    if (err) console.log(err);
    // callback when build is done
    callback(err);
  });
};
Ejemplo 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); }
    });
};
Ejemplo n.º 21
0
 it('should remove private collections with no scope option', function(done) {
   var metalsmith = Metalsmith('test/fixtures/basic');
     metalsmith
     .use(collections({
         articles: {},
         secrets: {
             metadata: { private: true }
         }
     }))
     .use(collectionScoping())
     .build(function(err) {
         if (err) return(done(err));
         var m = metalsmith.metadata();
         assert.notEqual(m.articles,null);
         assert.notEqual(m.collections.articles,null);
         assert.equal(m.secrets,null);
         assert.equal(m.collections.secrets,null);
         done();
     });
 });
Ejemplo n.º 22
0
 it("should remove private files from collections for non-private scope", function(done) {
     var metalsmith = Metalsmith('test/fixtures/basic');
     metalsmith
     .use(collections({
         articles: {}
     }))
     .use(collectionScoping())
     .build(function(err) {
         var m = metalsmith.metadata();
         m.collections.articles.forEach(function(page) {
             assert.equal(page["private"],null);
         });
         m.articles.forEach(function(page) {
             assert.equal(page["private"],null);
         });
         assert.equal(m.collections.articles.length,1);
         assert.equal(m.articles.length,1);
         done();
     });
 });
Ejemplo 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();
  });

});
  it('renders an RSS feed', async function() {
    const metalsmith = Metalsmith('test/fixtures/simple')
      .metadata({site})
      .use(collections({posts: '*.html'}))
      .use(
        feed({
          collection: 'posts'
        })
      );

    const rss = await parse(await build(metalsmith));
    assert.equal(rss['$']['xmlns:atom'], 'http://www.w3.org/2005/Atom');
    const channel = rss.channel[0];
    assert.equal(channel.title[0], site.title);
    assert.equal(channel.author[0], site.author);
    assert.equal(channel.item.length, 1);

    const post = channel.item[0];
    assert.equal(post.title[0], 'Theory of Juice');
    assert.equal(post.description[0], '<p>juice appeal</p>\n');
  });
    it('can customize description', async function() {
      const metalsmith = Metalsmith('test/fixtures/simple')
        .metadata({site})
        .use(collections({posts: '*.html'}))
        .use(
          feed({
            collection: 'posts',
            preprocess: file => ({
              ...file,
              description: `<h1>${file.title}</h1>${file.contents}`
            })
          })
        );

      const rss = await parse(await build(metalsmith));
      const post = rss.channel[0].item[0];
      assert.equal(post.title[0], 'Theory of Juice');
      assert.equal(
        post.description[0],
        '<h1>Theory of Juice</h1><p>juice appeal</p>\n'
      );
    });
Ejemplo n.º 26
0
module.exports = function build (callback, options) {
  options = options || {}
  var forceBuild = options.force || false

  // do the building
  Metalsmith(config.lessonRoot)
  .source(config.sourceFolder)
  .use(lessonReadme())
  .use(ignore(ignoreOptions))
  .clean(false) // do not delete files, allow gulp tasks in parallel
  .use(paths())
  // set layout for exercises
  .use(setMetadata(metadataOptions))
  // add relative(path) for use in layouts
  .use(relative())
  // create collections
  .use(collections(collectionOptions))
  .use(changed({
    force: forceBuild,
    extnames: {
      '.md': '.html'
    }
  }))
  // convert markdown to html
  .use(md)
  // add file.link metadata (now files are .html)
  .use(filepath())
  // globals for use in layouts
  .use(define(defineOptions))
  // apply layouts
  .use(layouts(layoutOptions))
  // build
  .destination('build')
  .build(function (err) {
    if (err) console.log(err)
    // callback when build is done
    callback(err)
  })
}
Ejemplo n.º 27
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);
}
Ejemplo n.º 28
0
  it('should ignore files not in a collection', function(done){
    Metalsmith('test/fixtures/collections')
      .use(collections({
        posts: {
          pattern: 'in_collection.html'
        }
      }))
      .use(permalinks({
          pattern: ':title',
          collection: 'posts'
      }))
      .use(function (files, metalsmith, done) {
          assert.equal(2, Object.keys(files).length);
          assert.equal(true, 'not_in_collection.html' in files);
          assert.equal(true, 'in-collection/index.html' in files);
          done();
      })
      .build(function(err){
        if (err) return done(err);
        equal('test/fixtures/pattern/expected', 'test/fixtures/pattern/build');
        done();
      });

  });
Ejemplo n.º 29
0
// This is the function where the actual magic happens. This contains the main
// Metalsmith build cycle used for building a locale subsite, such as the
// english one.
function buildLocale (source, locale) {
  console.time(`[metalsmith] build/${locale} finished`)
  const siteJSON = path.join(__dirname, 'locale', locale, 'site.json')
  const metalsmith = Metalsmith(__dirname)
  metalsmith
    // Sets global metadata imported from the locale's respective site.json.
    .metadata({
      site: require(siteJSON),
      project: source.project,
      i18n: i18nJSON(locale)
    })
    // Sets the build source as the locale folder.
    .source(path.join(__dirname, 'locale', locale))
    // Extracts the main menu and sub-menu links form locale's site.json and
    // adds them to the metadata. This data is used in the navigation template
    .use(navigation(source.project.currentVersions))
    // Defines the blog post/guide collections used to internally group them for
    // easier future handling and feed generation.
    .use(collections({
      blog: {
        pattern: 'blog/**/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false
      },
      blogAnnounce: {
        pattern: 'blog/announcements/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false
      },
      blogReleases: {
        pattern: 'blog/release/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false
      },
      blogVulnerability: {
        pattern: 'blog/vulnerability/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false
      },
      lastWeekly: {
        pattern: 'blog/weekly-updates/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false,
        limit: 1
      },
      tscMinutes: {
        pattern: 'foundation/tsc/minutes/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false
      },
      knowledgeBase: {
        pattern: 'knowledge/**/*.md',
        refer: false
      },
      guides: {
        pattern: 'docs/guides/!(index).md',
        refer: false
      }
    }))
    .use(pagination({
      path: 'blog/year',
      iteratee: (post, idx) => ({
        post,
        displaySummary: idx < 10
      })
    }))
    .use(markdown(markedOptions))
    .use(githubLinks({ locale: locale }))
    .use(prism())
    // Deletes Stylus partials since they'll be included in the main CSS file
    // anyways.
    .use(filterStylusPartials())
    .use(stylus({
      compress: true,
      paths: [path.join(__dirname, 'layouts', 'css')],
      use: [autoprefixer()]
    }))
    // Set pretty permalinks, we don't want .html suffixes everywhere.
    .use(permalinks({
      relative: false
    }))
    // Generates the feed XML files from their respective collections which were
    // defined earlier on.
    .use(feed({
      collection: 'blog',
      destination: 'feed/blog.xml',
      title: 'Node.js Blog'
    }))
    .use(feed({
      collection: 'blogAnnounce',
      destination: 'feed/announce.xml',
      title: 'Node.js Announcements'
    }))
    .use(feed({
      collection: 'blogReleases',
      destination: 'feed/releases.xml',
      title: 'Node.js Blog: Releases'
    }))
    .use(feed({
      collection: 'blogVulnerability',
      destination: 'feed/vulnerability.xml',
      title: 'Node.js Blog: Vulnerability Reports'
    }))
    .use(feed({
      collection: 'tscMinutes',
      destination: 'feed/tsc-minutes.xml',
      title: 'Node.js Technical Steering Committee meetings'
    }))
    // Finally, this compiles the rest of the layouts present in ./layouts.
    // They're language-agnostic, but have to be regenerated for every locale
    // anyways.
    .use(layouts({
      engine: 'handlebars',
      pattern: '**/*.html',
      partials: 'layouts/partials',
      helpers: {
        copyright: require('./scripts/helpers/copyright-year.js'),
        equals: require('./scripts/helpers/equals.js'),
        startswith: require('./scripts/helpers/startswith.js'),
        i18n: require('./scripts/helpers/i18n.js'),
        changeloglink: require('./scripts/helpers/changeloglink.js'),
        strftime: require('./scripts/helpers/strftime.js'),
        apidocslink: require('./scripts/helpers/apidocslink.js'),
        majorapidocslink: require('./scripts/helpers/majorapidocslink.js'),
        summary: require('./scripts/helpers/summary.js')
      }
    }))
    // Pipes the generated files into their respective subdirectory in the build
    // directory.
    .destination(path.join(__dirname, 'build', locale))

  // This actually executes the build and stops the internal timer after
  // completion.
  metalsmith.build((err) => {
    if (err) { throw err }
    console.timeEnd(`[metalsmith] build/${locale} finished`)
  })
}
Ejemplo n.º 30
0
var assets = require('metalsmith-assets');
var sass = require('metalsmith-sass');
var collections = require('metalsmith-collections');
var filenames = require('metalsmith-filenames');
var prism = require('metalsmith-prism');
var pagination = require('metalsmith-pagination');
var dateFormatter = require('metalsmith-date-formatter');
var path = require('./plugins/path');
var category = require('./plugins/category');

module.exports = Metalsmith(__dirname)
.use(filenames())
.use(collections({
	posts: {
		pattern: '**/*.md',
		sortBy: 'date',
		reverse: true
	}
}))
.use(dateFormatter({
	dates: [
		{
			key: 'date',
			format: 'MMMM Do YYYY'
		}
	]
}))
.use(path())
.use(assets({
	source: './assets',
	destination: './assets'