Skip to content

Commit 14c464d

Browse files
committed
Updates to tei view
1 parent 1a7ef90 commit 14c464d

4 files changed

Lines changed: 181 additions & 150 deletions

File tree

srophe-app/modules/config.xqm

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,74 @@ declare variable $config:app-root :=
2929
substring-before($modulePath, "/modules")
3030
;
3131

32-
declare variable $config:data-root := $config:app-root || "/data";
33-
3432
declare variable $config:repo-descriptor := doc(concat($config:app-root, "/repo.xml"))/repo:meta;
3533

3634
declare variable $config:expath-descriptor := doc(concat($config:app-root, "/expath-pkg.xml"))/expath:package;
3735

36+
(: Srophe variables :)
37+
(: Get repo-config.xml to parse global varaibles :)
38+
declare variable $config:get-config := doc($config:app-root || '/repo-config.xml');
39+
40+
(: Get access-config.xml to parse global varaibles for git-sync and recaptcha :)
41+
declare variable $config:get-access-config := doc($config:app-root || '/access-config.xml');
42+
43+
(: Establish eXist-db data root defined in repo.xml 'data-root':)
44+
declare variable $config:data-root :=
45+
let $app-root := $config:get-config//repo:app-root/text()
46+
let $data-root := concat($config:get-config//repo:data-root/text(),'/data')
47+
return replace($config:app-root, $app-root, $data-root);
48+
49+
(: Establish main navigation for app, used in templates for absolute links. :)
50+
declare variable $config:nav-base :=
51+
if($config:get-config//repo:nav-base/text() != '') then $config:get-config//repo:nav-base/text()
52+
else if($config:get-config//repo:nav-base/text() = '/') then ''
53+
else '';
54+
55+
(: Base URI used in record tei:idno :)
56+
declare variable $config:base-uri := $config:get-config//repo:base_uri/text();
57+
58+
(: Webapp title :)
59+
declare variable $config:app-title := $config:get-config//repo:title/text();
60+
61+
(: Webapp URL :)
62+
declare variable $config:app-url := $config:get-config//repo:url/text();
63+
64+
(: Element to use as id xml:id or idno :)
65+
declare variable $config:document-id := $config:get-config//repo:document-ids;
66+
67+
(: Map rendering, google or leaflet :)
68+
declare variable $config:app-map-option := $config:get-config//repo:maps/repo:option[@selected='true']/text();
69+
declare variable $config:map-api-key := $config:get-config//repo:maps/repo:option[@selected='true']/@api-key;
70+
71+
72+
(: Recaptcha Key :)
73+
declare variable $config:recaptcha :=
74+
if($config:get-access-config//recaptcha/site-key-variable != '') then
75+
environment-variable($config:get-access-config//recaptcha/site-key-variable/text())
76+
else if($config:get-access-config//private-key/text() != '') then $config:get-access-config//private-key/text()
77+
else ();
78+
79+
(:~
80+
: Get collection data
81+
: @param $collection match collection name in repo-config.xml
82+
:)
83+
declare function config:collection-vars($collection as xs:string?) as node()?{
84+
let $collection-config := $config:get-config//repo:collections
85+
for $collection in $collection-config/repo:collection[@name = $collection]
86+
return $collection
87+
};
88+
89+
(:~
90+
: Get collection data
91+
: @param $collection match collection name in repo-config.xml
92+
:)
93+
declare function config:collection-title($node as node(), $model as map(*), $collection as xs:string?) as xs:string?{
94+
if(config:collection-vars($collection)/@title != '') then
95+
string(config:collection-vars($collection)/@title)
96+
else $config:app-title
97+
98+
};
99+
38100
(:~
39101
: Resolve the given path using the current application context.
40102
: If the app resides in the file system,
@@ -97,4 +159,5 @@ declare function config:app-info($node as node(), $model as map(*)) {
97159
<td>{ request:get-attribute("$exist:controller") }</td>
98160
</tr>
99161
</table>
100-
};
162+
};
163+

srophe-app/modules/content-negotiation/content-negotiation.xql

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import module namespace config="http://syriaca.org/config" at "../config.xqm";
1212
import module namespace cntneg="http://syriaca.org/cntneg" at "content-negotiation.xqm";
1313
import module namespace tei2html="http://syriaca.org/tei2html" at "tei2html.xqm";
1414

15-
(: Data processing module. :)
16-
import module namespace data="http://syriaca.org/data" at "../lib/data.xqm";
15+
import module namespace global="http://syriaca.org/global" at "../lib/global.xqm";
1716

1817
(: Import KWIC module:)
1918
import module namespace kwic="http://exist-db.org/xquery/kwic";
@@ -32,47 +31,20 @@ let $path := if(request:get-parameter('id', '') != '') then
3231
else ()
3332
let $data :=
3433
if(request:get-parameter('id', '') != '' or request:get-parameter('doc', '') != '') then
35-
data:get-document()
36-
else if(request:get-parameter-names() != '') then
37-
let $hits := data:search('','','')
38-
return
39-
if(count($hits) gt 0) then
40-
<root>
41-
<action>{string-join(
42-
for $param in request:get-parameter-names()
43-
return concat('&amp;',$param, '=',request:get-parameter($param, '')),'')}</action>
44-
<info>hits: {count($hits)}</info>
45-
<start>1</start>
46-
<results>{
47-
let $start := if(request:get-parameter('start', 1)) then request:get-parameter('start', 1) else 1
48-
let $perpage := if(request:get-parameter('perpage', 10)) then request:get-parameter('perpage', 10) else 10
49-
for $hit in subsequence($hits,$start,$perpage)
50-
let $id := replace($hit/descendant::tei:idno[starts-with(.,$config:base-uri)][1],'/tei','')
51-
let $title := $hit/descendant::tei:titleStmt/tei:title
52-
let $expanded := kwic:expand($hit)
53-
return
54-
<json:value json:array="true">
55-
<id>{$id}</id>
56-
{$title}
57-
<hits>{normalize-space(string-join((tei2html:output-kwic($expanded, $id)),' '))}</hits>
58-
</json:value>
59-
}
60-
</results>
61-
</root>
62-
else
63-
<root>
64-
<json:value json:array="true">
65-
<action>{string-join(
66-
for $param in request:get-parameter-names()
67-
return concat('&amp;',$param, '=',request:get-parameter($param, '')),'')}</action>
68-
<info>No results</info>
69-
<start>0</start>
70-
</json:value>
71-
</root>
34+
let $id := request:get-parameter('id', '')
35+
let $parse-id :=
36+
if(contains($id,$global:base-uri) or starts-with($id,'http://')) then $id
37+
else if(contains(request:get-uri(),$global:nav-base)) then
38+
replace(request:get-uri(),$global:nav-base, $global:base-uri)
39+
else if(contains(request:get-uri(),$global:base-uri)) then request:get-uri()
40+
else $id
41+
let $final-id := if(ends-with($parse-id,'.html')) then substring-before($parse-id,'.html')
42+
else if(ends-with($parse-id,'/tei')) then substring-before($parse-id,'/tei')
43+
else $parse-id
44+
return global:get-rec($final-id)
7245
else ()
7346
let $format := if(request:get-parameter('format', '') != '') then request:get-parameter('format', '') else 'xml'
7447
return
7548
if(not(empty($data))) then
7649
cntneg:content-negotiation($data, $format, $path)
77-
else ()
78-
50+
else ()

0 commit comments

Comments
 (0)