]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/record/authors.tt2
LP#1752434: (follow-up) fix un/highlighting of author name
[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 find_hl_value;
27     outlist = [];
28     norm_needle = PROCESS normalize_string(unnorm_string=needle);
29     FOREACH hl IN attrs.display_field_list;
30         norm_value = PROCESS normalize_string(unnorm_string=hl.value);
31         outlist.push(hl.$f) IF norm_value == norm_needle;
32     END;
33
34     outlist.0;
35 END;
36
37 BLOCK normalize_string;
38     unnorm_string.replace('[#"^$\+\-,\.:;&|\[\]()]', ' ').replace('\s+',' ').replace('^\s+','').replace('\s+$','');
39 END;
40
41 BLOCK normalize_qterm;
42     PROCESS normalize_string(unnorm_string=subfield.textContent);
43 END;
44
45 BLOCK normalize_authors;
46     link_term = link_term _ ' ' _ sf;
47     sf_raw = PROCESS normalize_qterm;
48     qterm = qterm _ ' ' _ sf_raw;
49     indexed_term = 1;
50 END;
51
52 BLOCK build_author_links;
53     FOR node IN ctx.marc_xml.findnodes(xpath);
54         author_cnt = author_cnt + 1;
55         contrib_ref = '#schemacontrib' _ author_cnt;
56         iprop = ''; # schema.org item type / property
57         link_term = ''; # Linked term (e.g. Personal name + Fuller form of name)
58         supp_term = ''; # Supplementary terms
59         qterm = ''; # Search query
60         tlabels = [];
61         birthdate = '';
62         deathdate = '';
63         graphics = [];
64         tag = node.getAttribute('tag');
65         FOR subfield IN node.childNodes;
66             indexed_term = '';
67             NEXT UNLESS subfield.nodeName == "subfield";
68             code = subfield.getAttribute('code');
69             IF code == '4';
70                 relcode = subfield.textContent.substr(0,3);
71                 tlabels.push( relators.$relcode || label );
72             END;
73             IF code == 'e';
74                 tlabels.push( subfield.textContent() );
75                 indexed_term = 1;
76             END;
77             IF code == '6';
78                target_field = tag;
79                linked_fields = [subfield.textContent()];
80                get_linked_880s;
81             END;
82             NEXT UNLESS code.match('[a-z]');
83             sf = subfield.textContent | html;
84
85             # Only Persons have birth/death dates in schema.org
86             # Match personal/corporate/conference MODS subfields
87             IF tag.substr(1,2) == '00';
88                 IF code.match('[abcqu]');
89                     PROCESS normalize_authors;
90                 END;
91                 IF code.match('d');
92                     IF subfield.textContent.match('^\s*\d{4}');
93                         birthdate = subfield.textContent.replace('^\s*(\d{4}).*$', '$1');
94                     END;
95                     IF subfield.textContent.match('-\d{4}.*$');
96                         deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4}).*$', '$1');
97                     END;
98                     indexed_term = 1;
99                     sf_raw = PROCESS normalize_qterm;
100                     qterm = qterm _ sf_raw;
101                 END;
102             ELSIF tag.substr(1,2) == '10';
103                 IF code.match('[abcdn]');
104                     PROCESS normalize_authors;
105                 END;
106             ELSIF code.match('[acdeq]');
107                 PROCESS normalize_authors;
108             END;
109             UNLESS indexed_term;
110                 supp_term = supp_term _ ' ' _ sf;
111             END;
112         END;
113         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));
114         tlabel = tlabels.join(', ');
115         tlabels = [];
116         author_type = (tlabel || label) | html;
117         
118         # schema.org changes
119         IF type == 'author';
120             IF tag.substr(1,2) == '10' && args.schema.itemtype && args.schema.itemtype.match('MusicAlbum');
121                 iprop = ' typeof="MusicGroup" property="byArtist"';
122             ELSIF tag.substr(1,2) == '00';
123                 iprop = ' typeof="Person" property="author"';
124             ELSE;
125                 iprop = ' typeof="Organization" property="author"';
126             END;
127         ELSIF type == 'added';
128             IF tag.substr(1,2) == '00';
129                 iprop = ' typeof="Person" property="contributor';
130             ELSE;
131                 iprop = ' typeof="Organization" property="contributor';
132             END;
133             IF relcode;
134                 iprop = iprop _ ' http://id.loc.gov/vocabulary/relators/' _ relcode;
135             END;
136             iprop = iprop _ '"';
137         END;
138
139         link_term = link_term.replace('^\s+', '');
140         match_term = link_term _ ' ' _ birthdate _ ' ' _ deathdate;
141         matching_author_hl = PROCESS find_hl_value needle=match_term f=attrs.hl_field;
142
143         authtml = ' <span class="rdetail-author-div"' _ iprop _ ' resource="' _ contrib_ref _ '"><a href="' _ url _ '"><span resource="' _ contrib_ref _ '">';
144         IF iprop; authtml = authtml _ '<span property="name">'; END;
145         IF matching_author_hl;
146             authtml = authtml _ matching_author_hl;
147         ELSE;
148             authtml = authtml _ link_term;
149         END;
150         IF iprop; authtml = authtml _ '</span>'; END;
151         IF birthdate AND !matching_author_hl;
152             authtml = authtml _ ' <span property="birthDate">' _ birthdate _ '</span>-';
153         END;
154         IF deathdate AND !matching_author_hl;
155             authtml = authtml _ '<span property="deathDate">' _ deathdate _ '</span>';
156         END;
157         authtml = authtml _ '</span></a>'; # End search link
158
159         # Display supplemental terms (mostly about the author's work)
160         IF supp_term;
161             authtml = authtml _ ' ' _ supp_term;
162         END;
163
164         # Display linked 880 fields
165         FOREACH link880 IN graphics;
166             diratt = '';
167             IF link880.dir;
168                 diratt = ' dir="' _ link880.dir _ '"';
169             END;
170             authtml = authtml _ ' <span class="graphic880"' _ diratt _ '>';
171             link880.value | html;
172             authtml = authtml _ '</span>';
173         END;
174         authtml = authtml _ ' (<span property="description">' _ author_type _ '</span>). ';
175         authtml = authtml _ '</span>'; # End author span
176         authlist.push(authtml);
177     END;
178 END;
179 %]
180
181 <div class='rdetail_authors_div'>
182 [%- FOREACH author IN authors;
183     NEXT UNLESS author.xpath; 
184     authlist = [];
185     PROCESS build_author_links(
186         xpath=author.xpath, label=author.label, type=author.type
187     );
188     IF authlist.size;
189         FOREACH authtml IN authlist;
190             authtml;
191         END;
192     END;
193 END %]
194 </div>
195
196