Skip to content

Commit

Permalink
Updated SocialMetadata.hx to be smarter depending on the contents of …
Browse files Browse the repository at this point in the history
…the html file, to do with issue skial/haxe.io#24
  • Loading branch information
skial committed May 7, 2014
1 parent b606066 commit 5bcadb7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions all.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
-lib beanhx
-lib tjson
-lib selecthxml
-lib imagemagick
-debug
#-dce no
-cp src
Expand Down
29 changes: 27 additions & 2 deletions src/uhx/tuli/plugins/SocialMetadata.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uhx.tuli.plugins;

import haxe.imagemagick.Imagick;
import sys.io.File;
import uhx.sys.Tuli;

Expand Down Expand Up @@ -60,8 +61,6 @@ class SocialMetadata {
}
}

var url = dom.find('meta[property="og:url"]');

for (title in titles) {
title.setAttr('content', dom.find('title').text());
}
Expand All @@ -75,6 +74,32 @@ class SocialMetadata {
}
}

var img = 'img/skial.jpg';
var alt = dom.find('img[alt*="social"]');
var cardType = 'summary';

var images = [];
for (id in ['property', 'name']) {
for (meta in dom.find('meta[$id*="image"]')) {
if (meta.attr('content') == '') images.push( meta );
}
}

if (alt.length > 0) {
img = alt.first().attr('src');
var data = new Imagick('${Tuli.config.input}/$img'.normalize());
if (data.width >= 280 && data.height >= 150) {
dom.find('meta[name="twitter:image"]').setAttr('name', 'twitter:image:src');
cardType = 'summary_large_image';
}
}

dom.find('meta[name="twitter:card"]').setAttr('content', cardType);

for (image in images) image.setAttr('content', 'http://haxe.io/$img'.normalize());

var url = dom.find('meta[property="og:url"]');

if (url.length > 0) {
var path = 'http://haxe.io/$file'.normalize();
if (path.endsWith('index.html')) path = path.directory().addTrailingSlash();
Expand Down

0 comments on commit 5bcadb7

Please sign in to comment.