Commit 9aa9deb1 authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

cached index

parent 400b7724
......@@ -130,7 +130,7 @@ then
case "plc" return "Orte"
case "org" return "Institutionen"
case "wrk" return "Werke"
default return "The prefix " || $prefix || " is wrong or not listed for translation."
default return "The prefix " || $prefix || " is not in the dictonary."
else
switch ($prefix)
case "eve" return "Ereignis"
......@@ -138,5 +138,16 @@ else
case "plc" return "Ort"
case "org" return "Institution"
case "wrk" return "Werk"
default return "The prefix " || $prefix || " is wrong or not listed for translation."
default return "The prefix " || $prefix || " is not in the dictonary."
};
declare function local:get-list-by-prefix($prefix as xs:string)
as xs:string {
switch ($prefix)
case "eve" return "listEvent"
case "org" return "listOrg"
case "psn" return "listPerson"
case "plc" return "listPlace"
default return
"Prefix " || $prefix || " is not prepared."
};
\ No newline at end of file
xquery version "3.1";
(:~
: This module prepares the index html.
: @author Mathias Göbel
: @version 1.0
: @see https://fontane-nb.dariah.eu/register.html
:)
module namespace f-indexviewer="http://fontane-nb.dariah.eu/indexviewer";
import module namespace f-indexproc="http://fontane-nb.dariah.eu/indexproc" at "index-processor.xqm";
declare namespace ore="http://www.openarchives.org/ore/terms/";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
(: Main caching function
: @return path to the cached document :)
declare function local:cache()
as xs:string {
let $collection-uri := "/db/sade-projects/textgrid/data/xml/xhtml",
$resource := "index.xml"
let $agg := '253st.xml' (: TextGrid Aggregation containing all index files :)
let $uris := (doc('/db/sade-projects/textgrid/data/xml/agg/' || $agg)
//ore:aggregates/substring-after(@rdf:resource, 'textgrid:')
)[. != "25547"] (: omit the bibliography here :)
let $lastMod := $uris ! xmldb:last-modified($f-indexproc:dataPath, . || '.xml')
return
if( xmldb:last-modified($collection-uri, $resource) gt max($lastMod) )
then
(: prerendered index younger than index files: do nothing :)
$collection-uri || "/" || $resource
else
(: create the cache :)
xmldb:store($collection-uri, $resource, f-indexproc:register())
};
(:~
: Recursive transformation of the index document, if a specific item is requested.
: @param $nodes – node to be parsed
: @param $id – a single id prepared with generate-id()
: :)
declare function local:transform-entity($nodes as node()+, $id as xs:string)
as node()* {
for $node in $nodes
let $thisId := generate-id($node)
return
if ($thisId = $id)
then
(: set 'active' class :)
element { node-name($node) } {
$node/@*[local-name() != "class"],
attribute class {
string($node/@class),
"fhighlighted"
},
local:transform-entity($node/node(), $id)
}
else if(starts-with($id, $thisId))
then
typeswitch ($node)
case element(*) return
element { node-name($node) } {
if(contains($node/@class, "tab-pane"))
then
($node/@*[local-name() != "class"],
attribute class {
string($node/@class),
"active"
})
else
$node/@*,
local:transform-entity($node/node(), $id)
}
default return
$node
else $node
};
declare function local:tab-content($index as document-node(), $active as xs:string)
as element(xhtml:div) {
let $indexContentNodes := $index/xhtml:div/xhtml:div/xhtml:div
return
element xhtml:div {
attribute class {"tab-content"},
element xhtml:div {
attribute id {$active},
attribute class {"tab-pane", "active"},
if($f-indexproc:getEntity)
then
let $id := generate-id($index//xhtml:li[@id = $f-indexproc:getEntity])
return
local:transform-entity($indexContentNodes[@id = $active]/*, $id)
else
$indexContentNodes[@id = $active]/*
},
$indexContentNodes[@id != $active]
}
};
declare function f-indexviewer:prepare-new-cache()
as document-node() {
let $path := "/db/sade-projects/textgrid/data/xml/xhtml/index.xml"
let $cleanup :=
if( doc-available($path) )
then xmldb:remove("/db/sade-projects/textgrid/data/xml/xhtml", "index.xml")
else true()
return
doc( local:cache() )
};
declare function f-indexviewer:main($model as map()*, $node as node(), $index as xs:string) {
if ($f-indexproc:notebookParam)
then
f-indexproc:register()/xhtml:div/xhtml:div/xhtml:div[@id = $index]
else
let $doc := doc( local:cache() )
return
if ($f-indexproc:getEntity)
then
let $id := generate-id($doc//xhtml:li[@id = $f-indexproc:getEntity])
return
local:transform-entity($doc/xhtml:div/xhtml:div/xhtml:div[@id = $index], $id)
else
$doc/xhtml:div/xhtml:div/xhtml:div[@id = $index]
};
declare function f-indexviewer:tabs($nodes as node(), $model as map(*), $index as xs:string) {
local:transfrom-tabs($nodes/*, $index)
};
declare function local:transfrom-tabs($nodes as node()+, $index as xs:string) {
for $node in $nodes
return
typeswitch ( $node )
case element(xhtml:div) return
local:transfrom-tabs($node/node(), $index)
case element(xhtml:ul) return
element xhtml:ul {
$node/@*,
local:transfrom-tabs($node/node(), $index)
}
case element(xhtml:li) return
element xhtml:li {
$node/@*[not(@class)],
if($node/xhtml:a/@href = "register-" || $index || ".html")
then
attribute class { string($node/@class), "active"}
else $node/@class,
local:transfrom-tabs($node/node(), $index)
}
case element(xhtml:a) return
element xhtml:a {
if($f-indexproc:notebookParam)
then
($node/@*[local-name() != "href"],
attribute href { string($node/@href) || "?nb=" || $f-indexproc:notebookParam })
else $node/@*,
$node/(*,text())
}
default return
$node
};
......@@ -230,13 +230,13 @@ declare function f-misc:list($datadir, $param, $num as xs:integer) {
<li>Stellenkommentar</li>
<li>Register
<ul>
<li><a href="register.html?nb={$uri[last()]}&amp;i=listPerson">Register der Personen und Werke</a></li>
<li><a href="register.html?nb={$uri[last()]}&amp;i=list-works">Register der Werke</a></li>
<li><a href="register.html?nb={$uri[last()]}&amp;i=list-Fontan">Register der Werke Theodor Fontanes</a></li>
<li><a href="register.html?nb={$uri[last()]}&amp;i=list-periodical">Register der Periodika</a></li>
<li><a href="register.html?nb={$uri[last()]}&amp;i=listPlace">Geographisches Register</a></li>
<li><a href="register.html?nb={$uri[last()]}&amp;i=listEvent">Register der Ereignisse</a></li>
<li><a href="register.html?nb={$uri[last()]}&amp;i=listOrg">Register der Institutionen und Körperschaften</a></li>
<li><a href="register-listPerson.html?nb={$uri[last()]}">Register der Personen und Werke</a></li>
<li><a href="register-list-works.html?nb={$uri[last()]}">Register der Werke</a></li>
<li><a href="register-list-Fontane.html?nb={$uri[last()]}">Register der Werke Theodor Fontanes</a></li>
<li><a href="register-list-periodical.html?nb={$uri[last()]}">Register der Periodika</a></li>
<li><a href="register-listPlace.html?nb={$uri[last()]}">Geographisches Register</a></li>
<li><a href="register-listEvent.html?nb={$uri[last()]}">Register der Ereignisse</a></li>
<li><a href="register-listOrg.html?nb={$uri[last()]}">Register der Institutionen und Körperschaften</a></li>
</ul>
</li>
</ul>
......
......@@ -17,7 +17,6 @@ import module namespace fontaneSfEx="http://fontane-nb.dariah.eu/SfEx" at '../f
import module namespace fontaneLitVZ="http://fontane-nb.dariah.eu/LitVZ" at "../fontane/literaturverzeichnis.xqm";
import module namespace f-register="http://fontane-nb.dariah.eu/register" at "../fontane/register.xqm";
import module namespace fontaneUeberblickskommentar="http://fontane-nb.dariah.eu/Ueberblickskommentar" at "../fontane/ueberblickskommentar.xqm";
import module namespace console="http://exist-db.org/xquery/console";
declare function mviewer:show($node as node(), $model as map(*), $id as xs:string, $view as xs:string?) as item()* {
switch (config:get("sade.develop"))
......
......@@ -9,6 +9,7 @@ import module namespace templates="http://exist-db.org/xquery/templates" ;
import module namespace mviewer="http://sade/multiviewer" at "multiviewer/multiviewer.xqm" ;
import module namespace console="http://exist-db.org/xquery/console" at "java:org.exist.console.xquery.ConsoleModule";
import module namespace f-misc="http://fontane-nb.dariah.eu/ns/SADE/misc" at "fontane/misc.xqm";
import module namespace f-indexviewer="http://fontane-nb.dariah.eu/register" at "fontane/index-viewer.xqm";
import module namespace f-render="http://fontane-nb.dariah.eu/ns/SADE/render" at "fontane/render.xqm";
import module namespace config="http://textgrid.de/ns/SADE/config" at "config/config.xqm";
import module namespace fsearch = "http://sade/faceted-search" at "faceted-search/faceted-search.xqm";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment