Last Updated: February 25, 2016
·
1.155K
· jeremymorgan

Creating Generic OctoPress Headers

I saw another question on the Octopress GitHub list about <a href="https://cqauthors.intel.com/cf#/content/www/th/th/education/k12/assessing-projects/assessment-plans/elementary.html?cq_ck=1351553608960">importing existing markdown files</a> and it turned out he needed some header info added to the pages, and those are usually added by Octopress. He had a program that converted all his .html files to markdown, and had to add them by hand.

I wrote this quick Ruby script to do it, and now I'm sharing it everywhere I can in hopes that it will help others with this same problem:

#!/usr/bin/ruby -w
# Header adder
# adds some generic headers to your Markdown files for Octopress
# use/branch/distribute as you see fit

Dir["*.markdown"].each { |ourfile|

content = File.read(ourfile)
newcontent = "---
layout: post
title: \"TITLE\"
date: 2012-10-23 01:38
comments: true
author: Your Name
categories:
- Your Category
permalink: \/permalink
---\n\n" + content
 File.open(ourfile, 'r+') { |file| file.write(newcontent) }
}

I hope this helps others! Create this file and run it in your src folder and it will add a generic header to each markdown file, you will still have to fill in the information for each page however.

You can also fork this from github: <a href="https://github.com/JeremyMorgan/Octopress-Header-Adder">https://github.com/JeremyMorgan/Octopress-Header-Adder</a>