Skip to content

Commit

Permalink
Consider default branch if no branch is provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael committed Jun 29, 2012
1 parent 8fbeede commit 9139b1b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
82 changes: 49 additions & 33 deletions _includes/model.js
Expand Up @@ -151,59 +151,75 @@ function loadBranches(user, repo, cb) {
//
// List all postings for a given site plus load _config.yml

function loadSite(user, repo, branch, path, cb) {
function loadPosts(user, repo, branch, path, cb) {
var repo = getRepo(user, repo);

function getDefaultBranch(cb) {
repo.show(function(err, repo) {
cb(null, repo.master_branch);
});
}

function loadConfig(cb) {
repo.read(branch, "_config.yml", function(err, data) {
if (err) return cb(err);
cb(null, jsyaml.load(data));
});
}

function load() {
loadConfig(function(err, config) {
app.state.jekyll = !err;
app.state.config = config;

loadConfig(function(err, config) {
app.state.jekyll = !err;

app.state.config = config;
if (!path) path = config && config.prose && config.prose.rooturl ? config.prose.rooturl : "";

if (!path) path = config && config.prose && config.prose.rooturl ? config.prose.rooturl : "";

repo.getSha(branch, path, function(err, sha) {
repo.getTree(sha, function(err, tree) {
if (err) return cb("Not found");
repo.getSha(branch, path, function(err, sha) {
repo.getTree(sha, function(err, tree) {
if (err) return cb("Not found");

var paths = _.compact(_.map(tree, function(file) {
return file.type === "tree" ? (path ? path + "/" : "")+ file.path : null;
}));
var paths = _.compact(_.map(tree, function(file) {
return file.type === "tree" ? (path ? path + "/" : "")+ file.path : null;
}));

paths = [path].concat(paths);
paths = [path].concat(paths);

// Include a parent folder path
if (path !== "") paths = [_.parentPath(path)].concat(paths);
// Include a parent folder path
if (path !== "") paths = [_.parentPath(path)].concat(paths);

app.state.config = config;
app.state.paths = paths;
app.state.path = path ? path : paths[0];
app.state.config = config;
app.state.paths = paths;
app.state.path = path ? path : paths[0];

var posts = _.map(tree, function(file) {
// Make sense of the file path
function semantify(file, filetype) {
return {
path: path == "" ? file.path : path + "/"+file.path,
date: "",
filetype: filetype,
title: file.path
};
}
var posts = _.map(tree, function(file) {
// Make sense of the file path
function semantify(file, filetype) {
return {
path: path == "" ? file.path : path + "/"+file.path,
date: "",
filetype: filetype,
title: file.path
};
}

if (file.type === "tree") return null; // Skip directories
if (_.markdown(file.path)) return semantify(file, "markdown");
return semantify(file, "file");
if (file.type === "tree") return null; // Skip directories
if (_.markdown(file.path)) return semantify(file, "markdown");
return semantify(file, "file");
});
cb(null, {"posts": _.compact(posts.reverse())});
});

cb(null, {"posts": _.compact(posts.reverse())});
});
});
}

// Load ahead
if (branch) return load();

// Fallback to default branch
getDefaultBranch(function(err, defaultBranch) {
app.state.branch = branch = defaultBranch;
load();
});
}

Expand Down
1 change: 0 additions & 1 deletion _includes/routers/application.js
Expand Up @@ -47,7 +47,6 @@ routers.Application = Backbone.Router.extend({
// #example-user/example-repo/gh-pages/path/to
// #example-user/example-repo/gh-pages
posts: function(url) {
if (url.split('/').length < 3) return app.instance.notify('error', 'Not Found');
if (confirmExit()) {
app.instance.posts.apply(this, this.extractURL(url));
}
Expand Down
2 changes: 1 addition & 1 deletion _includes/views/application.js
Expand Up @@ -69,7 +69,7 @@ views.Application = Backbone.View.extend({
},

posts: function (user, repo, branch, path) {
loadSite(user, repo, branch, path, _.bind(function (err, data) {
loadPosts(user, repo, branch, path, _.bind(function (err, data) {
if (err) return this.notify('error', 'The requested resource could not be found.');
this.header.render();
this.replaceMainView("posts", new views.Posts({ model: data, id: 'posts' }).render());
Expand Down

0 comments on commit 9139b1b

Please sign in to comment.