Skip to content

Instantly share code, notes, and snippets.

@seerocode
Forked from mlafeldt/Rakefile
Created April 20, 2018 16:06
Show Gist options
  • Select an option

  • Save seerocode/77a52e1b6d9698da17ca0ce8f1b5e16c to your computer and use it in GitHub Desktop.

Select an option

Save seerocode/77a52e1b6d9698da17ca0ce8f1b5e16c to your computer and use it in GitHub Desktop.

Revisions

  1. @mlafeldt mlafeldt revised this gist Oct 9, 2015. 1 changed file with 13 additions and 3 deletions.
    16 changes: 13 additions & 3 deletions Rakefile
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,14 @@ BUILD_DIR = '_site'
    DEPLOY_DIR = '_deploy'
    DEPLOY_BRANCH = 'master'

    def git(*args)
    sh 'git', *args
    end

    def open_in_editor(filename)
    sh "open", "-a", "/Applications/Byword.app", filename
    end

    desc "Build the site"
    task :build do
    sh "jekyll build"
    @@ -30,6 +38,8 @@ task :new_draft, :title do |t, args|
    f << "\n"
    f << "Add awesome content here.\n"
    end

    open_in_editor(filename)
    end

    desc 'Create a new post'
    @@ -48,6 +58,8 @@ task :new_post, :title do |t, args|
    f << "\n"
    f << "Add awesome post content here.\n"
    end

    open_in_editor(filename)
    end

    desc 'Create a new page'
    @@ -65,10 +77,8 @@ task :new_page, :title do |t, args|
    f << "\n"
    f << "Add awesome page content here.\n"
    end
    end

    def git(*args)
    sh 'git', *args
    open_in_editor(filename)
    end

    desc 'Deploy the site via Git'
  2. @mlafeldt mlafeldt created this gist Oct 7, 2015.
    111 changes: 111 additions & 0 deletions Rakefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,111 @@
    require 'stringex'

    POSTS_DIR = '_posts'
    BUILD_DIR = '_site'
    DEPLOY_DIR = '_deploy'
    DEPLOY_BRANCH = 'master'

    desc "Build the site"
    task :build do
    sh "jekyll build"
    end

    desc "Start web server to preview site"
    task :preview do
    sh "jekyll serve --drafts --watch"
    end

    desc 'Create a new draft'
    task :new_draft, :title do |t, args|
    title = args[:title] || 'New Draft'
    filename = File.join('_drafts', "#{title.to_url}.md")

    puts "==> Creating new draft: #{filename}"
    open(filename, 'w') do |f|
    f << "---\n"
    f << "layout: post\n"
    f << "title: \"#{title.to_html(true)}\"\n"
    f << "tags:\n"
    f << "---\n"
    f << "\n"
    f << "Add awesome content here.\n"
    end
    end

    desc 'Create a new post'
    task :new_post, :title do |t, args|
    title = args[:title] || 'New Post'
    timestamp = Time.now.strftime('%Y-%m-%d')
    filename = File.join(POSTS_DIR, "#{timestamp}-#{title.to_url}.md")

    puts "==> Creating new post: #{filename}"
    open(filename, 'w') do |f|
    f << "---\n"
    f << "layout: post\n"
    f << "title: \"#{title.to_html(true)}\"\n"
    f << "tags:\n"
    f << "---\n"
    f << "\n"
    f << "Add awesome post content here.\n"
    end
    end

    desc 'Create a new page'
    task :new_page, :title do |t, args|
    title = args[:title] || 'New Page'
    filename = File.join(title.to_url, 'index.md')

    puts "==> Creating new page: #{filename}"
    mkdir_p title.to_url
    open(filename, 'w') do |f|
    f << "---\n"
    f << "layout: page\n"
    f << "title: \"#{title.to_html(true)}\"\n"
    f << "---\n"
    f << "\n"
    f << "Add awesome page content here.\n"
    end
    end

    def git(*args)
    sh 'git', *args
    end

    desc 'Deploy the site via Git'
    task :deploy => :build do
    repo_url = `git config jekyll.deployurl`.chomp
    if repo_url.empty?
    abort 'error: set git repo url via `git config jekyll.deployurl` first'
    end

    if File.directory?(DEPLOY_DIR)
    rm_rf Dir["#{DEPLOY_DIR}/*"]
    else
    mkdir_p DEPLOY_DIR
    end

    if File.directory?(File.join(DEPLOY_DIR, '.git'))
    puts "==> Updating Git repository in #{DEPLOY_DIR} ..."
    cd DEPLOY_DIR do
    git 'fetch', '--prune'
    git 'reset', '--hard', "origin/#{DEPLOY_BRANCH}"
    end
    else
    puts "==> Cloning Git repository into #{DEPLOY_DIR} ..."
    git 'clone', '--branch', DEPLOY_BRANCH, repo_url, DEPLOY_DIR
    end

    puts "==> Copying files from #{BUILD_DIR} to #{DEPLOY_DIR} ..."
    cp_r Dir["#{BUILD_DIR}/*"], DEPLOY_DIR

    cd DEPLOY_DIR do
    puts '==> Pushing changes to remote Git repository...'
    git 'add', '--all'
    git 'commit', '--message', "Site updated at #{Time.now}"
    git 'push', 'origin', DEPLOY_BRANCH
    end

    puts '==> Site successfully deployed.'
    end

    task :default => :preview