Skip to content

Instantly share code, notes, and snippets.

@bastibl
Created August 16, 2017 14:37
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 bastibl/8baed642df528b07ee0b68b65069f5d3 to your computer and use it in GitHub Desktop.
Save bastibl/8baed642df528b07ee0b68b65069f5d3 to your computer and use it in GitHub Desktop.
//=======================================================================
// ARCHIVE
//=======================================================================
var archive = function() {
var posts = [];
function bufferContents(file, enc, cb) {
var p = {
title: file.title,
url: file.url,
date: file.date
};
posts.push(p);
cb();
};
function endStream(cb) {
posts.sort(function(a, b) {
if(a.date < b.date) return 1;
if(a.date > b.date) return -1;
return 0;
});
var f = new File({
cwd: '',
base: null,
path: 'archive/index.html'
});
f.posts = posts;
f.description = "Blog Archive of Carriers Everywhere";
this.push(f);
cb();
};
return through.obj(bufferContents, endStream);
};
gulp.task('archive', function() {
return gulp.src('content/_posts/*.md')
.pipe(frontmatter({property: 'frontmatter',
remove: true}))
.pipe(extractMetadata())
.pipe(archive())
.pipe(renderTemplate('archive'))
.pipe(debug())
.pipe(gulp.dest('dist'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment