Skip to content

Commit fd30273

Browse files
committed
rework nanoc and node build processes to use a config file (order.yaml) to control category and article listing order. resolves jquery#87
1 parent 5e33b0e commit fd30273

File tree

5 files changed

+117
-29
lines changed

5 files changed

+117
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
output/
22
tmp/*
33
tmp
4+
order.json
45
.DS_Store

Rules

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,18 @@ end
8383
Nanoc3::Filter.register 'CodeBlocks', :code_blocks
8484

8585
preprocess do
86-
@chapterOrder = [
87-
"getting-started",
88-
"javascript-101",
89-
"using-jquery-core",
90-
"events",
91-
"effects",
92-
"ajax",
93-
"plugins",
94-
"performance",
95-
"code-organization",
96-
"faq"
97-
]
98-
86+
@order = YAML.load(File.read("order.yaml"))
87+
@chapter_articles = {}
88+
@chapter_order = @order.map{ |chapter|
89+
@chapter_articles[ chapter.keys.first ] = chapter[ chapter.keys.first ]
90+
chapter.keys.first
91+
}
9992
@chapters = {}
100-
10193
@github_users = {
10294
"jquery" => nil
10395
}
10496

97+
File.open("order.json", "w") {|f| f.write @order.to_json }
10598
@items.each do |item|
10699
item[:chapter] = item[:filename].split('/')[1]
107100
item[:chapter_title] = item[:chapter].gsub(/-/, " ").upcase
@@ -118,25 +111,25 @@ preprocess do
118111
@github_users[ username ] = JSON.parse(request.body_str)
119112
end
120113

114+
@grouped_items = @items.group_by {|item| item[:chapter]}
121115

122-
@groupedItems = @items.group_by {|item| item[:chapter]}
123-
124-
@orderedItems = []
116+
@ordered_items = []
125117

126-
@chapterOrder.each do |folder|
127-
myitems = @groupedItems[ folder ]
118+
@chapter_order.each do |folder|
128119
@chapters [ folder] = {}
129-
@chapters[ folder ][ :items ] = @groupedItems[folder].sort_by {|i| i[:section] || 0 }
130-
@orderedItems = @orderedItems + @chapters[ folder ][ :items ]
120+
@chapters[ folder ][ :items ] = @grouped_items[folder].sort_by {|i|
121+
p @chapter_articles[ i[ :chapter ] ].index( p i.identifier.split('/')[2] ) || 0
122+
@chapter_articles[ i[ :chapter ] ].index( p i.identifier.split('/')[2] ) || 0
123+
}
124+
@ordered_items = @ordered_items + @chapters[ folder ][ :items ]
131125
@chapters[ folder ][ :title ] = folder.gsub(/-/, " ").upcase
132126
@chapters[ folder ][ :folder ] = folder
133127
end
134-
135128
@items.each do |item|
136-
i = item[:ordinal_index] = @orderedItems.index(item)
129+
i = item[:ordinal_index] = @ordered_items.index(item)
137130
if i
138-
item[:next_item] = @orderedItems[ i+1 ]
139-
item[:previous_item] = @orderedItems[ i-1 ]
131+
item[:next_item] = @ordered_items[ i+1 ]
132+
item[:previous_item] = @ordered_items[ i-1 ]
140133
end
141134
item[:github_user] = @github_users[ item[:github] ]
142135
end

nanoc2wordpress/nanoc.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@ fs = require("fs"),
66
jsdom = require( "jsdom" ),
77
_ = require( "underscore" ),
88
config = require("./config"),
9+
order = require("../order"),
910

1011
OUTPUT_DIR = config.git_dir + "/output",
1112
META_REGEX = /<script id="nanoc_meta".*<\/script>(\\n)*/,
1213

1314
site = {
1415
articles: [],
1516
categories: []
16-
};
17+
},
18+
19+
category_articles = {},
20+
category_order = order.map(function( articles ) {
21+
for ( var a in articles ) {
22+
category_articles[ a ] = articles[a];
23+
return a;
24+
}
25+
});
1726

1827
_.mixin(require('underscore.string').exports());
1928

