Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for different authors in the URL, closes #316 #333

Merged
merged 13 commits into from
Nov 28, 2019
Next Next commit
fix breadcrumbs and URL rewritings for multiple authors #316
  • Loading branch information
peterstadler committed Nov 14, 2019
commit 2c3bac5a51e5dc7fd9aca5b011024e9a2e557e3d
22 changes: 10 additions & 12 deletions modules/app.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import module namespace wega-util-shared="http://xquery.weber-gesamtausgabe.de/m
: @return xs:string
:)
declare function app:createUrlForDoc($doc as document-node()?, $lang as xs:string) as xs:string? {
let $path := controller:path-to-resource($doc, $lang)
let $path := controller:path-to-resource($doc, $lang)[1]
return
if($doc and $path) then core:link-to-current-app($path || '.html')
else ()
Expand Down Expand Up @@ -181,10 +181,9 @@ declare function app:set-line-wrap($node as node(), $model as map(*)) as element
declare
%templates:default("lang", "en")
function app:breadcrumb-person($node as node(), $model as map(*), $lang as xs:string) as element(a) {
let $authorElem := query:get-author-element($model?doc)[1]
let $authorElem := query:get-author-element($model?doc)[(@key, @dbkey) = tokenize($model?('exist:path'), '/')]
let $authorID :=
if(config:is-person($model('docID'))) then $model('docID')
else if($model?docType='diaries') then 'A002068'
else $authorElem/(@key, @dbkey)
let $href :=
if ($authorID = config:get-option('anonymusID')) then ()
Expand All @@ -205,11 +204,10 @@ declare
declare
%templates:default("lang", "en")
function app:breadcrumb-docType($node as node(), $model as map(*), $lang as xs:string) as element(a) {
let $authorID := query:get-authorID($model('doc'))
let $href := core:link-to-current-app(functx:substring-before-last(controller:path-to-resource($model('doc'), $lang), '/'))
let $href := core:link-to-current-app(functx:substring-before-last($model('$exist:path'), '/'))
let $display-name := replace(functx:substring-after-last($href, '/'), '_', ' ')
let $elem :=
if($href and not($authorID = config:get-option('anonymusID'))) then QName('http://www.w3.org/1999/xhtml', 'a')
if($href and not(contains($href, config:get-option('anonymusID')))) then QName('http://www.w3.org/1999/xhtml', 'a')
else QName('http://www.w3.org/1999/xhtml', 'span')
return
element {$elem} {
Expand Down Expand Up @@ -251,7 +249,7 @@ declare
declare
%templates:default("lang", "en")
function app:breadcrumb-var($node as node(), $model as map(*), $lang as xs:string) as element() {
let $pathTokens := tokenize(request:get-attribute('$exist:path'), '/')
let $pathTokens := tokenize($model?('$exist:path'), '/')
return
element {node-name($node)} {
$node/@*,
Expand Down Expand Up @@ -314,7 +312,7 @@ declare
case 'gnd-beacon' return if($model('gnd')) then 'beacon.html' else ()
default return ()
let $ajax-url :=
if(config:get-doctype-by-id($model('docID')) and $ajax-resource) then core:link-to-current-app(controller:path-to-resource($model('doc'), $lang) || '/' || $ajax-resource)
if(config:get-doctype-by-id($model('docID')) and $ajax-resource) then core:link-to-current-app(controller:path-to-resource($model('doc'), $lang)[1] || '/' || $ajax-resource)
else if(gl:spec($model?specID, $model?schemaID) and $ajax-resource) then core:link-to-current-app(replace($model('exist:path'), '\.[xhtml]+$', '') || '/' || $ajax-resource)
else ()
return
Expand Down Expand Up @@ -1532,7 +1530,7 @@ declare
%templates:default("lang", "en")
function app:csLink($node as node(), $model as map(*), $lang as xs:string) as element(div) {
let $doc := $model('doc')
let $correspondent-1-key := query:get-authorID($doc)
let $correspondent-1-key := query:get-authorID($doc)[1]
let $correspondent-1-gnd := query:get-gnd($correspondent-1-key)
let $correspondent-2-key := ($doc//tei:correspAction[@type = 'received']//@key[parent::tei:persName or parent::name or parent::tei:orgName])[1]
let $correspondent-2-gnd := query:get-gnd($correspondent-2-key)
Expand Down Expand Up @@ -1575,15 +1573,15 @@ declare
: @return element html:p
:)
declare %private function app:get-news-foot($doc as document-node(), $lang as xs:string) as element(p)? {
let $authorID := query:get-authorID($doc)
let $authorElem := query:get-author-element($doc)
let $dateFormat :=
if ($lang = 'de') then '[FNn], [D]. [MNn] [Y]'
else '[FNn], [MNn] [D], [Y]'
return
if($authorID) then
if(count($authorElem) gt 0) then
element p {
attribute class {'authorDate'},
app:printCorrespondentName(query:get-author-element($doc), $lang, 'fs'),
app:printCorrespondentName($authorElem, $lang, 'fs'),
concat(', ', date:format-date(xs:date($doc//tei:publicationStmt/tei:date/xs:dateTime(@when)), $dateFormat, $lang))
}
else()
Expand Down
16 changes: 9 additions & 7 deletions modules/controller.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ declare function controller:dispatch($exist-vars as map(*)) as element(exist:dis
map:entry('media-type', $media-type)
))
let $doc := core:doc($docID)
let $path := controller:encode-path-segments-for-uri(controller:path-to-resource($doc, $exist-vars('lang')))
let $path := controller:path-to-resource($doc, $exist-vars('lang')) ! controller:encode-path-segments-for-uri(.)
(: let $log := util:log-system-out($exist-vars('exist:path')):)
(: let $log := util:log-system-out($path):)
return
if($media-type and $exist-vars('exist:path') eq $path || '.' || $media-type) then controller:forward-document($updated-exist-vars)
else if($media-type and $path) then controller:redirect-absolute('/' || $path || '.' || $media-type)
if($media-type and $exist-vars('exist:path') = ($path ! (. || '.' || $media-type))) then controller:forward-document($updated-exist-vars)
else if($media-type and count($path) gt 0) then controller:redirect-absolute('/' || $path[1] || '.' || $media-type)
(: last else case: document does not exist :)
else controller:error(map:put($updated-exist-vars, 'error-message', 'resource not found'), 404)
};
Expand Down Expand Up @@ -381,8 +381,10 @@ declare function controller:encode-path-segments-for-uri($uri-string as xs:strin
: Warning:
: * No URL encoding here, see controller:encode-path-segments-for-uri()
: * resulting paths do not include exist:prefix, see core:link-to-current-app()
:
: @return a sequence of valid (external) paths for a document, based on the authors and docType
~:)
declare function controller:path-to-resource($doc as document-node()?, $lang as xs:string) as xs:string? {
declare function controller:path-to-resource($doc as document-node()?, $lang as xs:string) as xs:string* {
let $docID := $doc/*/@xml:id
let $docType := config:get-doctype-by-id($docID) (: Die originale Darstellung der doctypes, also 'persons', 'letters' etc:)
let $displayName := (: Die Darstellung als URL, also 'Korrespondenz', 'Tagebücher' etc. :)
Expand All @@ -402,7 +404,7 @@ declare function controller:path-to-resource($doc as document-node()?, $lang as
if($docType = ('persons', 'orgs', 'places')) then str:join-path-elements(('/', $lang, $docID))
else if($docType = 'var') then str:join-path-elements(('/', $lang, lang:get-language-string('project', $lang), $docID))
else if($docType = 'addenda') then str:join-path-elements(('/', $lang, lang:get-language-string('project', $lang), lang:get-language-string('volContents', $lang), $docID))
else if($authorID and $displayName) then str:join-path-elements(('/', $lang, $authorID, $displayName, $docID))
else if(count($authorID) gt 0 and $displayName) then $authorID ! str:join-path-elements(('/', $lang, ., $displayName, $docID))
else core:logToFile('error', 'controller:path-to-resource(): could not create path for ' || $docID)
};

Expand All @@ -423,7 +425,7 @@ declare function controller:docType-url-for-author($author as document-node(), $
case 'letters' return 'correspondence'
default return $docType
return
core:link-to-current-app(str:join-path-elements((controller:path-to-resource($author, $lang), $docType-path-segment || '.html')))
core:link-to-current-app(str:join-path-elements((controller:path-to-resource($author, $lang)[1], $docType-path-segment || '.html')))
};

(:
Expand Down Expand Up @@ -478,7 +480,7 @@ declare function controller:redirect-by-gnd($exist-vars as map(*)) as element(ex
let $doc := query:doc-by-gnd(controller:basename($exist-vars('exist:resource')))[last()]
let $media-type := controller:media-type($exist-vars)
return
if(exists($doc) and $media-type) then controller:redirect-absolute(controller:path-to-resource($doc, $exist-vars('lang')) || '.' || $media-type)
if(exists($doc) and $media-type) then controller:redirect-absolute(controller:path-to-resource($doc, $exist-vars('lang'))[1] || '.' || $media-type)
else controller:error($exist-vars, 404)
};

Expand Down
2 changes: 1 addition & 1 deletion modules/lod.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ declare function lod:jsonld($model as map(*), $lang as xs:string) as map(*) {
let $schema.org-type := lod:schema.org-type($model)
let $identifier := lod:DC.identifier($model)
let $url :=
if($model?doc) then core:permalink(controller:path-to-resource($model?doc, $lang))
if($model?doc) then core:permalink(controller:path-to-resource($model?doc, $lang)[1])
else $identifier
let $jsonld-common := map {
'@id': $identifier,
Expand Down
8 changes: 4 additions & 4 deletions modules/query.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ declare function query:title($key as xs:string) as xs:string {
: @param $item the id of the TEI document (or the document node itself) to grab the author from
: @return xs:string the WeGA ID
:)
declare function query:get-authorID($doc as document-node()?) as xs:string {
let $author-element := query:get-author-element($doc)[1]
declare function query:get-authorID($doc as document-node()?) as xs:string* {
let $author-element := query:get-author-element($doc)
let $id := $author-element/@key | $author-element/@dbkey
return
if(exists($doc) and $id) then string($id)
if(exists($doc) and count($id) gt 0) then $id ! string(.)
else if(exists($doc)) then config:get-option('anonymusID')
else ''
else ()
};

(:~
Expand Down