-
-
Save joshisa/accfd1e644f71809f46c to your computer and use it in GitHub Desktop.
Embedded gist syntax for Ghost. Place in ./core/server/api/posts.js.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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.')); | |
}); | |
}, |
This hack mod works with Ghost 0.6.4
Gisto comment added
One more BluemixGisto comment
with pain is gain
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change is required since it seems that gists now have id's that are alphanumeric. Therefore, the regex needs to be changed from [0-9] to [a-z0-9] for both references. Also, to allow more than one gist embed, I needed to add the global modifier /g to the regex expression. Demo found @ https://blueghostrox.mybluemix.net/autoarchive-testing-underway/