@@ -68,6 +77,7 @@ function processCategories( continuation ) {
6877
_.extend( cat, JSON.parse(meta.textContent) )
6978
cat.contents = _.trim(cat.contents.replace( META_REGEX, ""));
7079
cat.slug = cat.chapter;
80+
cat.menu_order = category_order.indexOf( cat.chapter );
7181
}
7282
});
7383
continuation();
@@ -95,6 +105,7 @@ function processArticles( continuation ) {
95105
_.extend( file, JSON.parse(meta.textContent) )
96106
file.contents = _.trim(file.contents.replace( META_REGEX, ""));
97107
file.slug = file.filename.replace( "/"+file.chapter+ "/", "").replace("/index.html", "");
108+
file.menu_order = category_articles[ file.chapter ] ? category_articles[ file.chapter ].indexOf( file.slug ) : -1;
98109
}
99110
});
100111
continuation();

nanoc2wordpress/wordpress.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ var wordpress = module.exports = {
4040
function(){
4141
var group = this.group();
4242
pages.forEach(function( page, index ) {
43-
wordpress.createPage( page, group() )
43+
// Only allow pages that are in the order.yaml sitemap
44+
if ( ~page.menu_order ) {
45+
wordpress.createPage( page, group() )
46+
} else {
47+
group()(null);
48+
}
4449
});
4550
},
4651
function(){
@@ -54,8 +59,9 @@ var wordpress = module.exports = {
5459
localDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(),
5560
gmtDate = date.getUTCFullYear() + "-" + (date.getUTCMonth() + 1) + "-" + date.getUTCDate() + " " + date.getUTCHours() + ":" + date.getUTCMinutes() + ":" + date.getUTCSeconds();
5661
db.query(
57-
"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` = ?",
58-
[1, page.slug, page.title, page.contents, localDate, gmtDate, localDate, gmtDate, "closed", "closed"],
62+
"INSERT INTO `" + postsTable + "` " + "SET `post_type` = 'page', `post_author` = ?, `post_name` = ?, `post_title` = ?, `post_content` = ?, `menu_order` = ?, "
63+
+ "`post_date` = ?, `post_date_gmt` = ?, `post_modified` = ?, `post_modified_gmt` = ?, `comment_status` = ?, `ping_status` = ?",
64+
[1, page.slug, page.title, page.contents, page.menu_order, localDate, gmtDate, localDate, gmtDate, "closed", "closed"],
5965
this
6066
);
6167
},

order.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
- about-jquery:
2+
- downloading-jquery
3+
- how-jquery-works
4+
- javascript-101:
5+
- running-code
6+
- syntax-basics
7+
- types
8+
- operators
9+
- conditional-code
10+
- loops
11+
- reserved-words
12+
- arrays
13+
- objects
14+
- functions
15+
- testing-type
16+
- this-keyword
17+
- scope
18+
- closures
19+
- using-jquery-core:
20+
- dollar-object-vs-function
21+
- document-ready
22+
- avoid-conflicts-other-libraries
23+
- attributes
24+
- selecting-elements
25+
- working-with-selections
26+
- manipulating-elements
27+
- traversing
28+
- css-styling-dimensions
29+
- data-methods
30+
- feature-browser-detection
31+
- utility-methods
32+
- events:
33+
- events-to-elements
34+
- inside-event-handling-function
35+
- event-helpers
36+
- event-extensions
37+
- event-delegation
38+
- using_delegate_and_undelegate
39+
- working_with_events_part_1
40+
- working_with_events_part_2
41+
- triggering-event-handlers
42+
- introduction-to-custom-events
43+
- effects:
44+
- built-in-effects
45+
- custom-effects
46+
- managing-effects
47+
- queue_and_dequeue_explained
48+
- uses_of_queue_and_dequeue
49+
- ajax:
50+
- key-concepts
51+
- jquery-ajax-methods
52+
- ajax-and-forms
53+
- working-with-jsonp
54+
- ajax-events
55+
- plugins:
56+
- finding-evaluating-plugins
57+
- basic-plugin-creation
58+
- a_plugin_development_pattern
59+
- making_a_jquery_plugin_truly_customizable
60+
- stateful-plugins-with-widget-factory
61+
- performance:
62+
- append-outside-loop
63+
- cache-loop-length
64+
- clever-conditionals
65+
- detach-elements-before-work-with-them
66+
- dont-act-on-absent-elements
67+
- optimize-selectors
68+
- use-stylesheets-for-changing-css
69+
- variable-definition
70+
- read-the-source
71+
- code-organization:
72+
- concepts
73+
- beware-anonymous-functions
74+
- dont-repeat-yourself
75+
- faq:
76+
- add_keyboard_navigation
77+
- enable_the_back_button

0 commit comments

Comments
 (0)