Support for published and date variables in YAML front matter. Fixes #222, fixes #220, fixes #146, fixes #72
This commit is contained in:
parent
0be5402e83
commit
511ffafbf0
@ -720,7 +720,7 @@ define([
|
||||
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();
|
||||
connect(task);
|
||||
authenticate(task, 'blogger');
|
||||
@ -730,7 +730,7 @@ define([
|
||||
if(token) {
|
||||
headers.Authorization = "Bearer " + token.access_token;
|
||||
}
|
||||
function publish() {
|
||||
function uploadPost() {
|
||||
var url = "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/posts/";
|
||||
var data = {
|
||||
kind: "blogger#post",
|
||||
@ -758,7 +758,7 @@ define([
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function(post) {
|
||||
postId = post.id;
|
||||
task.chain();
|
||||
task.chain(publish);
|
||||
}).fail(function(jqXHR) {
|
||||
var error = {
|
||||
code: jqXHR.status,
|
||||
@ -771,9 +771,40 @@ define([
|
||||
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() {
|
||||
if(blogId !== undefined) {
|
||||
task.chain(publish);
|
||||
task.chain(uploadPost);
|
||||
return;
|
||||
}
|
||||
$.ajax({
|
||||
@ -786,7 +817,7 @@ define([
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function(blog) {
|
||||
blogId = blog.id;
|
||||
task.chain(publish);
|
||||
task.chain(uploadPost);
|
||||
}).fail(function(jqXHR) {
|
||||
var error = {
|
||||
code: jqXHR.status,
|
||||
|
@ -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();
|
||||
connect(task);
|
||||
authenticate(task);
|
||||
@ -120,6 +120,8 @@ define([
|
||||
post_id: postId,
|
||||
tags: tags,
|
||||
format: format,
|
||||
state: state,
|
||||
date: date,
|
||||
title: title,
|
||||
content: content
|
||||
}, oauthParams);
|
||||
|
@ -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();
|
||||
connect(task);
|
||||
authenticate(task);
|
||||
@ -105,6 +105,8 @@ define([
|
||||
site: site,
|
||||
postId: postId,
|
||||
tags: tags,
|
||||
status: status,
|
||||
date: date,
|
||||
title: title,
|
||||
content: content
|
||||
};
|
||||
|
@ -17,7 +17,9 @@ define([
|
||||
frontMatter.tags !== undefined && (labelList = frontMatter.tags);
|
||||
}
|
||||
_.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) {
|
||||
callback(error);
|
||||
return;
|
||||
|
@ -32,7 +32,9 @@ define([
|
||||
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) {
|
||||
callback(error);
|
||||
return;
|
||||
|
@ -16,8 +16,10 @@ define([
|
||||
if(frontMatter) {
|
||||
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,]/)));
|
||||
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) {
|
||||
callback(error);
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user