Skip to content

Instantly share code, notes, and snippets.

@ryanatwork
Created January 10, 2014 23:29
Show Gist options
  • Save ryanatwork/8364724 to your computer and use it in GitHub Desktop.
Save ryanatwork/8364724 to your computer and use it in GitHub Desktop.
Parsely Meta Tag Ruby Example
require 'date'
title = "Zipf's Law of the Internet: Explaining Online Behavior"
link = "http://blog.parsely.com/post/57821746552"
image_url = "http://blog.parsely.com/inline_mra670hTvL1qz4rgp.png"
section = "Programming"
author = "Alan Alexander Milne"
pub_date = Time.new(2012,1,1,11,34,2, '-05:00')
tags = ["statistics", "zipf", "internet", "behavior"]
def get_clean_parsely_page_value(val)
return val.gsub(/\n/, "").gsub(/'/, '\u0027')
end
parsely_page = {}
parsely_page[:title] = get_clean_parsely_page_value(title)
parsely_page[:link] = link
parsely_page[:image_url] = image_url
parsely_page[:type] = "post"
parsely_page[:post_id] = "57821746552"
parsely_page[:pub_date] = pub_date.utc.strftime("%FT%TZ")
parsely_page[:section] = get_clean_parsely_page_value(section)
parsely_page[:author] = get_clean_parsely_page_value(author)
parsely_page[:tags] = tags
output = "<meta name='parsely-page' content='#{JSON.generate(parsely_page)}' />"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment