TPAC: Fix schema.org name / dates for authors
[working/Evergreen.git] / Open-ILS / src / templates / opac / parts / record / authors.tt2
index 43a3060..94a887b 100644 (file)
@@ -28,7 +28,10 @@ BLOCK build_author_links;
         qterm = '';
         iprop = '';
         tlabel = '';
+        birthdate = '';
+        deathdate = '';
         graphics = [];
+        tag = node.getAttribute('tag');
         FOR subfield IN node.childNodes;
             NEXT UNLESS subfield.nodeName == "subfield";
             code = subfield.getAttribute('code');
@@ -37,17 +40,27 @@ BLOCK build_author_links;
                 tlabel = relators.$relcode || label;
             END;
             IF code == '6';
+               target_field = tag;
                linked_fields = [subfield.textContent()];
-               target_field = node.getAttribute('tag');
                get_linked_880s;
             END;
             NEXT UNLESS code.match('[a-z]');
             sf = subfield.textContent | html;
-            term = term _ ' ' _ sf;
             IF code.match('[acdq]');
                 sf_raw = subfield.textContent.replace('[#"^$\+\-,\.:;&|\[\]()]', ' ');
                 qterm = qterm _ ' ' _ sf_raw;
             END;
+            # Only Persons have birth/death dates in schema.org
+            IF code.match('d') && tag.substr(1,2) == '00';
+                IF subfield.textContent.match('^\s*\d{4}');
+                    birthdate = subfield.textContent.replace('^\s*(\d{4}).*$', '$1');
+                END;
+                IF subfield.textContent.match('-\d{4}\s*$');
+                    deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4})\s*$', '$1');
+                END;
+            ELSE;
+                term = term _ ' ' _ sf;
+            END;
         END;
         url = mkurl(ctx.opac_root _ '/results', {query => qterm, qtype => 'author'}, ['page', 'expand']);
         author_type = (tlabel || label) | html;
@@ -57,7 +70,7 @@ BLOCK build_author_links;
             IF args.schema.itemtype && args.schema.itemtype.match('MusicAlbum');
                 iprop = ' itemtype="http://schema.org/MusicGroup" itemscope itemprop="byArtist"';
             ELSE;
-                iprop = ' itemprop="accountablePerson"';
+                iprop = ' itemtype="http://schema.org/Person" itemscope itemprop="author"';
             END;
         ELSIF type == 'added';
             iprop = ' itemprop="contributor"';
@@ -66,6 +79,12 @@ BLOCK build_author_links;
         IF iprop; '<span itemprop="name">'; END;
         term.replace('^\s+', '');
         IF iprop; '</span>'; END;
+        IF birthdate;
+            ' <span itemprop="birthDate">' _ birthdate _ '</span>-';
+        END;
+        IF deathdate;
+            '<span itemprop="deathDate">' _ deathdate _ '</span>';
+        END;
         '</a>';
         FOREACH link880 IN graphics;
             diratt = '';