Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rewrite to add multiple accounts / blogs and git commits

* files are configured via _config.yml
	(see README.md for configuration instructions)
* commits are handled via backticked shell calls
	This is admittedly fragile. Grit would be preferred.
* code for handling commits via Grit is included but commented out
	as it always results in "fatal: corrupt tree file"
	when you try and do almost anything with the repo after committing to it.
  • Loading branch information...
commit b5a43ca9bf1b6033fdad25d1ded36c3431e31564 1 parent c4c45c2
@masukomi authored committed
View
1  .gitignore
@@ -1 +0,0 @@
-Gemfile.lock
View
2  Gemfile
@@ -2,4 +2,4 @@ source "http://rubygems.org"
gem 'mail'
gem 'nokogiri'
-
+#gem 'grit'
View
30 Gemfile.lock
@@ -0,0 +1,30 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ diff-lcs (1.1.3)
+ fileutils (0.7)
+ rmagick (>= 2.13.1)
+ grit (2.4.1)
+ diff-lcs (~> 1.1)
+ mime-types (~> 1.15)
+ i18n (0.6.0)
+ mail (2.3.0)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ nokogiri (1.5.0)
+ polyglot (0.3.2)
+ rmagick (2.13.1)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ fileutils
+ grit
+ mail
+ nokogiri
View
148 README.md
@@ -1,11 +1,19 @@
# JekyllMail #
-JekyllMail enables you to post to your [Jekyll](https://github.com/mojombo/jekyll) / [Octopress](http://octopress.org/) powered blog by email.
+JekyllMail enables you to post to your [Jekyll](https://github.com/mojombo/jekyll)
+or [Octopress](http://octopress.org/) powered blog by email.
## How it Works ##
-Once configured (see below) JekyllMail will log into a POP3 account, check for messages with a pre-defined secret in the subject line, convert them into appropriately named files, and save them in your _posts or _drafts directory. After that your normal Jekyll watcher process can take over and do its thing.
+Once configured (see below) JekyllMail will log into a POP3 account, check for messages with
+a pre-defined secret in the subject line, convert them into appropriately named files, and
+save them in your `_posts` directory. Images will be extracted and saved in a date specific
+directory under your `images` directory.
+
+Once it's placed those files there it will (optionally) also add them to your blog's git repo.
+This will work even if it's a bare repo and the `source` directory you had it save files under
+is in a detached worktree.
+
-**Warning:** At the end of every run JekyllMail *deletes every e-mail* in the account. This is for two reasons: 1) we don't want to have to maintain a list of what e-mails we've already ingested and posted 2) once an e-mail's been ingested we don't need it 3) there are probably 400 spam e-mails in the account that should be deleted. 4) less e-mail in the box means faster runs.... ok four reasons.
## Usage ##
The magic is all in the subject line. In order to differentiate your email from the spam that's almost guaranteed to find your account eventually suck in the appropriate metadata A subject line for JekyllMail has two parts the title (of your post) and the metadata which will go into the YAML frontmatter Jekyll needs. The metadata is a series of key value pairs separated by slashes. One of those key value pairs *must* be "secret" and the secret listed in your configuration. Note that the keys must contain no spaces and be immediately followed by a colon.
@@ -20,53 +28,135 @@ Your secret should be short, easy to remember, easy to type, and very unlikely t
Your e-mail can be formatted in Markdown, Textile, or HTML.
### Subject Metadata ###
-There are a handful of keys that JekyllMail is specifically looking for. All of these are optional except "secret":
+There are a handful of keys that JekyllMail is specifically looking for in the subject.
+**All of these are optional except "secret"**:
-* published: defaults to true. Set this to "false" if you want this post to be saved in the _drafts folder.
+* published: defaults to true. Set this to "false" to prevent the post from being published.
* markup: can be: html, markdown, md, textile, txt (textile)
* tags: expects a comma separated list of tags for your post
* slug: the "slug" for the file-name. E.g. yyyy-mm-dd-*slug*.extension
### Images ###
-Image attachments will be extracted by JekyllMail and placed in dated directory that corresponds with the date of the posting.
+Image attachments will be extracted by JekyllMail and placed in dated directory
+that corresponds with the date of the posting.
+
+For example If you attached flag.jpg to a post sent on July 4th 2012 it would be
+stored in <images_dir>/2012/07/04/flag.jpg
-For example If you attached flag.jpg to a post sent on July 4th 2012 it would be stored in <images_dir>/2012/07/04/flag.jpg
+JekyllMail will look for the image tags in your document that reference the image
+filename and update them to point to the correct published file path. For example
+it will convert \!\[alt text\]\(flag.jpg\) in a Markdown document to
+\!\[alt text\]\(http://example.com/path/to/images/dir/2012/07/04/flag.jpg\).
+Textile and HTML posts are also supported.
-JekyllMail will look for the image tags in your document that reference the image filename and update them to point to the correct published file path. For example it will convert \!\[alt text\]\(flag.jpg\) in a Markdown document to \!\[alt text\]\(http://path/to/images/dir/2012/07/04/flag.jpg\). Textile and HTML posts are also supported.
+In practice this simply means that if you insert a \!\[alt text\]\(flag.jpg\)
+tag and attach an image named flag.jpg to the same email everything will
+show up as expected in your post even though JekyllMail has moved that image
+off to a dated subdirectory (just like the post's url).
+
+## Installation ##
+Checkout this git repo on your server, cd into the resulting directory, and
+run `bundle install` to make sure all the required gems are present.
-In practice this simply means that if you insert a \!\[alt text\]\(flag.jpg\) tag and attach an image named flag.jpg to the same email everything will show up as expected in your post even though JekyllMail has moved that image off to a dated subdirectory (just like the post).
## Configuration ##
-If you're using Jekyll you're using git. JekyllMail is configured via its own section of you global [git config](http://kernel.org/pub/software/scm/git/docs/git-config.html).
+JekyllMail is configured via a \_config.yml file in its root directory.
+Within this are a series of "blog" stanzas one for each blog you'll have
+it checking mail for.
+
+A single blog config file will look something like this
+
+ blogs:
+ - jekyll_repo: /full/path/to/jekyll/repo
+ source_dir: /full/path/to/jekyll/source
+ pop_server: mail.example.com
+ pop_user: jekyllmail@example.com
+ pop_password: mypassword
+ secret: a_secret
+ markup: markdown
+ site_url: http://blog.example.com
+ commit_after_save: true
+
+### Configuration Notes ###
+The `secret` is a short piece of text that must appear in the subject of
+each email. This is used to filter out the spam and will never be posted.
+
+If `commit_after_save` is true JekyllMail will add and commit any new post
+and images to the repo specified in `jekyll_repo`.
+
+The `source_dir` must be the absolut paths to the directory containing
+the `_posts` and `images` directories. JekyllMail does not
+currently support a configuration where these directories live elsewhere.
+However, this is where
- [jekyllmail]
- jekyllRepo = /path/to/my_jekyll_repo
- postsDir = /path/to/my_jekyll_repo/source/_posts
- draftsDir = /path/to/my_jekyll_repo/source/_drafts
- imagesDir = /path/to/my_jekyll_repo/images
- popServer = mail.example.com
- popPassword = 1x2x3fdc3
- popUser = jekyllmail@example.com
- secret = easy-to-remember-hard-to-guess
- defaultMarkup = markdown
- siteUrl = http://www.example.com
- commitAfterSave = true
- pushAfterSave = origin master
+Please note that paths must *not* end with a slash.
+Your `pop_user` doesn't have to be an e-mail address. It might just be
+"jekyllmail", or whatever username you've chosen for the e-mail account.
+It all depends on how your server is configured. It's probably best to use
+something other than "jekyllmail" though.
+## Cron Jobs ##
+You need to schedule two tasks to run regularly: JekyllMail itself, and
+a script to kick-off the generation of new HTML files once JekyllMail has
+done its job and commited the new files to your blog's git repo.
-You can add these to your ~/.gitconfig by editing it directly or by commands like the following:
+There are a variety of ways to accomplish this. The simplest way is
+probably to create a shell script.
- git config --global add jekyllmail.postsDir /path/to/my_jekyll_site/source/_posts
+To kick of JekyllMail it might look something like this:
+
+ #!/bin/sh
+ cd /full/path/to/jekyllmail
+ bundle exec ruby jekyllmail.rb
+
+To kick off the generation of the new HTML you'll need a second
+script like this:
+
+ #!/bin/sh
+ cd /full/path/to/blogs/worktree
+ bundle exec rake generate
+
+Depending on your server's ruby / gem configuration you may have to add some
+additional info to the top of those ( just below the `#!/bin/sh` ). On a system
+with a locally installed RVM and gems directory the top of your script might
+look something like this:
+
+ #!/bin/sh
+ [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
+ GEM_PATH=$GEM_PATH:/home/my_username/.gems
+ PATH=$PATH:/home/my_username/.gems/bin
+
+To help get you started check out the `run_jekyllmail.sh` and `build_site.sh`
+scripts that come along with the repo.
+
+For more information on configuring Jekyll/Octopress to generate HTML server-side
+see this post on [Serving Octopress from a Self-Hosted Git Repository](http://weblog.masukomi.org/2011/12/19/serving-octopress-from-a-self-hosted-git-repository/)
+
+Save the file anywhere that isn't served up to the public, make it executable,
+and add a new line to your [crontab](http://crontab.org/) to run it every five
+minutes or so.
+
+
+## Warning ##
+At the end of every run JekyllMail *deletes every e-mail* in the account.
+This is for two reasons:
+
+1. We don't want to have to maintain a list of what e-mails we've already ingested and posted
+2. Once an e-mail's been ingested we don't need it
+3. There are probably 400 spam e-mails in the account that should be deleted anyway.
+4. less e-mail in the box means faster runs
+
+Ok, four reasons.
-Please note that paths must *not* end with a slash.
-Your popUser doesn't have to be an e-mail address. It might just be "jekyllmail", or whatever username you've chosen for the e-mail account. It all depends on how your server is configured.
### Known Issues ###
-Check out the [Issues page](https://github.com/masukomi/JekyllMail/issues) on Github for the current list of known issues.
+Check out the [Issues page](https://github.com/masukomi/JekyllMail/issues) on
+Github for the current list of known issues (if any).
## Credit where credit is due ##
-JekyllMail was based on a [post & gist](http://tedkulp.com/2011/05/18/send-email-to-jekyll/) by [Ted Kulp](http://tedkulp.com/). He did all the heavy lifting. JekyllMail is simply a more generic version that speaks POP3, is more spam resistent, and should work for anyone.
+JekyllMail was based on a [post & gist](http://tedkulp.com/2011/05/18/send-email-to-jekyll/)
+by [Ted Kulp](http://tedkulp.com/), but has come a long way since then.
## License ##
JekyllMail is distributed under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
View
11 _config.yml
@@ -0,0 +1,11 @@
+---
+blogs:
+- jekyll_repo: /home/username/workspace/jekyll_test_site
+ source_dir: /home/username/workspace/jekyll_test_site/source
+ pop_server: mail.example.com
+ pop_user: jekyllmail@example.com
+ pop_password: password_here
+ secret: jekyllmail
+ markup: markdown
+ site_url: http://blog.example.com
+ commit_after_save: true
View
9 build_site.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# CHANGE ME TO MEET THE NEEDS OF YOUR SERVER CONFIGURATION
+
+[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
+GEM_PATH=$GEM_PATH:/home/my_username/.gems
+PATH=$PATH:/home/my_username/.gems/bin
+cd /home/my_username/jekyll/
+bundle exec rake generate
View
349 jekyllmail.rb
@@ -10,172 +10,243 @@
# TODO
# error handling:
-# - complain if any of the required prefs are not defined
+# - complain if any of the required blog are not defined
require 'rubygems'
+require 'yaml'
require 'net/pop'
require 'mail'
require 'nokogiri'
require 'fileutils'
+#require 'grit'
+#include Grit
+
+
+DEBUG = false
+
+#JEKYLLMAIL_USER= Actor.from_string("JekyllMail Script <jekyllmail@masukomi.org>")
+
+
+directory_keys = ['jekyll_repo', 'source_dir', 'site_url']
+yaml = YAML::load(File.open('_config.yml'))
+blogs = yaml['blogs']
+blogs.each do | blog |
+ # the blog hash contains
+ # jekyll_repo => absolute path to the root of the jekyll repo
+ # source_dir => absolute path to the directory containing _posts, _drafts, and images
+ # pop_server => domain name
+ # pop_user => username
+ # pop_password => plaintext password
+ # secret => the secret that must appear in the email subject
+ # markup => markup or textile
+ # site_url => the http://.... url to the root of the public web site
+ # commit_after_save => boolean
+ # git_branch => the name of the git branch to commit to
+ ## git_branch is Unused until we get Grit working correctly
+
+ directory_keys.each do | key |
+ blog[key].sub!(/\/$/, '') # remove any trailing slashes from directory paths
+ puts "#{key}: #{blog[key]}"
+ end
+ blog['images_dir'] ||= 'images' #relative to site_url
+ blog['posts_dir'] ||= '_posts' #relative to source_dir
-#Change me
-prefs = {
- :path_to_posts => `git config jekyllmail.postsDir`.chomp,
- :path_to_drafts => `git config jekyllmail.draftsDir`.chomp,
- :path_to_images => `git config jekyllmail.imagesDir`.chomp,
- :pop_server => `git config jekyllmail.popServer`.chomp,
- :pop_user => `git config jekyllmail.popUser`.chomp,
- :pop_password => `git config jekyllmail.popPassword`.chomp,
- :secret => `git config jekyllmail.secret`.chomp,
- # secret must appear in the subject line or the message will be deleted unread
- :markup => `git config jekyllmail.defaultMarkup`.chomp,
-}
-
-
-Mail.defaults do
- retriever_method :pop3, :address => prefs[:pop_server],
- :port => 995,
- :user_name => prefs[:pop_user],
- :password => prefs[:pop_password],
- :enable_ssl => true
-end
-
-emails = Mail.all
-if (emails.length == 0 )
- puts "No Emails found"
- exit 0
-else
- puts "#{emails.length} email(s) found"
-end
+ Mail.defaults do
+ retriever_method :pop3, :address => blog['pop_server'],
+ :port => 995,
+ :user_name => blog['pop_user'],
+ :password => blog['pop_password'],
+ :enable_ssl => true
+ end
+ emails = Mail.all
+ if (emails.length == 0 )
+ puts "No Emails found" if DEBUG
+ exit 0
+ else
+ puts "#{emails.length} email(s) found" if DEBUG
+ end
-emails.each do | mail |
- markup_extensions = {:html => 'html', :markdown => 'markdown', :md => 'markdown', :textile => 'textile', :txt => 'textile'}
- keyvals = {:tags => '', :markup => prefs[:markup], :slug => '', :published => true, :layout => 'post'}
- subject = mail.subject
- #If there is no working subject, bail
- next if subject.empty?
-
- (title, raw_data) = subject.split(/\|\|/) # two pipes separate subject from data
- title.gsub!(/^\s+|\s+$/, '')
- unless raw_data.nil?
- datums = raw_data.split('/')
- datums.each do |datum|
- next if datum.nil?
- (key, val) = datum.split(/:\s?/)
- key.gsub!(/\s+/, '')
- val.gsub!(/\s+$/, '')
- keyvals[key.to_sym] = val
- end
- end
-
-
- # if it doesn't contain the secret we can assume it to be spam
- next unless keyvals[:secret] == prefs[:secret]
-
- keyvals.delete(:secret) # we don't want that in the post's Frontmatter
- slug = title.gsub(/[^[:alnum:]]+/, '-').downcase.strip.gsub(/\A\-+|\-+\z/, '')
- time = Time.now
- name = "%02d-%02d-%02d-%s.%s" % [time.year, time.month, time.day, slug, markup_extensions[keyvals[:markup].to_sym]]
-
-
- #TODO figure out a better way to integrate hashtag
- # support or removal:
- # - Maybe they should be converted to tags?
- # - Maybe they should be killed?
- #Now remove any hash tags (like from Instagram)
- #title = title.gsub(/ \#\w+/, '').strip
-
- body = ''
-
- #Is this multipart?
- if mail.multipart?
- html_part = -1
- txt_part = -1
-
- #Figure out which part is html and which
- #is text
- mail.parts.each_with_index do |p,idx|
- if p.content_type.start_with?('text/html')
- html_part = idx
- elsif p.content_type.start_with?('text/plain')
- txt_part = idx
+ emails.each do | mail |
+ files_to_commit = []
+ markup_extensions = {:html => 'html', :markdown => 'markdown', :md => 'markdown', :textile => 'textile', :txt => 'textile'}
+ keyvals = {:tags => '', :markup => blog['markup'], :slug => '', :published => true, :layout => 'post'}
+ subject = mail.subject
+ puts "processing email with subject: #{subject}" if DEBUG
+
+ #If there is no working subject, bail
+ next if subject.empty?
+
+ # <subject> || key: value / key: value / key: value, value, value
+ (title, raw_data) = subject.split(/\|\|/) # two pipes separate subject from data
+ title.gsub!(/^\s+|\s+$/, '')
+ unless raw_data.nil?
+ datums = raw_data.split('/')
+ datums.each do |datum|
+ next if datum.nil?
+ (key, val) = datum.split(/:\s?/)
+ key.gsub!(/\s+/, '')
+ val.gsub!(/\s+$/, '')
+ keyvals[key.to_sym] = val
end
end
-
- mail.attachments.each do |attachment|
- if (attachment.content_type.start_with?('image/'))
- fn = attachment.filename
- images_dir = prefs[:path_to_images] + ("/%02d/%02d/%02d" % [time.year, time.month, time.day]) + '/'
- unless Dir.exists?(images_dir)
- FileUtils.mkdir_p(images_dir)
+
+
+ # if it doesn't contain the secret we can assume it to be spam
+ next unless keyvals[:secret] == blog['secret']
+
+ keyvals.delete(:secret) # we don't want that in the post's Frontmatter
+ slug = title.gsub(/[^[:alnum:]]+/, '-').downcase.strip.gsub(/\A\-+|\-+\z/, '')
+ time = Time.now
+ name = "%02d-%02d-%02d-%s.%s" % [time.year, time.month, time.day, slug, markup_extensions[keyvals[:markup].to_sym]]
+
+
+ #TODO figure out a better way to integrate hashtag
+ # support or removal:
+ # - Maybe they should be converted to tags?
+ # - Maybe they should be killed?
+ #Now remove any hash tags (like from Instagram)
+ #title = title.gsub(/ \#\w+/, '').strip
+
+ body = ''
+
+ images_needing_replacement = {} #maps filename to public url file will be served from
+ #Is this multipart?
+ if mail.multipart?
+ html_part = -1
+ txt_part = -1
+
+ #Figure out which part is html and which
+ #is text
+ mail.parts.each_with_index do |p,idx|
+ if p.content_type.start_with?('text/html')
+ html_part = idx
+ elsif p.content_type.start_with?('text/plain')
+ txt_part = idx
end
- begin
- File.open( images_dir + fn, "w+b", 0644 ) { |f| f.write attachment.body.decoded }
- rescue Exception => e
- puts "Unable to save data for #{fn} because #{e.message}"
+ end
+
+ mail.attachments.each do |attachment|
+ if (attachment.content_type.start_with?('image/'))
+ fn = attachment.filename
+ images_dir = blog['images_dir'] + ("/%02d/%02d/%02d" % [time.year, time.month, time.day])
+ absolute_images_dir = "#{blog['source_dir']}/#{images_dir}"
+ puts "absolute_images_dir: #{absolute_images_dir}"
+ images_needing_replacement[fn] = "#{blog['site_url']}/#{images_dir}/#{fn}"
+ puts "image url: #{images_needing_replacement[fn]}"
+ unless Dir.exists?(absolute_images_dir)
+ puts "creating dir #{absolute_images_dir}" if DEBUG
+ FileUtils.mkdir_p(absolute_images_dir)
+ end
+ begin
+ puts "saving image to #{blog['source_dir']}/#{images_dir}/#{fn}" if DEBUG
+ File.open( "#{blog['source_dir']}/#{images_dir}/#{fn}", "w+b", 0644 ) { |f| f.write attachment.body.decoded }
+ files_to_commit << "source/#{images_dir}/#{fn}"
+ rescue Exception => e
+ $stderr.puts "Unable to save data for #{fn} because #{e.message}"
+ end
end
end
+
+
+ #If the markup isn't html, try and use the
+ #text if it exists. Anything else, use the html
+ #version
+ if txt_part > -1 and keyvals[:markup] != 'html'
+ body = mail.parts[txt_part].body.decoded
+ elsif html_part > -1
+ body = mail.parts[html_part].body.decoded
+ end
+ else
+ #Just grab the body no matter what it is
+ body = mail.body.decoded
end
-
-
- #If the markup isn't html, try and use the
- #text if it exists. Anything else, use the html
- #version
- if txt_part > -1 and keyvals[:markup] != 'html'
- body = mail.parts[txt_part].body.decoded
- elsif html_part > -1
- body = mail.parts[html_part].body.decoded
- end
- else
- #Just grab the body no matter what it is
- body = mail.body.decoded
- end
- #If we have no body after all that, bail
- exit if body.strip.empty?
+ #If we have no body after all that, bail
+ exit if body.strip.empty?
- #If it's html, run it through nokogiri to make sure it's clean
- if keyvals[:markup] == 'html'
- #body.gsub!(/[“””“]/, '"')
- #body.gsub!(/[’‘’]/, "'")
- body = Nokogiri::HTML::DocumentFragment.parse(body.strip).to_html
- end
+ #If it's html, run it through nokogiri to make sure it's clean
+ if keyvals[:markup] == 'html'
+ #body.gsub!(/[“””“]/, '"')
+ #body.gsub!(/[’‘’]/, "'")
+ body = Nokogiri::HTML::DocumentFragment.parse(body.strip).to_html
+ end
+ if (images_needing_replacement.length() > 0)
+ #TODO break this out into a method for testability
+ images_needing_replacement.each do | filename, path |
+ if keyvals[:markup] == 'markdown'
+ body.gsub!(/(\(|\]:\s|<)#{Regexp.escape(filename)}/, "\\1#{path}")
+ elsif keyvals[:markup] == 'textile'
+ body.gsub!(/!#{Regexp.escape(filename)}(!|\()/, "!#{path}\\1")
+ elsif keyvals[:markup] == 'html'
+ body.gsub!(/(src=(?:'|")|href=(?:'|"))#{Regexp.escape(filename)}/i, "\\1#{path}")
+ # WARNING: won't address urls in css
+ # Is case insensitive so it won't differentiatee FOO.jpg from foo.jpg or FoO.jpg
+ # people shouldn't be using the same name for different files anyway. :P
+ end
+ end
+ end
- draft_filename = prefs[:path_to_drafts] + '/' + name
- post_filename = prefs[:path_to_posts] + '/' + name
-
- exit unless File.writable?(prefs[:path_to_posts])
-
- open(draft_filename, 'w') do |str|
- str << "---\n"
- str << "title: '#{title}'\n"
- str << "date: %02d-%02d-%02d %02d:%02d:%02d\n" % [time.year, time.month, time.day, time.hour, time.min, time.sec]
- keyvals.keys.sort.each do |key|
- if key != :tags and key != :slug
- str << "#{key}: #{keyvals[key]}\n"
- elsif key == :tags
- unless keyvals[:tags].empty?
- str << "tags: \n"
- keyvals[:tags].split(',').each do |string|
- str << "- " + string.strip + "\n"
+ post_filename = "#{blog['source_dir']}/#{blog['posts_dir']}/#{name}"
+
+ exit unless File.writable?("#{blog['source_dir']}/#{blog['posts_dir']}")
+ # First we want to try and successfully write everything to the filesystem
+ # We'll do this in the drafts directory
+ open(post_filename, 'w') do |str|
+ str << "---\n"
+ str << "title: '#{title}'\n"
+ str << "date: %02d-%02d-%02d %02d:%02d:%02d\n" % [time.year, time.month, time.day, time.hour, time.min, time.sec]
+ keyvals.keys.sort.each do |key|
+ if key != :tags and key != :slug
+ str << "#{key}: #{keyvals[key]}\n"
+ elsif key == :tags
+ unless keyvals[:tags].empty?
+ str << "tags: \n"
+ keyvals[:tags].split(',').each do |string|
+ str << "- " + string.strip + "\n"
+ end
end
end
end
+ str << "---\n"
+ str << body
end
- str << "---\n"
- str << body
- end
- # if this isn't a draft move it over to the posts directory
- unless keyvals[:published] == 'false'
- FileUtils.mv(draft_filename, post_filename)
+ files_to_commit << post_filename
+
+ if blog['commit_after_save'] and files_to_commit.size() > 0
+ # NOTES for devs
+# @repo = Repo.new(blog['jekyll_repo'])
+# index = @repo.index
+# index.add('foo/bar/baz.txt', 'hello!')
+# index.commit('first commit')
+ # possibly Dir.chdir('repo/test.git') { jekyll_repo.add('foo.txt') }
+
+ #repo = Grit::Repo.new(blog['jekyll_repo'])
+ #parents = [repo.commits.first]
+ #index = repo.index
+
+ Dir.chdir(blog['jekyll_repo']) #probably unnecessary
+ files_to_commit.each do |file|
+ relative_file_name = file.sub(/.*?source\//, 'source/')
+ puts "adding #{relative_file_name}" if DEBUG
+ #index.add(relative_file_name, open(file, "rb") {|io| io.read })
+ #repo_specific_file_name, binary_data
+ `git add #{relative_file_name}`
+ end
+ puts "committing" if DEBUG
+ #sha = index.commit("Adding post #{slug} via JekyllMail", parents, JEKYLLMAIL_USER, nil, blog['git_branch'])
+ #puts "sha = #{sha}" if DEBUG
+ `git commit -m "Adding post #{slug} via JekyllMail"`
+ end
+
+
end
+ Mail.delete_all() unless DEBUG
+ # when debugging it's much easier to just leave the emails there and re-use them
end
-
-Mail.delete_all()
View
9 run_jekyllmail.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# CHANGE ME TO MEET THE NEEDS OF YOUR SERVER CONFIGURATION
+
+[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
+GEM_PATH=$GEM_PATH:/home/my_username/.gems
+PATH=$PATH:/home/my_username/.gems/bin
+cd /home/my_username/jekyllmail_repo/
+bundle exec ruby jekyllmail.rb
Please sign in to comment.
Something went wrong with that request. Please try again.