Scott's Recipes Logo

Creating Blog Posts Easily in Bridgetown

Last Updated On: 2025-09-01 04:31:52 -0400

Bridgetown straddles the line between a static site generator and a blogging tool. As such it lacks support for something like the old jekyll-compose plugin which used to make it drop dead easy to create a blog post by taking a title and generating a date stamped and properly named markdown file.

Happily there is an easy work around for this – you can add a Rake task to the Bridgetown Rakefile that does all this for you. The source code is below and all you need to do is copy it into your Rakefile.

namespace :post do
  # create a new post like jekyll post or jekyll draft 
  # Example filename: 2022-08-11-equity-allocation-for-advisors-in-early-stage-startups.md  
  # Usage:
  # bridgetown post:new POST="Equity Allocation For Advisors in Early Stage Startups" 
  # -or-
  # bridgetown post:new POST="Equity Allocation For Advisors in Early Stage Startups" DRAFT=1
  task :new do #, [:title] do |task, args|
    title = ENV['POST']
    puts "title = #{title}"
    title_for_filename = title.gsub(/ +/, ' ').downcase.gsub(/ /,'-')
    date_for_filename = "#{Date.today.year}-#{format('%03d', Date.today.month)}-#{format('%03d', Date.today.day)}"
    extension = ".md"
    filename = "#{date_for_filename}-#{title_for_filename}#{extension}"
    output_dest = File.join(Dir.pwd, 'src/_posts', filename)
    output_lines = []
    output_lines << "---"
    output_lines << "layout: post"
    output_lines << "title: #{title}"
    output_lines << "category: "
    output_lines << "tags: ['']"
    if ENV['DRAFT'] == '1'
      output_lines << "published: false"
    end
    output_lines << "---"
    output_lines << ""
    output_lines << ""
    
    File.open(output_dest, "w+") do |f| 
      f.puts(output_lines) 
    end 
    
    # todo 
    # * colorize the output like jekyll
    
    starting_offset = output_dest.index("src/_posts")
    
    puts "\n\nNew post created at: #{output_dest[starting_offset, output_dest.length]}"
  end
end

And then run it with a command like:

bin/bridgetown post:new POST="Creating Blog Posts Easily in Bridgetown"

And you should see output like:

title = Creating Blog Posts Easily in Bridgetown


New post created at: src/_posts/2023-02-14-creating-blog-posts-easily-in-bridgetown.md

As you can see the Rake task took the string name you gave it and created the right markdown file that you can easily edit and then publish.