Add basic schema.org microdata to record details
authorDan Scott <dan@coffeecode.net>
Mon, 19 Mar 2012 03:13:12 +0000 (23:13 -0400)
committerDan Scott <dscott@laurentian.ca>
Fri, 30 Mar 2012 15:50:09 +0000 (11:50 -0400)
It's shocking how little we can easily and reliably extract from MARC to
map to schema.org's metadata structure. However, what I could get shows
up relatively nicely on Google's Rich Snippets testing tool.

Signed-off-by: Dan Scott <dan@coffeecode.net>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/opac/parts/record/authors.tt2
Open-ILS/src/templates/opac/parts/record/subjects.tt2
Open-ILS/src/templates/opac/parts/record/summary.tt2

index fc06cac..4a0419c 100644 (file)
@@ -28,6 +28,7 @@ BLOCK build_author_links;
     FOR node IN ctx.marc_xml.findnodes(xpath);
         term = '';
         qterm = '';
+        iprop = '';
         FOR subfield IN node.childNodes;
             NEXT UNLESS subfield.nodeName == "subfield";
             code = subfield.getAttribute('code');
@@ -39,7 +40,14 @@ BLOCK build_author_links;
         END;
         url = mkurl(ctx.opac_root _ '/results', {query => qterm, qtype => 'author'}, ['page', 'expand']);
         author_type = label | html;
-        '<a href="' _ url _ '">' _ term _ '</a> (' _ author_type _ '). ';
+        
+        # schema.org changes
+        IF type == 'author';
+            iprop = ' itemprop="accountablePerson"';
+        ELSIF type == 'added';
+            iprop = ' itemprop="contributor"';
+        END;
+        '<a href="' _ url _ '"' _ iprop _ '>' _ term.replace('^\s+', '') _ '</a> (' _ author_type _ '). ';
     END;
 END;
 %]
@@ -47,7 +55,9 @@ END;
 <div class='rdetail_authors_div'>
 [%- FOREACH author IN authors;
     NEXT UNLESS author.xpath; 
-    links = PROCESS build_author_links(xpath=author.xpath, label=author.label);
+    links = PROCESS build_author_links(
+        xpath=author.xpath, label=author.label, type=author.type
+    );
     IF links.match('\S') %]
     <span class='rdetail-author-div'>[% links %]</span>
     [%- END %]
index 59e26a5..52d9ac8 100644 (file)
@@ -57,7 +57,7 @@
             <tbody>
                 <tr>
                     <td class='rdetail_subject_type'>[% subj.label %]</td>
-                    <td class='rdetail_subject_value'>[% content %]</td>
+                    <td class='rdetail_subject_value' itemprop='keywords'>[% content %]</td>
                 </tr>
             </tbody>
         </table>
index 7ca150e..c652d88 100644 (file)
@@ -51,7 +51,7 @@
             <img alt="[% attrs.format_label %]" title="[% attrs.format_label | html %]" src="[% attrs.format_icon %]" />
         </div>
         [%- END %]
-        <h1 id='rdetail_title'>[% attrs.title_extended | html %]</h1>
+        <h1 id='rdetail_title' itemprop="name">[% attrs.title_extended | html %]</h1>
         [%- INCLUDE "opac/parts/record/authors.tt2" %]
     </div>
 </div>
@@ -115,7 +115,7 @@ IF num_uris > 0;
     [%- IF attrs.isbns.0; FOR isbn IN attrs.isbns %]
     <li class='rdetail_isbns'>
         <strong class='rdetail_label'>[% l('ISBN:'); %]</strong>
-        <span class='rdetail_value'>[% isbn | html  %]</span>
+        <span class='rdetail_value' itemprop='isbn'>[% isbn | html  %]</span>
     </li>
         [%- END %]
     [%- END %]
@@ -141,7 +141,12 @@ IF num_uris > 0;
     [%- IF attrs.publisher %]
     <li id='rdetail_publisher'>
         <strong class='rdetail_label'>[% l("Publisher:") %]</strong>
-        <span class='rdetail_value'>[% attrs.publisher | html %] [% IF attrs.pubdate; attrs.pubdate | html; END %]</span>
+        <span class='rdetail_value' itemprop="publisher">[%
+            attrs.publisher | html;
+        %]</span>[% IF attrs.pubdate; %] <span itemprop="datePublished">[%
+            attrs.pubdate | html;
+            END;
+        %]</span>
     </li>
     [%- END %]
 </ul>