Merge branch 'bloggerpage' of https://github.com/wiibaa/stackedit into wiibaa-bloggerpage
This commit is contained in:
commit
a3b8211b42
@ -943,6 +943,96 @@ define([
|
|||||||
task.enqueue();
|
task.enqueue();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
googleHelper.uploadBloggerPage = function(blogUrl, blogId, pageId, isDraft, publishDate, title, content, callback) {
|
||||||
|
var accountId = 'google.blogger0';
|
||||||
|
var task = new AsyncTask();
|
||||||
|
connect(task);
|
||||||
|
authenticate(task, 'blogger', accountId);
|
||||||
|
task.onRun(function() {
|
||||||
|
var headers = {};
|
||||||
|
var authorizationMgr = authorizationMgrMap[accountId];
|
||||||
|
if(authorizationMgr && authorizationMgr.token) {
|
||||||
|
headers.Authorization = "Bearer " + authorizationMgr.token.access_token;
|
||||||
|
}
|
||||||
|
function uploadPage() {
|
||||||
|
var url = "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/pages/";
|
||||||
|
var data = {
|
||||||
|
kind: "blogger#page",
|
||||||
|
blog: {
|
||||||
|
id: blogId
|
||||||
|
},
|
||||||
|
title: title,
|
||||||
|
content: content
|
||||||
|
};
|
||||||
|
var type = "POST";
|
||||||
|
// If it's an update
|
||||||
|
if(pageId !== undefined) {
|
||||||
|
url += pageId;
|
||||||
|
data.id = pageId;
|
||||||
|
type = "PUT";
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
headers: headers,
|
||||||
|
type: type,
|
||||||
|
contentType: "application/json",
|
||||||
|
dataType: "json",
|
||||||
|
timeout: constants.AJAX_TIMEOUT
|
||||||
|
}).done(function(page) {
|
||||||
|
pageId = page.id;
|
||||||
|
task.chain();
|
||||||
|
}).fail(function(jqXHR) {
|
||||||
|
var error = {
|
||||||
|
code: jqXHR.status,
|
||||||
|
message: jqXHR.statusText
|
||||||
|
};
|
||||||
|
// Handle error
|
||||||
|
if(error.code === 404 && pageId !== undefined) {
|
||||||
|
error = 'Page ' + pageId + ' not found on Blogger.|removePublish';
|
||||||
|
}
|
||||||
|
handleError(error, task);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function getBlogId() {
|
||||||
|
if(blogId !== undefined) {
|
||||||
|
task.chain(uploadPage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: "https://www.googleapis.com/blogger/v3/blogs/byurl",
|
||||||
|
data: {
|
||||||
|
url: blogUrl
|
||||||
|
},
|
||||||
|
headers: headers,
|
||||||
|
dataType: "json",
|
||||||
|
timeout: constants.AJAX_TIMEOUT
|
||||||
|
}).done(function(blog) {
|
||||||
|
blogId = blog.id;
|
||||||
|
task.chain(uploadPage);
|
||||||
|
}).fail(function(jqXHR) {
|
||||||
|
var error = {
|
||||||
|
code: jqXHR.status,
|
||||||
|
message: jqXHR.statusText
|
||||||
|
};
|
||||||
|
// Handle error
|
||||||
|
if(error.code === 404) {
|
||||||
|
error = 'Blog "' + blogUrl + '" not found on Blogger.|removePublish';
|
||||||
|
}
|
||||||
|
handleError(error, task);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
task.chain(getBlogId);
|
||||||
|
});
|
||||||
|
task.onSuccess(function() {
|
||||||
|
callback(undefined, blogId, pageId);
|
||||||
|
});
|
||||||
|
task.onError(function(error) {
|
||||||
|
callback(error);
|
||||||
|
});
|
||||||
|
task.enqueue();
|
||||||
|
};
|
||||||
|
|
||||||
// Use by Google's client.js
|
// Use by Google's client.js
|
||||||
window.delayedFunction = undefined;
|
window.delayedFunction = undefined;
|
||||||
window.runDelayedFunction = function() {
|
window.runDelayedFunction = function() {
|
||||||
|
@ -683,7 +683,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group modal-publish-blogger">
|
<div class="form-group modal-publish-blogger modal-publish-bloggerpage">
|
||||||
<label class="col-lg-4 control-label"
|
<label class="col-lg-4 control-label"
|
||||||
for="input-publish-blogger-url">Blog URL</label>
|
for="input-publish-blogger-url">Blog URL</label>
|
||||||
<div class="col-lg-7">
|
<div class="col-lg-7">
|
||||||
@ -720,6 +720,15 @@
|
|||||||
class="form-control">
|
class="form-control">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
class="form-group modal-publish-bloggerpage">
|
||||||
|
<label class="col-lg-4 control-label" for="input-publish-pageid">Update
|
||||||
|
existing page ID (optional)</label>
|
||||||
|
<div class="col-lg-7">
|
||||||
|
<input type="text" id="input-publish-pageid" placeholder="PageID"
|
||||||
|
class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group modal-publish-dropbox">
|
<div class="form-group modal-publish-dropbox">
|
||||||
<label class="col-lg-4 control-label"
|
<label class="col-lg-4 control-label"
|
||||||
for="input-publish-dropbox-path">File path</label>
|
for="input-publish-dropbox-path">File path</label>
|
||||||
@ -799,6 +808,18 @@
|
|||||||
target="_blank">YAML front matter</a> to specify the title and the tags/labels of your publication.</p>
|
target="_blank">YAML front matter</a> to specify the title and the tags/labels of your publication.</p>
|
||||||
<p><b>Interpreted variables:</b> <code>title</code>, <code>tags</code>, <code>published</code>, <code>date</code>.</p>
|
<p><b>Interpreted variables:</b> <code>title</code>, <code>tags</code>, <code>published</code>, <code>date</code>.</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
<blockquote class="front-matter-info modal-publish-bloggerpage">
|
||||||
|
<p><b>Tip:</b> You can use a
|
||||||
|
<a href="http://jekyllrb.com/docs/frontmatter/"
|
||||||
|
target="_blank">YAML front matter</a> to specify the title of your page.</p>
|
||||||
|
<p><b>Interpreted variables:</b> <code>title</code>.</p>
|
||||||
|
</blockquote>
|
||||||
|
<blockquote class="url-info modal-publish-bloggerpage">
|
||||||
|
<p><b>About URL:</b> For newly created page , Blogger API will append a generated number to the url like <code>about-me-1234.html</code>, if you deeply care about your URL naming, you should first create the page on Blogger and then update them with StackEdit specifying the pageId when publishing.
|
||||||
|
</p>
|
||||||
|
<p><b>About page visibility:</b> Blogger API does not respect published status for pages.When publishing the page to Blogger, the page will be <strong>live</strong> but not added to the page listing. You should arrange the page listing from Blogger dashboard.
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<a href="#" class="btn btn-default" data-dismiss="modal">Cancel</a>
|
<a href="#" class="btn btn-default" data-dismiss="modal">Cancel</a>
|
||||||
|
42
public/res/providers/bloggerPageProvider.js
Normal file
42
public/res/providers/bloggerPageProvider.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
define([
|
||||||
|
"underscore",
|
||||||
|
"utils",
|
||||||
|
"classes/Provider",
|
||||||
|
"helpers/googleHelper"
|
||||||
|
], function(_, utils, Provider, googleHelper) {
|
||||||
|
|
||||||
|
var bloggerPageProvider = new Provider("bloggerpage", "Blogger Page");
|
||||||
|
bloggerPageProvider.defaultPublishFormat = "html";
|
||||||
|
bloggerPageProvider.publishPreferencesInputIds = [
|
||||||
|
"blogger-url"
|
||||||
|
];
|
||||||
|
|
||||||
|
bloggerPageProvider.publish = function(publishAttributes, frontMatter, title, content, callback) {
|
||||||
|
var isDraft = frontMatter && frontMatter.published === false;
|
||||||
|
var publishDate = frontMatter && frontMatter.date;
|
||||||
|
googleHelper.uploadBloggerPage(publishAttributes.blogUrl, publishAttributes.blogId, publishAttributes.pageId, isDraft, publishDate, title, content, function(error, blogId, pageId) {
|
||||||
|
if(error) {
|
||||||
|
callback(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
publishAttributes.blogId = blogId;
|
||||||
|
publishAttributes.pageId = pageId;
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
bloggerPageProvider.newPublishAttributes = function(event) {
|
||||||
|
var publishAttributes = {};
|
||||||
|
var blogUrl = utils.getInputTextValue("#input-publish-blogger-url", event);
|
||||||
|
if(blogUrl !== undefined) {
|
||||||
|
publishAttributes.blogUrl = utils.checkUrl(blogUrl);
|
||||||
|
}
|
||||||
|
publishAttributes.pageId = utils.getInputTextValue("#input-publish-pageid");
|
||||||
|
if(event.isPropagationStopped()) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return publishAttributes;
|
||||||
|
};
|
||||||
|
|
||||||
|
return bloggerPageProvider;
|
||||||
|
});
|
@ -12,6 +12,7 @@ define([
|
|||||||
"classes/Provider",
|
"classes/Provider",
|
||||||
"classes/AsyncTask",
|
"classes/AsyncTask",
|
||||||
"providers/bloggerProvider",
|
"providers/bloggerProvider",
|
||||||
|
"providers/bloggerPageProvider",
|
||||||
"providers/dropboxProvider",
|
"providers/dropboxProvider",
|
||||||
"providers/gistProvider",
|
"providers/gistProvider",
|
||||||
"providers/githubProvider",
|
"providers/githubProvider",
|
||||||
|
@ -346,7 +346,7 @@ kbd {
|
|||||||
background-position: -54px 0;
|
background-position: -54px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon-provider-blogger {
|
.icon-provider-blogger, .icon-provider-bloggerpage {
|
||||||
background-position: -72px 0;
|
background-position: -72px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user