Hcard

eschnou edited this page Mar 3, 2011 · 1 revision

hCard is a simple, open, distributed format for representing people, companies, organizations, and places, using a 1:1 representation of vCard (RFC2426) properties and values in semantic HTML or XHTML. hCard is one of several open microformat standards suitable for embedding in HTML, XHTML, Atom, RSS, and arbitrary XML. Spec: http://microformats.org/wiki/hcard

lookup(url, callback)

Attempt to fetch a HCard at the given URL. If a HCard is present, it is parsed and returned to the callback as a Javascript associative array. The keys match the names of the HCard properties.

Example:

var ostatus = require('ostatus');
ostatus.hcard.lookup("http://identi.ca/eschnou/hcard", function(err, hcard) {
   console.log(hcard);
});

Will outpout:

{ photo:    'http://avatar.identi.ca/16106-96-20080722053859.png',
  nickname: 'eschnou',
  fn:       'Laurent',
  label:    'Liège, Belgium',
  url:      'http://eschnou.com',
  note: 'Coder, not blogger. Technology enthusiast. Exploring the future of the web & mobility.' 
 }

render(hcard, callback)

Given an associative array whose keys are matching HCard parameters, this function will render a proper HCard. In practice, it is simply rendering the template hcard.html.mu using the provided content.

Examples:

var ostatus = require('ostatus');
var hcard = { avatar:   'http://avatar.identi.ca/16106-96-20080722053859.png',
              nickname: 'eschnou',
              fn:       'Laurent',
              location: 'Liège, Belgium',
              note: 'Coder, not blogger. Technology enthusiast. Exploring the future of the web & mobility.' 
 }
ostatus.hcard.render(hcard, function(err, html) {
   console.log(html);
});

Will output:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
  	<head> 
   	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>HCard - eschnou</title> 
</head> 
<body id="hcard"> 
	<div id="wrapper"> 
		<div id="i" class="entity_profile vcard author"> 
	       <h2>User profile</h2> 
	       <dl class="entity_depiction"> 
	        <dt>Photo</dt> 
	        <dd> 
	        	<img src="http://avatar.identi.ca/16106-96-20080722053859.png"
                                 Class="photo avatar" width="96" height="96" alt="eschnou"/> 
			</dd> 
		   </dl> 
	       <dl class="entity_nickname"> 
	        <dt>Nickname</dt> 
	        <dd> 
	         <a href="" rel="me" class="nickname url uid">eschnou</a> 
		</dd> 
	       </dl> 
	       <dl class="entity_fn"> 
	        <dt>Full name</dt> 
	        <dd> 
	         <span class="fn">Laurent</span> 
	        </dd> 
	       </dl> 
	       <dl class="entity_location"> 
	        <dt>Location</dt> 
	        <dd class="label">Liège, Belgium</dd> 
	       </dl> 
	       <dl class="entity_note"> 
	        <dt>Note</dt> 
	        <dd class="note">Software hacker, building socialJS.</dd> 
		   </dl> 
	  	</div> 
	</div> 
</body>