Tweet your blog post title with Jekyll
- Add
gem 't'
to your Gemfile bundle install
bundle exec t authorize
and follow instructions to get API keys.- Permissions must be 'Read and Write'
- Once authenticated, the permissions are stored in
~/.trc
. We will need this file to tweet once the deployment successful, but as this file contains sensitive information, you want to secure it viatravis encrypt-file
like this:
Now let's see what happen in the rake task tweet_last_article
. Two parts :
1.Before Deployment, we check if we have an unpublished article and retrieve its title and url.
We go through the list of _posts
files and take the last one. Grab the title from the content if any or build the one from the filename. Then goes the URL also building the last name.
Note that the base URL could certainly be retrieved from somewhere else, but I didn't look more into it.
Don't forget to execute it before the deployment to Github:
2.After successful deployment, we tweet any message created before the deployment.
And so we will need to add the following to .travis.yml
:
That's it! if you think there's another simpler, more secure solution or any improvements, let me know on Twitter.