Created
December 14, 2013 16:44
-
-
Save yitsushi/7961607 to your computer and use it in GitHub Desktop.
First image as cover image in Ghost
This file contains hidden or 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
diff --git a/core/server/models/post.js b/core/server/models/post.js | |
index b471f51..5e3c680 100644 | |
--- a/core/server/models/post.js | |
+++ b/core/server/models/post.js | |
@@ -44,13 +44,19 @@ Post = ghostBookshelf.Model.extend({ | |
saving: function (newPage, attr, options) { | |
/*jslint unparam:true*/ | |
- var self = this; | |
+ var self = this, | |
+ imageMatch; | |
// Remove any properties which don't belong on the post model | |
this.attributes = this.pick(this.permittedAttributes); | |
this.set('html', converter.makeHtml(this.get('markdown'))); | |
+ imageMatch = this.get('markdown').match(/!\[[^\]]+\]\(([^\)]+)\)/); | |
+ if (imageMatch) { | |
+ this.set('image', imageMatch[1]); | |
+ } | |
+ | |
this.set('title', this.sanitize('title').trim()); | |
if (this.hasChanged('status') && this.get('status') === 'published') { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made it for social sharing:
default.hbs: