Permalink
Browse files

[fix] get file async

  • Loading branch information...
1 parent 553d163 commit 776412498d1e23ef83727c4740d44eefa5f252d2 @Swaagie Swaagie committed Mar 7, 2013
Showing with 13 additions and 9 deletions.
  1. +13 −9 index.js
View
@@ -105,9 +105,12 @@ function walkSync(dir, result, sub) {
// Append file information to current container.
result[current][ref] = {
href: sub ? name.join('/') : '',
- title: get(file).title,
path: dir
};
+
+ get(file, function (error, content) {
+ result[current][ref].title = content.title;
+ });
}
});
@@ -127,14 +130,15 @@ function get(file, callback) {
file = 'index.md';
}
- var content = fs.readFileSync(path.resolve(__dirname + '/content/', file), 'utf8');
-
- return {
- content: content,
- description: scrape(content, 'description'),
- title: scrape(content, 'title'),
- tags: tags(content, 10)
- };
+ file = path.resolve(__dirname + '/content/', file);
+ fs.readFile(file, 'utf8', function read(error, md) {
+ callback.apply(this, [error, {
+ content: md,
+ description: scrape(md, 'description'),
+ title: scrape(md, 'title'),
+ tags: tags(md, 10)
+ }]);
+ });
}
//

0 comments on commit 7764124

Please sign in to comment.