Skip to content

Commit

Permalink
[api]: Added toc to home page
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Aug 26, 2011
1 parent ae39628 commit 857ccb6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
3 changes: 0 additions & 3 deletions lib/generators/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ article.weld = function(dom, articles) {
var metadata = articles[i].metadata;
dom.innerHTML = docs.content.theme['./theme/article.html'].toString();




var data = {
metadata: metadata,
content: content,
Expand Down
38 changes: 35 additions & 3 deletions lib/generators/home.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
var docs = require('../docs');
var docs = require('../docs'),
weld = require('weld').weld,
findit = require('findit'),
helpers = require('../helpers');

var home = exports;

var fs = require('fs');

home.weld = function(dom, data) {

// load all articles
var _articles = findit.sync('./articles');

//
// Filter out all non-markdown files
//
_articles = _articles.filter(function(a){
a = a.replace('./articles', '');
if(a.match(/\./)){
return false;
} else {
return true;
}
});

var toc = helpers.filesToTree(_articles);

// perform weld
dom.innerHTML = docs.content.theme['./theme/index.html'].toString();

var data = {
toc: toc
};

weld(dom, data, {
map: function(parent, element, key, val) {
element.innerHTML = val;
return false;
}
});


return dom;

};

home.generate = function(output, data) {
// write index.html to file system
//fs.writeFileSync('./public/index.html', JSON.stringify(output, true, 2));
fs.writeFileSync('./public/index.html', output);
};

home.load = function(data, dom) {
Expand Down
27 changes: 8 additions & 19 deletions lib/generators/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ theme.weld = function(dom, data) {

theme.generate = function(output, files) {

console.log(Object.keys(files));
// write toc to file system
Object.keys(files).forEach(function(filePath){
// Filter out the weld templates for now
// TODO: refactor this block,
// we should have a better idea of weld tempaltes, not an array
var templates = ['index.html', 'toc.html', 'article.html'];
if(templates.indexOf(path.basename(filePath)) !== -1){
return;
}
var newPath = filePath.replace('./theme', '/../../public');
newPath = path.normalize(__dirname + newPath);
//
Expand All @@ -33,24 +38,8 @@ theme.load = function() {

// load the theme

// Filter out the weld templates for now
var filterTemplates = function (file) {
return true;
// TODO: refactor this block,
// we should have a better idea of weld tempaltes, not an array
/*
var templates = ['index.html', 'toc.html', 'article.html'];
if(templates.indexOf(path.basename(file)) !== -1){
return false;
} else {
return true;
}
*/
};

var theme = helpers.readDir('./theme', true, filterTemplates);
var theme = helpers.readDir('./theme', true);


return theme;

};
2 changes: 1 addition & 1 deletion theme/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<div id="home">
<p><h1><a href="/articles">browse articles...</a></h1></p>
<br/><br/><br/><br/><br/><br/><br/><br/>
<div id="toc"></div>
</div>

<!-- end generated content -->
Expand Down

0 comments on commit 857ccb6

Please sign in to comment.