From 5440193f69886d0aa485529fd3c8d1d2a58d9da2 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Sun, 7 Apr 2013 19:54:42 -0400 Subject: [PATCH] TPAC: Make RDFa Lite current with schema.org state Break out Organizations, Persons, and MusicGroups like we did with schema.org. Signed-off-by: Dan Scott --- .../templates_rdfa/opac/parts/record/authors.tt2 | 57 ++++++++++++++++++++-- .../src/templates_rdfa/opac/parts/record/body.tt2 | 2 +- .../templates_rdfa/opac/parts/record/contents.tt2 | 11 +++++ .../templates_rdfa/opac/parts/record/subjects.tt2 | 11 +++++ .../templates_rdfa/opac/parts/record/summary.tt2 | 32 ++++++++++++ 5 files changed, 108 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/templates_rdfa/opac/parts/record/authors.tt2 b/Open-ILS/src/templates_rdfa/opac/parts/record/authors.tt2 index 5969588fca..e8020ffead 100644 --- a/Open-ILS/src/templates_rdfa/opac/parts/record/authors.tt2 +++ b/Open-ILS/src/templates_rdfa/opac/parts/record/authors.tt2 @@ -28,6 +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'); @@ -35,24 +39,69 @@ BLOCK build_author_links; relcode = subfield.textContent.substr(0,3); tlabel = relators.$relcode || label; END; + IF code == '6'; + target_field = tag; + linked_fields = [subfield.textContent()]; + 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; # schema.org changes IF type == 'author'; - iprop = ' property="accountablePerson"'; + IF args.schema.itemtype && args.schema.itemtype.match('MusicAlbum'); + iprop = ' typeof="http://schema.org/MusicGroup" property="byArtist"'; + ELSIF tag.substr(1,2) == '00'; + iprop = ' typeof="http://schema.org/Person" property="author"'; + ELSE; + iprop = ' typeof="http://schema.org/Organization" property="author"'; + END; ELSIF type == 'added'; - iprop = ' property="contributor"'; + IF tag.substr(1,2) == '00'; + iprop = ' typeof="http://schema.org/Person" property="contributor"'; + ELSE; + iprop = ' typeof="http://schema.org/Organization" property="contributor"'; + END; + END; + ''; + IF iprop; ''; END; + term.replace('^\s+', ''); + IF iprop; ''; END; + IF birthdate; + ' ' _ birthdate _ '-'; + END; + IF deathdate; + '' _ deathdate _ ''; + END; + ''; + FOREACH link880 IN graphics; + diratt = ''; + IF link880.dir; + diratt = ' dir="' _ link880.dir _ '"'; + END; + ' '; + link880.value | html; + ''; END; - '' _ term.replace('^\s+', '') _ ' (' _ author_type _ '). '; + ' (' _ author_type _ '). '; END; END; %] diff --git a/Open-ILS/src/templates_rdfa/opac/parts/record/body.tt2 b/Open-ILS/src/templates_rdfa/opac/parts/record/body.tt2 index 5bf95a418b..352c366b23 100644 --- a/Open-ILS/src/templates_rdfa/opac/parts/record/body.tt2 +++ b/Open-ILS/src/templates_rdfa/opac/parts/record/body.tt2 @@ -1,7 +1,7 @@ [%- attrs = {marc_xml => ctx.marc_xml}; PROCESS "opac/parts/misc_util.tt2"; PROCESS get_marc_attrs args=attrs; - stop_parms = ['expand','cnoffset']; + stop_parms = ['expand','cnoffset','copy_offset','copy_limit']; ctx.record_attrs = attrs; # capture for JS %]
diff --git a/Open-ILS/src/templates_rdfa/opac/parts/record/contents.tt2 b/Open-ILS/src/templates_rdfa/opac/parts/record/contents.tt2 index ff96d7391d..29fc33b4cd 100644 --- a/Open-ILS/src/templates_rdfa/opac/parts/record/contents.tt2 +++ b/Open-ILS/src/templates_rdfa/opac/parts/record/contents.tt2 @@ -157,15 +157,26 @@ BLOCK render_contents; xpath = xpath || '//*[starts-with(@tag,"5")]'; FOR node IN ctx.marc_xml.findnodes(xpath); all_content = []; + graphics = []; FOR subfield IN node.childNodes; NEXT UNLESS subfield.nodeName == "subfield"; code = subfield.getAttribute('code'); + IF code == '6'; + linked_fields = [subfield.textContent()]; + target_field = node.getAttribute('tag'); + get_linked_880s; + END; NEXT UNLESS code.match('[a-z]'); all_content.push(subfield.textContent); END; total_contents = all_content.join(" ").replace('\s+$', ''); %] [% total_contents; IF total_contents.size; "
"; END; + FOREACH link880 IN graphics; + '
'; + link880.value | html; + '
'; + END; END; END %] diff --git a/Open-ILS/src/templates_rdfa/opac/parts/record/subjects.tt2 b/Open-ILS/src/templates_rdfa/opac/parts/record/subjects.tt2 index f070c645b0..5460f5c095 100644 --- a/Open-ILS/src/templates_rdfa/opac/parts/record/subjects.tt2 +++ b/Open-ILS/src/templates_rdfa/opac/parts/record/subjects.tt2 @@ -31,9 +31,15 @@ xpath = xpath || '//*[starts-with(@tag,"6")]'; FOR node IN ctx.marc_xml.findnodes(xpath); all_terms = []; + graphics = []; FOR subfield IN node.childNodes; NEXT UNLESS subfield.nodeName == "subfield"; code = subfield.getAttribute('code'); + IF code == '6'; + linked_fields = [subfield.textContent()]; + target_field = node.getAttribute('tag'); + get_linked_880s; + END; NEXT UNLESS code.match('[a-z]'); IF code.match('[vxyz]'); " > "; END; # at this point, we actually have a partial term to use. @@ -44,6 +50,11 @@ [% single_term %] [%- END; IF all_terms.size; "
"; END; + FOREACH link880 IN graphics; + '
'; + link880.value | html; + '
'; + END; END; END %] diff --git a/Open-ILS/src/templates_rdfa/opac/parts/record/summary.tt2 b/Open-ILS/src/templates_rdfa/opac/parts/record/summary.tt2 index 0a0901ddeb..96d5bfd438 100644 --- a/Open-ILS/src/templates_rdfa/opac/parts/record/summary.tt2 +++ b/Open-ILS/src/templates_rdfa/opac/parts/record/summary.tt2 @@ -146,6 +146,21 @@ IF num_uris > 0;
  • [% l("Edition:") %] [% attrs.edition | html %] + [%- + FOR entry IN attrs.graphic_editions; + FOR alt IN entry.graphic; + diratt = ""; + IF alt.dir; + diratt = ' dir="' _ alt.dir _ '"'; + END; + -%] +
    + [% alt.value | html %] +
    + [%- + END; + END; + -%]
  • [%- END %] [%- IF attrs.publisher %] @@ -160,6 +175,23 @@ IF num_uris > 0; [%- IF attrs.pubdate; %] [% attrs.pubdate | html; %] [%- END; %] + [%- + IF attrs.graphic_pubinfos.size > 0; + FOR entry IN attrs.graphic_pubinfos; + FOR alt IN entry.graphic; + diratt = ""; + IF alt.dir; + diratt = ' dir="' _ alt.dir _ '"'; + END; + -%] +
    + [% alt.value | html %] +
    + [%- + END; + END; + END + -%] [%- END %] -- 2.11.0