Skip to content

Instantly share code, notes, and snippets.

@clauswitt
Forked from minhajuddin/new.rb
Created January 7, 2012 09:45
Show Gist options
  • Select an option

  • Save clauswitt/1574298 to your computer and use it in GitHub Desktop.

Select an option

Save clauswitt/1574298 to your computer and use it in GitHub Desktop.

Revisions

  1. clauswitt revised this gist Jan 7, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion new.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/usr/bin/env ruby

    # Script to create a jekyll blog post using a template. It takes one input parameter
    # Script to create a jekyll blog post using a template and open it in textmate. It takes one input parameter
    # which is the title of the blog post
    # e.g. command:
    # $ ./new.rb "helper script to create new posts using jekyll"
  2. clauswitt revised this gist Jan 7, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion new.rb
    Original file line number Diff line number Diff line change
    @@ -29,4 +29,4 @@
    new_post_file.puts new_post
    new_post_file.close

    puts "created => #{filepath}"
    puts `mate #{filepath}`
  3. clauswitt revised this gist Jan 7, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion new.rb
    Original file line number Diff line number Diff line change
    @@ -6,9 +6,11 @@
    # $ ./new.rb "helper script to create new posts using jekyll"
    #
    # Author:Khaja Minhajuddin (http://minhajuddin.com)
    # Minor tweaks by Claus Witt (http://www.clauswitt.com)


    # Some constants
    TEMPLATE = "template.markdown"
    TEMPLATE = "_template.markdown"
    TARGET_DIR = "_posts"

    # Get the title which was passed as an argument
  4. minhajuddin created this gist Sep 30, 2010.
    30 changes: 30 additions & 0 deletions new.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/usr/bin/env ruby

    # Script to create a jekyll blog post using a template. It takes one input parameter
    # which is the title of the blog post
    # e.g. command:
    # $ ./new.rb "helper script to create new posts using jekyll"
    #
    # Author:Khaja Minhajuddin (http://minhajuddin.com)

    # Some constants
    TEMPLATE = "template.markdown"
    TARGET_DIR = "_posts"

    # Get the title which was passed as an argument
    title = ARGV[0]
    # Get the filename
    filename = title.gsub(' ','-')
    filename = "#{ Time.now.strftime('%Y-%m-%d') }-#{filename}.markdown"
    filepath = File.join(TARGET_DIR, filename)

    # Create a copy of the template with the title replaced
    new_post = File.read(TEMPLATE)
    new_post.gsub!('TITLE', title);

    # Write out the file to the target directory
    new_post_file = File.open(filepath, 'w')
    new_post_file.puts new_post
    new_post_file.close

    puts "created => #{filepath}"