Skip to content

Instantly share code, notes, and snippets.

@jrk
Forked from al3x/newpost.rb
Created May 5, 2009 06:48
Show Gist options
  • Select an option

  • Save jrk/106869 to your computer and use it in GitHub Desktop.

Select an option

Save jrk/106869 to your computer and use it in GitHub Desktop.

Revisions

  1. jrk revised this gist May 5, 2009. 1 changed file with 8 additions and 5 deletions.
    13 changes: 8 additions & 5 deletions newpost.rb
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,29 @@
    #!/usr/bin/env ruby

    require Dir

    unless ARGV[0]
    puts 'Usage: newpost "the post title"'
    exit(-1)
    end

    blog_root = "/Users/jrk/proj/blog"
    date_prefix = Time.now.strftime("%Y-%m-%d")
    postname = ARGV[0].strip.downcase.gsub(/ /, '-')
    post = "/Users/al3x/src/al3x.github.com/_posts/#{date_prefix}-#{postname}.textile"
    post = "#{blog_root}/_posts/#{date_prefix}-#{postname}.md"

    header = <<-END
    ---
    layout: post
    title: "#{ARGV[0]}"
    ---
    h1. {{ page.title }}
    END

    Dir.chdir(blog_root)

    File.open(post, 'w') do |f|
    f << header
    end

    system("mate", "-a", post)
    system("mate", "-w", post)
    system("git", "add", post)
  2. @al3x al3x revised this gist Apr 23, 2009. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions newpost.rb
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,13 @@
    #!/usr/bin/env ruby

    unless ARGV[0]
    puts "Usage: newpost post-title"
    puts 'Usage: newpost "the post title"'
    exit(-1)
    end

    date_prefix = Time.now.strftime("%Y-%m-%d")
    postname = ARGV[0].strip.downcase.gsub(/ /, '-')
    post = "/Users/al3x/src/al3x.github.com/_posts/#{date_prefix}-#{postname}.textile"

    header = <<-END
    ---
    @@ -18,9 +19,8 @@
    END

    f = File.open("/Users/al3x/src/al3x.github.com/_posts/#{date_prefix}-#{postname}.textile", 'w+')
    f << header
    f.close
    File.open(post, 'w') do |f|
    f << header
    end

    system("#{ENV['VISUAL']} #{f.path}")
    exit(0)
    system("mate", "-a", post)
  3. @al3x al3x created this gist Apr 22, 2009.
    26 changes: 26 additions & 0 deletions newpost.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/usr/bin/env ruby

    unless ARGV[0]
    puts "Usage: newpost post-title"
    exit(-1)
    end

    date_prefix = Time.now.strftime("%Y-%m-%d")
    postname = ARGV[0].strip.downcase.gsub(/ /, '-')

    header = <<-END
    ---
    layout: post
    title: "#{ARGV[0]}"
    ---
    h1. {{ page.title }}
    END

    f = File.open("/Users/al3x/src/al3x.github.com/_posts/#{date_prefix}-#{postname}.textile", 'w+')
    f << header
    f.close

    system("#{ENV['VISUAL']} #{f.path}")
    exit(0)