Skip to content

Instantly share code, notes, and snippets.

@joshisa
Forked from glennblock/posts.js
Last active September 24, 2016 10:48
Show Gist options
  • Select an option

  • Save joshisa/accfd1e644f71809f46c to your computer and use it in GitHub Desktop.

Select an option

Save joshisa/accfd1e644f71809f46c to your computer and use it in GitHub Desktop.
Embedded gist syntax for Ghost. Place in ./core/server/api/posts.js.
//the code below will embed replace [gist id=x] tags with an embedded gist similar to the way the Wordpress Gist
//plugin works. I wrote this in order to import posts from Wordpress. See //GB: for the changes.
//SPJ: Updated for compatibility with Ghost 0.6.4
/**
* ### Read
* Find a post, by ID, UUID, or Slug
*
* @public
* @param {{id_or_slug (required), context, status, include, ...}} options
* @return {Promise(Post)} Post
*/
read: function read(options) {
var attrs = ['id', 'slug', 'status', 'uuid'],
data = _.pick(options, attrs);
options = _.omit(options, attrs);
// only published posts if no user is present
if (!data.uuid && !(options.context && options.context.user)) {
data.status = 'published';
}
if (options.include) {
options.include = prepareInclude(options.include);
}
return dataProvider.Post.findOne(data, options).then(function (result) {
var omitted;
if (result) {
omitted = result.toJSON(options);
omitted.author = _.omit(omitted.author);
omitted.user = _.omit(omitted.user);
//GB: replace the gist tag with the embedded gist
omitted.html = omitted.html.replace(/\[gist id=([a-z0-9]+)\]/g, "<script src=\"https://gist.github.com/$1.js\"></script>");
return {posts: [omitted]};
}
return Promise.reject(new errors.NotFoundError('Post not found.'));
});
},
@joshisa

joshisa commented Dec 8, 2015

Copy link
Copy Markdown
Author

Gisto comment added

@joshisa

joshisa commented Dec 8, 2015

Copy link
Copy Markdown
Author

One more BluemixGisto comment

@joshisa

joshisa commented Dec 8, 2015

Copy link
Copy Markdown
Author

with pain is gain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment