Permalink
Browse files

rework nanoc and node build processes to use a config file (order.yam…

…l) to control category and article listing order. resolves #87
  • Loading branch information...
1 parent 5e33b0e commit fd302739a26d95993a1ada4d9d49111eba442d83 @ajpiano ajpiano committed Mar 23, 2012
Showing with 117 additions and 29 deletions.
  1. +1 −0 .gitignore
  2. +18 −25 Rules
  3. +12 −1 nanoc2wordpress/nanoc.js
  4. +9 −3 nanoc2wordpress/wordpress.js
  5. +77 −0 order.yaml
View
@@ -1,4 +1,5 @@
output/
tmp/*
tmp
+order.json
.DS_Store
View
@@ -83,25 +83,18 @@ end
Nanoc3::Filter.register 'CodeBlocks', :code_blocks
preprocess do
- @chapterOrder = [
- "getting-started",
- "javascript-101",
- "using-jquery-core",
- "events",
- "effects",
- "ajax",
- "plugins",
- "performance",
- "code-organization",
- "faq"
- ]
-
+ @order = YAML.load(File.read("order.yaml"))
+ @chapter_articles = {}
+ @chapter_order = @order.map{ |chapter|
+ @chapter_articles[ chapter.keys.first ] = chapter[ chapter.keys.first ]
+ chapter.keys.first
+ }
@chapters = {}
-
@github_users = {
"jquery" => nil
}
+ File.open("order.json", "w") {|f| f.write @order.to_json }
@items.each do |item|
item[:chapter] = item[:filename].split('/')[1]
item[:chapter_title] = item[:chapter].gsub(/-/, " ").upcase
@@ -118,25 +111,25 @@ preprocess do
@github_users[ username ] = JSON.parse(request.body_str)
end
+ @grouped_items = @items.group_by {|item| item[:chapter]}
- @groupedItems = @items.group_by {|item| item[:chapter]}
-
- @orderedItems = []
+ @ordered_items = []
- @chapterOrder.each do |folder|
- myitems = @groupedItems[ folder ]
+ @chapter_order.each do |folder|
@chapters [ folder] = {}
- @chapters[ folder ][ :items ] = @groupedItems[folder].sort_by {|i| i[:section] || 0 }
- @orderedItems = @orderedItems + @chapters[ folder ][ :items ]
+ @chapters[ folder ][ :items ] = @grouped_items[folder].sort_by {|i|
+ p @chapter_articles[ i[ :chapter ] ].index( p i.identifier.split('/')[2] ) || 0
+ @chapter_articles[ i[ :chapter ] ].index( p i.identifier.split('/')[2] ) || 0
+ }
+ @ordered_items = @ordered_items + @chapters[ folder ][ :items ]
@chapters[ folder ][ :title ] = folder.gsub(/-/, " ").upcase
@chapters[ folder ][ :folder ] = folder
end
-
@items.each do |item|
- i = item[:ordinal_index] = @orderedItems.index(item)
+ i = item[:ordinal_index] = @ordered_items.index(item)
if i
- item[:next_item] = @orderedItems[ i+1 ]
- item[:previous_item] = @orderedItems[ i-1 ]
+ item[:next_item] = @ordered_items[ i+1 ]
+ item[:previous_item] = @ordered_items[ i-1 ]
end
item[:github_user] = @github_users[ item[:github] ]
end
@@ -6,14 +6,23 @@ fs = require("fs"),
jsdom = require( "jsdom" ),
_ = require( "underscore" ),
config = require("./config"),
+order = require("../order"),
OUTPUT_DIR = config.git_dir + "/output",
META_REGEX = /<script id="nanoc_meta".*<\/script>(\\n)*/,
site = {
articles: [],
categories: []
-};
+},
+
+category_articles = {},
+category_order = order.map(function( articles ) {
+ for ( var a in articles ) {
+ category_articles[ a ] = articles[a];
+ return a;
+ }
+});
_.mixin(require('underscore.string').exports());
@@ -68,6 +77,7 @@ function processCategories( continuation ) {
_.extend( cat, JSON.parse(meta.textContent) )
cat.contents = _.trim(cat.contents.replace( META_REGEX, ""));
cat.slug = cat.chapter;
+ cat.menu_order = category_order.indexOf( cat.chapter );
}
});
continuation();
@@ -95,6 +105,7 @@ function processArticles( continuation ) {
_.extend( file, JSON.parse(meta.textContent) )
file.contents = _.trim(file.contents.replace( META_REGEX, ""));
file.slug = file.filename.replace( "/"+file.chapter+ "/", "").replace("/index.html", "");
+ file.menu_order = category_articles[ file.chapter ] ? category_articles[ file.chapter ].indexOf( file.slug ) : -1;
}
});
continuation();
@@ -40,7 +40,12 @@ var wordpress = module.exports = {
function(){
var group = this.group();
pages.forEach(function( page, index ) {
- wordpress.createPage( page, group() )
+ // Only allow pages that are in the order.yaml sitemap
+ if ( ~page.menu_order ) {
+ wordpress.createPage( page, group() )
+ } else {
+ group()(null);
+ }
});
},
function(){
@@ -54,8 +59,9 @@ var wordpress = module.exports = {
localDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(),
gmtDate = date.getUTCFullYear() + "-" + (date.getUTCMonth() + 1) + "-" + date.getUTCDate() + " " + date.getUTCHours() + ":" + date.getUTCMinutes() + ":" + date.getUTCSeconds();
db.query(
- "INSERT INTO `" + postsTable + "` " + "SET `post_type` = 'page', `post_author` = ?, `post_name` = ?, `post_title` = ?, `post_content` = ?, " + "`post_date` = ?, `post_date_gmt` = ?, `post_modified` = ?, `post_modified_gmt` = ?, `comment_status` = ?, `ping_status` = ?",
- [1, page.slug, page.title, page.contents, localDate, gmtDate, localDate, gmtDate, "closed", "closed"],
+ "INSERT INTO `" + postsTable + "` " + "SET `post_type` = 'page', `post_author` = ?, `post_name` = ?, `post_title` = ?, `post_content` = ?, `menu_order` = ?, "
+ + "`post_date` = ?, `post_date_gmt` = ?, `post_modified` = ?, `post_modified_gmt` = ?, `comment_status` = ?, `ping_status` = ?",
+ [1, page.slug, page.title, page.contents, page.menu_order, localDate, gmtDate, localDate, gmtDate, "closed", "closed"],
this
);
},
View
@@ -0,0 +1,77 @@
+- about-jquery:
+ - downloading-jquery
+ - how-jquery-works
+- javascript-101:
+ - running-code
+ - syntax-basics
+ - types
+ - operators
+ - conditional-code
+ - loops
+ - reserved-words
+ - arrays
+ - objects
+ - functions
+ - testing-type
+ - this-keyword
+ - scope
+ - closures
+- using-jquery-core:
+ - dollar-object-vs-function
+ - document-ready
+ - avoid-conflicts-other-libraries
+ - attributes
+ - selecting-elements
+ - working-with-selections
+ - manipulating-elements
+ - traversing
+ - css-styling-dimensions
+ - data-methods
+ - feature-browser-detection
+ - utility-methods
+- events:
+ - events-to-elements
+ - inside-event-handling-function
+ - event-helpers
+ - event-extensions
+ - event-delegation
+ - using_delegate_and_undelegate
+ - working_with_events_part_1
+ - working_with_events_part_2
+ - triggering-event-handlers
+ - introduction-to-custom-events
+- effects:
+ - built-in-effects
+ - custom-effects
+ - managing-effects
+ - queue_and_dequeue_explained
+ - uses_of_queue_and_dequeue
+- ajax:
+ - key-concepts
+ - jquery-ajax-methods
+ - ajax-and-forms
+ - working-with-jsonp
+ - ajax-events
+- plugins:
+ - finding-evaluating-plugins
+ - basic-plugin-creation
+ - a_plugin_development_pattern
+ - making_a_jquery_plugin_truly_customizable
+ - stateful-plugins-with-widget-factory
+- performance:
+ - append-outside-loop
+ - cache-loop-length
+ - clever-conditionals
+ - detach-elements-before-work-with-them
+ - dont-act-on-absent-elements
+ - optimize-selectors
+ - use-stylesheets-for-changing-css
+ - variable-definition
+ - read-the-source
+- code-organization:
+ - concepts
+ - beware-anonymous-functions
+ - dont-repeat-yourself
+- faq:
+ - add_keyboard_navigation
+ - enable_the_back_button

0 comments on commit fd30273

Please sign in to comment.