Skip to content

Commit

Permalink
rework nanoc and node build processes to use a config file (order.yam…
Browse files Browse the repository at this point in the history
…l) to control category and article listing order. resolves #87
  • Loading branch information
ajpiano committed Mar 23, 2012
1 parent 5e33b0e commit fd30273
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
output/
tmp/*
tmp
order.json
.DS_Store
43 changes: 18 additions & 25 deletions Rules
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion nanoc2wordpress/nanoc.js
Expand Up @@ -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());

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 9 additions & 3 deletions nanoc2wordpress/wordpress.js
Expand Up @@ -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(){
Expand All @@ -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
);
},
Expand Down
77 changes: 77 additions & 0 deletions order.yaml
@@ -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.