Skip to content

Instantly share code, notes, and snippets.

@jgarber623
Last active August 29, 2015 14:10
Show Gist options
  • Save jgarber623/70eea394e58ed320cf1a to your computer and use it in GitHub Desktop.
Save jgarber623/70eea394e58ed320cf1a to your computer and use it in GitHub Desktop.
Useful scripts for converting and preparing data for FrancisCMS.

Detailed instructions on how to use these scripts coming soon!

filepaths = Dir.glob('/path/to/posts/*.md')
filepaths.each do |filepath|
yaml = YAML.load_file(filepath)
post = FrancisCms::Post.new({
body: IO.read(filepath).split("\n---\n\n")[1..-1].join("\n---\n\n"),
published_at: yaml['date'],
slug: /\d{4}-\d{2}-\d{2}-(.+?).md/.match(filepath)[1],
title: yaml['title']
})
post.excerpt = yaml['excerpt'] unless yaml['excerpt'].nil?
post.tag_list = yaml['tags'].join(', ') unless yaml['tags'].nil?
unless yaml['copies'].nil?
yaml['copies'].each do |copy|
post.syndications.new({ name: copy['title'], url: copy['url'] })
end
end
post.save!
sleep(1)
end
webmentions = JSON.load(File.open('/path/to/webmentions.json', 'r'))
webmentions.each do |webmention|
FrancisCms::Webmention.new(
source: webmention['source'],
target: webmention['target'],
created_at: webmention['created_at']
).save!
sleep(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment