Stackedit/src/services/providers/wordpressProvider.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-09-26 22:54:26 +00:00
import store from '../../store';
import wordpressHelper from './helpers/wordpressHelper';
2018-04-27 14:37:05 +00:00
import Provider from './common/Provider';
2017-09-26 22:54:26 +00:00
2018-04-27 14:37:05 +00:00
export default new Provider({
2017-09-26 22:54:26 +00:00
id: 'wordpress',
getToken(location) {
return store.getters['data/wordpressTokens'][location.sub];
},
getUrl(location) {
return `https://wordpress.com/post/${location.siteId}/${location.postId}`;
},
getDescription(location) {
const token = this.getToken(location);
return `${location.postId}${location.domain}${token.name}`;
},
publish(token, html, metadata, publishLocation) {
return wordpressHelper.uploadPost(
token,
publishLocation.domain,
publishLocation.siteId,
publishLocation.postId,
metadata.title,
html,
metadata.tags,
metadata.categories,
metadata.excerpt,
metadata.author,
metadata.featuredImage,
metadata.status,
metadata.date,
)
.then(post => ({
...publishLocation,
siteId: `${post.site_ID}`,
postId: `${post.ID}`,
}));
},
makeLocation(token, domain, postId) {
const location = {
providerId: this.id,
sub: token.sub,
domain,
};
if (postId) {
location.postId = postId;
}
return location;
},
});