Support for published and date variables in YAML front matter. Fixes #222, fixes #220, fixes #146, fixes #72

This commit is contained in:
benweet 2013-12-08 18:05:49 +00:00
parent 0be5402e83
commit 511ffafbf0
6 changed files with 51 additions and 10 deletions

View File

@ -720,7 +720,7 @@ define([
task.enqueue(); task.enqueue();
}; };
googleHelper.uploadBlogger = function(blogUrl, blogId, postId, labelList, title, content, callback) { googleHelper.uploadBlogger = function(blogUrl, blogId, postId, labelList, isDraft, publishDate, title, content, callback) {
var task = new AsyncTask(); var task = new AsyncTask();
connect(task); connect(task);
authenticate(task, 'blogger'); authenticate(task, 'blogger');
@ -730,7 +730,7 @@ define([
if(token) { if(token) {
headers.Authorization = "Bearer " + token.access_token; headers.Authorization = "Bearer " + token.access_token;
} }
function publish() { function uploadPost() {
var url = "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/posts/"; var url = "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/posts/";
var data = { var data = {
kind: "blogger#post", kind: "blogger#post",
@ -758,7 +758,7 @@ define([
timeout: constants.AJAX_TIMEOUT timeout: constants.AJAX_TIMEOUT
}).done(function(post) { }).done(function(post) {
postId = post.id; postId = post.id;
task.chain(); task.chain(publish);
}).fail(function(jqXHR) { }).fail(function(jqXHR) {
var error = { var error = {
code: jqXHR.status, code: jqXHR.status,
@ -771,9 +771,40 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
function publish() {
var url = "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/posts/" + postId;
if(isDraft) {
url += "/revert";
}
else {
url += "/publish";
if(publishDate) {
url += '?publishDate=' + publishDate.toISOString();
}
}
$.ajax({
url: url,
headers: headers,
type: 'POST',
dataType: "json",
timeout: constants.AJAX_TIMEOUT
}).done(function(post) {
task.chain();
}).fail(function(jqXHR) {
var error = {
code: jqXHR.status,
message: jqXHR.statusText
};
// Handle error
if(error.code === 404) {
error = 'Post ' + postId + ' not found on Blogger.|removePublish';
}
handleError(error, task);
});
}
function getBlogId() { function getBlogId() {
if(blogId !== undefined) { if(blogId !== undefined) {
task.chain(publish); task.chain(uploadPost);
return; return;
} }
$.ajax({ $.ajax({
@ -786,7 +817,7 @@ define([
timeout: constants.AJAX_TIMEOUT timeout: constants.AJAX_TIMEOUT
}).done(function(blog) { }).done(function(blog) {
blogId = blog.id; blogId = blog.id;
task.chain(publish); task.chain(uploadPost);
}).fail(function(jqXHR) { }).fail(function(jqXHR) {
var error = { var error = {
code: jqXHR.status, code: jqXHR.status,

View File

@ -110,7 +110,7 @@ define([
}); });
} }
tumblrHelper.upload = function(blogHostname, postId, tags, format, title, content, callback) { tumblrHelper.upload = function(blogHostname, postId, tags, format, state, date, title, content, callback) {
var task = new AsyncTask(); var task = new AsyncTask();
connect(task); connect(task);
authenticate(task); authenticate(task);
@ -120,6 +120,8 @@ define([
post_id: postId, post_id: postId,
tags: tags, tags: tags,
format: format, format: format,
state: state,
date: date,
title: title, title: title,
content: content content: content
}, oauthParams); }, oauthParams);

View File

@ -94,7 +94,7 @@ define([
}); });
} }
wordpressHelper.upload = function(site, postId, tags, title, content, callback) { wordpressHelper.upload = function(site, postId, tags, status, date, title, content, callback) {
var task = new AsyncTask(); var task = new AsyncTask();
connect(task); connect(task);
authenticate(task); authenticate(task);
@ -105,6 +105,8 @@ define([
site: site, site: site,
postId: postId, postId: postId,
tags: tags, tags: tags,
status: status,
date: date,
title: title, title: title,
content: content content: content
}; };

View File

@ -17,7 +17,9 @@ define([
frontMatter.tags !== undefined && (labelList = frontMatter.tags); frontMatter.tags !== undefined && (labelList = frontMatter.tags);
} }
_.isString(labelList) && (labelList = _.compact(labelList.split(/[\s,]/))); _.isString(labelList) && (labelList = _.compact(labelList.split(/[\s,]/)));
googleHelper.uploadBlogger(publishAttributes.blogUrl, publishAttributes.blogId, publishAttributes.postId, labelList, title, content, function(error, blogId, postId) { var isDraft = frontMatter && frontMatter.published === false;
var publishDate = frontMatter && frontMatter.date;
googleHelper.uploadBlogger(publishAttributes.blogUrl, publishAttributes.blogId, publishAttributes.postId, labelList, isDraft, publishDate, title, content, function(error, blogId, postId) {
if(error) { if(error) {
callback(error); callback(error);
return; return;

View File

@ -32,7 +32,9 @@ define([
return 'markdown'; return 'markdown';
})(); })();
tumblrHelper.upload(publishAttributes.blogHostname, publishAttributes.postId, labelList.join(','), format, title, content, function(error, postId) { var state = (frontMatter && frontMatter.published === false) ? 'draft' : 'published';
var date = frontMatter && frontMatter.date;
tumblrHelper.upload(publishAttributes.blogHostname, publishAttributes.postId, labelList.join(','), format, state, date, title, content, function(error, postId) {
if(error) { if(error) {
callback(error); callback(error);
return; return;

View File

@ -16,8 +16,10 @@ define([
if(frontMatter) { if(frontMatter) {
frontMatter.tags !== undefined && (labelList = frontMatter.tags); frontMatter.tags !== undefined && (labelList = frontMatter.tags);
} }
var status = (frontMatter && frontMatter.published === false) ? 'draft' : 'publish';
var date = frontMatter && frontMatter.date;
_.isString(labelList) && (labelList = _.compact(labelList.split(/[\s,]/))); _.isString(labelList) && (labelList = _.compact(labelList.split(/[\s,]/)));
wordpressHelper.upload(publishAttributes.site, publishAttributes.postId, labelList.join(','), title, content, function(error, postId) { wordpressHelper.upload(publishAttributes.site, publishAttributes.postId, labelList.join(','), status, date, title, content, function(error, postId) {
if(error) { if(error) {
callback(error); callback(error);
return; return;