Skip to content

Instantly share code, notes, and snippets.

@gabrielhpugliese
Created October 29, 2012 12:27
Show Gist options
  • Save gabrielhpugliese/3973258 to your computer and use it in GitHub Desktop.
Save gabrielhpugliese/3973258 to your computer and use it in GitHub Desktop.
Auto Graph App
jQuery(document).ready(function(){
var $head = jQuery('head');
var img_src = jQuery('img').attr('src');
if (img_src.indexOf('http://') == -1 && img_src.indexOf('https://') == -1)
img_src = window.location.protocol + '//' + window.location.hostname + jQuery('img').attr('src');
var ogp_tags = {'title': $head.find('title').text().trim(),
'url': window.location.href,
'description': '[%description%]' ? '[%description%]' : jQuery('.lead').html(),
'image': '[%image%]' ? '[%image%]' : img_src,
'type': '[%type%]' ? '[%type%]' : 'website'};
for (i in ogp_tags){
if(ogp_tags.hasOwnProperty(i) && ogp_tags[i] != null)
var tag = '<meta property="og:'+ i +'" content="'+ ogp_tags[i] +'" />';
$head.append(tag);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment