]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/record/authors.tt2
LP#1414033: Add rel="nofollow" to search/browse links
[working/Evergreen.git] / Open-ILS / src / templates / opac / parts / record / authors.tt2
1 [%-  
2
3 PROCESS "opac/parts/relators.tt2";
4
5 author_cnt = 0;
6 authors = [
7     {
8         type => 'author', 
9         label => l('Author'),
10         xpath => '//*[@tag="100"]|//*[@tag="110"]|//*[@tag="111"]'
11     }, {
12         type => 'added', 
13         label => l('Added Author'),
14         xpath => '//*[@tag="700"]|//*[@tag="710"]|//*[@tag="711"]'
15     }, {
16         type => 'cast', 
17         label => l('Cast'),
18         xpath => '//*[@tag="508"]'
19     }, {
20         type => 'notes', 
21         label => l('Author Notes: '),
22         xpath => '' # Comes from added content...
23     }
24 ];
25
26 BLOCK normalize_qterm;
27     subfield.textContent.replace('[#"^$\+\-,\.:;&|\[\]()]', ' ');
28 END;
29
30 BLOCK normalize_authors;
31     link_term = link_term _ ' ' _ sf;
32     sf_raw = PROCESS normalize_qterm;
33     qterm = qterm _ ' ' _ sf_raw;
34     indexed_term = 1;
35 END;
36
37 BLOCK build_author_links;
38     FOR node IN ctx.marc_xml.findnodes(xpath);
39         author_cnt = author_cnt + 1;
40         contrib_ref = '#schemacontrib' _ author_cnt;
41         iprop = ''; # schema.org item type / property
42         link_term = ''; # Linked term (e.g. Personal name + Fuller form of name)
43         supp_term = ''; # Supplementary terms
44         qterm = ''; # Search query
45         tlabel = '';
46         birthdate = '';
47         deathdate = '';
48         graphics = [];
49         tag = node.getAttribute('tag');
50         FOR subfield IN node.childNodes;
51             indexed_term = '';
52             NEXT UNLESS subfield.nodeName == "subfield";
53             code = subfield.getAttribute('code');
54             IF code == '4';
55                 relcode = subfield.textContent.substr(0,3);
56                 tlabel = relators.$relcode || label;
57             END;
58             IF code == '6';
59                target_field = tag;
60                linked_fields = [subfield.textContent()];
61                get_linked_880s;
62             END;
63             NEXT UNLESS code.match('[a-z]');
64             sf = subfield.textContent | html;
65
66             # Only Persons have birth/death dates in schema.org
67             # Match personal/corporate/conference MODS subfields
68             IF tag.substr(1,2) == '00';
69                 IF code.match('[abcqu]');
70                     PROCESS normalize_authors;
71                 END;
72                 IF code.match('d');
73                     IF subfield.textContent.match('^\s*\d{4}');
74                         birthdate = subfield.textContent.replace('^\s*(\d{4}).*$', '$1');
75                     END;
76                     IF subfield.textContent.match('-\d{4}.*$');
77                         deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4}).*$', '$1');
78                     END;
79                     indexed_term = 1;
80                     sf_raw = PROCESS normalize_qterm;
81                     qterm = qterm _ sf_raw;
82                 END;
83             ELSIF tag.substr(1,2) == '10';
84                 IF code.match('[abcdn]');
85                     PROCESS normalize_authors;
86                 END;
87             ELSIF code.match('[acdeq]');
88                 PROCESS normalize_authors;
89             END;
90             UNLESS indexed_term;
91                 supp_term = supp_term _ ' ' _ sf;
92             END;
93         END;
94         url = mkurl(ctx.opac_root _ '/results', {query => qterm.replace('^\s*(.*?)\s*$', '$1'), qtype => 'author'}, stop_parms.merge(expert_search_parms, general_search_parms, browse_search_parms, facet_search_parms));
95         author_type = (tlabel || label) | html;
96         
97         # schema.org changes
98         IF type == 'author';
99             IF tag.substr(1,2) == '10' && args.schema.itemtype && args.schema.itemtype.match('MusicAlbum');
100                 iprop = ' typeof="MusicGroup" property="byArtist"';
101             ELSIF tag.substr(1,2) == '00';
102                 iprop = ' typeof="Person" property="author"';
103             ELSE;
104                 iprop = ' typeof="Organization" property="author"';
105             END;
106         ELSIF type == 'added';
107             IF tag.substr(1,2) == '00';
108                 iprop = ' typeof="Person" property="contributor';
109             ELSE;
110                 iprop = ' typeof="Organization" property="contributor';
111             END;
112             IF relcode;
113                 iprop = iprop _ ' http://id.loc.gov/vocabulary/relators/' _ relcode;
114             END;
115             iprop = iprop _ '"';
116         END;
117         authtml = ' <span class="rdetail-author-div"' _ iprop _ ' resource="' _ contrib_ref _ '"><a href="' _ url _ '" rel="nofollow" vocab=""><span resource="' _ contrib_ref _ '">';
118         IF iprop; authtml = authtml _ '<span property="name">'; END;
119         authtml = authtml _ link_term.replace('^\s+', '');
120         IF iprop; authtml = authtml _ '</span>'; END;
121         IF birthdate;
122             authtml = authtml _ ' <span property="birthDate">' _ birthdate _ '</span>-';
123         END;
124         IF deathdate;
125             authtml = authtml _ '<span property="deathDate">' _ deathdate _ '</span>';
126         END;
127         authtml = authtml _ '</span></a>'; # End search link
128
129         # Display supplemental terms (mostly about the author's work)
130         IF supp_term;
131             authtml = authtml _ ' ' _ supp_term;
132         END;
133
134         # Display linked 880 fields
135         FOREACH link880 IN graphics;
136             diratt = '';
137             IF link880.dir;
138                 diratt = ' dir="' _ link880.dir _ '"';
139             END;
140             authtml = authtml _ ' <span class="graphic880"' _ diratt _ '>';
141             link880.value | html;
142             authtml = authtml _ '</span>';
143         END;
144         authtml = authtml _ ' (<span property="description">' _ author_type _ '</span>). ';
145         authtml = authtml _ '</span>'; # End author span
146         authlist.push(authtml);
147     END;
148 END;
149 %]
150
151 <div class='rdetail_authors_div'>
152 [%- FOREACH author IN authors;
153     NEXT UNLESS author.xpath; 
154     authlist = [];
155     PROCESS build_author_links(
156         xpath=author.xpath, label=author.label, type=author.type
157     );
158     IF authlist.size;
159         FOREACH authtml IN authlist;
160             authtml;
161         END;
162     END;
163 END %]
164 </div>
165
166