Last active
August 29, 2015 14:01
-
-
Save doowb/e707e98fac9ced0456a4 to your computer and use it in GitHub Desktop.
Assemble workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Assemble = require('assemble'); | |
var Permalinks = require('assemble-permalinks'); | |
var siteConfig = { | |
options: { | |
assets: '_gh_pages/public/', | |
layout: 'default', | |
ext: '.html', | |
}, | |
src: 'src/templates/pages/*.hbs', | |
dest: '_gh_pages/' | |
}; | |
var permalinksOptions = { | |
structure: ':basename/index:html' | |
} | |
// create a new instance of assemble | |
var assemble = new Assemble(); | |
// using the site configuration, load files from disk and turn into objects: | |
/* | |
``` | |
[{ | |
src: 'src/templates/pages/about.hbs', | |
dest: '_gh_pages/about.html', | |
data: { title: 'Awesomeness' }, | |
content: 'About Page {{title}}', | |
orig: '' | |
}] | |
``` | |
*/ | |
var pages = Assemble.files.load(siteConfig); | |
// add the objects to the pages collection, turning them into `Page` objects | |
assemble.pages.add(pages); | |
// run permalinks middleware to adjust the `dest` proprety on the `pages` | |
var permalinks = new Permalinks(permalinksOptions); | |
assemble.pages.run(permalinks); | |
// render the pages collection | |
assemble.pages.render(); | |
// write the pages collection to disk | |
assemble.pages.write(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Assemble = require('assemble'); | |
var Permalinks = require('assemble-permalinks'); | |
var blogConfig = { | |
options: { | |
assets: '_gh_pages/public/', | |
layout: 'blog', | |
ext: '.html', | |
}, | |
src: 'src/templates/posts/*.md', | |
dest: '_gh_pages/blog/' | |
}; | |
var permalinksOptions = { | |
structure: ':YYYY/:MM/:DD/:basename/index:html' | |
} | |
// create a new instance of assemble | |
var assemble = new Assemble(); | |
// using the blog configuration, load files from disk and turn into objects: | |
/* | |
``` | |
[{ | |
src: 'src/templates/post/2014-05-21-whats-new-in-assemble.hbs', | |
dest: '_gh_pages/2014-05-21-whats-new-in-assemble.html', | |
data: { title: "What's New in Assemble!" }, | |
content: '{{title}}', | |
orig: '' | |
}] | |
``` | |
*/ | |
var files = Assemble.files.load(blogConfig); | |
// create a new Post object inherited from Page | |
var Post = Assemble.Page.extend({ | |
constructor: function (config) { | |
Assemble.Page.call(this, config); | |
// using the src, parse out the date attributes | |
this.data.set('date', this.parseDate(this.src)); | |
}, | |
toString: function () { | |
return 'Post'; | |
} | |
}); | |
// create a new Posts collection object inherited from Pages | |
var Posts = Assemble.Pages.extend({ | |
constructor: function (config) { | |
Assemble.Posts.call(this, config, Post, 'Post'); | |
} | |
}); | |
// create a new instance of the Posts collection and add it to the assemble object | |
var posts = new Posts(); | |
// add the objects to the posts collection, turning them into `Post` objects | |
posts.add(files); | |
// run permalinks middleware to adjust the `dest` proprety on the `posts` | |
var permalinks = new Permalinks(permalinksOptions); | |
assemble.run(posts, permalinks); | |
// render the posts collection | |
assemble.run(posts, assemble.render); | |
// write the posts collection to disk | |
assemble.run(posts, assemble.write); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment