Skip to content

Commit 31f27d7

Browse files
committed
use parent/child pages in wordpress instead of using taxonomy
1 parent bc08dee commit 31f27d7

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

nanoc2wordpress/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ function processSite( finish ) {
4949
console.log( "Truncating wordpress tables" )
5050
wordpress.reset( this );
5151
},
52-
// Step 5: Create Wordpress Taxonomy
52+
// Step 5: Create Wordpress Parent Pages for categories
5353
function() {
54-
console.log( "Creating WordPress Taxonomy" )
55-
wordpress.createTerms( site.categories, this )
54+
console.log( "Creating WordPress Parent Pages" )
55+
wordpress.createPages( site.categories, this )
5656
},
5757
// Step 6: Create articles in WordPress
5858
function(){
59-
console.log( "Creating WordPress Pages" );
59+
console.log( "Creating WordPress Pages for Articles" );
6060
wordpress.createPages( site.articles, this )
6161
},
6262
// Step 7: Flush WordPress rewrite rules

nanoc2wordpress/nanoc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ function compile( continuation ) {
3030
}
3131

3232
function findFiles( continuation ) {
33-
var finder = require( "findit" ).find( OUTPUT_DIR );
33+
var finder = require( "findit" ).find( OUTPUT_DIR ),
34+
ts = new Date();
3435

3536
finder.on( "file", function( file ) {
3637
var locPath = file.replace( OUTPUT_DIR, "" ),
@@ -40,9 +41,9 @@ function findFiles( continuation ) {
4041
if ( isHome ) {
4142
// TODO: Deal with home page
4243
} else if ( isCategory ) {
43-
site.categories.push({ path: file })
44+
site.categories.push({ path: file, isCategory: true, date: ts })
4445
} else if ( locPath.indexOf("/assets/") !=0 ) {
45-
site.articles.push({ path: file });
46+
site.articles.push({ path: file, isCategory: false, date: ts });
4647
}
4748
});
4849

@@ -66,6 +67,7 @@ function processCategories( continuation ) {
6667
if (meta) {
6768
_.extend( cat, JSON.parse(meta.textContent) )
6869
cat.contents = _.trim(cat.contents.replace( META_REGEX, ""));
70+
cat.slug = cat.chapter;
6971
}
7072
});
7173
continuation();
@@ -86,15 +88,13 @@ function processArticles( continuation ) {
8688
});
8789
},
8890
function processMeta(err, windows) {
89-
var ts = new Date();
9091
windows.forEach( function(win, index) {
9192
var meta = win.document.getElementById('nanoc_meta'),
9293
file = site.articles[ index ];
9394
if (meta) {
9495
_.extend( file, JSON.parse(meta.textContent) )
9596
file.contents = _.trim(file.contents.replace( META_REGEX, ""));
9697
file.slug = file.filename.replace( "/"+file.chapter+ "/", "").replace("/index.html", "");
97-
file.date = ts;
9898
}
9999
});
100100
continuation();

nanoc2wordpress/wordpress.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var mysql = require("mysql"),
22
Step = require("step"),
33
config = require("./config");
44

5-
var db, postIds = {}, categoryMap = {},
5+
var db, categoryMap = {},
66
optionsTable = table("options"),
77
postmetaTable = table("postmeta"),
88
postsTable = table("posts"),
@@ -65,7 +65,11 @@ var wordpress = module.exports = {
6565
}
6666

6767
page.id = info.insertId;
68-
postIds[page.slug] = info.insertId;
68+
69+
if ( page.isCategory ) {
70+
categoryMap[ page.chapter ] = page.id
71+
}
72+
6973
var guid = "http://" + config.host_name + "/?p=" + page.id;
7074
db.query(
7175
"UPDATE " + postsTable + " SET `guid`=? WHERE id=?",
@@ -74,16 +78,19 @@ var wordpress = module.exports = {
7478
);
7579

7680
},
77-
function setTerm(error, info) {
81+
function (error, info) {
7882
if (error) {
7983
throw error;
8084
}
81-
82-
db.query(
83-
"INSERT INTO `" + termRelationshipsTable + "` " + "SET `object_id` = ?, `term_taxonomy_id` = ?",
84-
[ page.id, categoryMap[page.chapter] ],
85-
this
86-
);
85+
if ( page.isCategory ) {
86+
return this( null );
87+
} else {
88+
db.query(
89+
"UPDATE " + postsTable + " SET `post_parent`=? WHERE id=?",
90+
[ categoryMap[page.chapter], page.id ],
91+
this
92+
);
93+
}
8794
},
8895
function(error) {
8996
if (error) {

0 commit comments

Comments
 (0)