Skip to content

Commit

Permalink
Use placeholders and replace for prerendered json
Browse files Browse the repository at this point in the history
  • Loading branch information
simar0at committed May 10, 2024
1 parent cb224a2 commit f34e557
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions vicav.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ function vicav:_project_config() {
return if (matches($accept-header, '[+/]json'))
then
let $jsonAsXML :=
if (exists(try{collection('prerendered_json')} catch err:FODC0002 {()}) and
exists(collection('prerendered_json')//json[projectConfig/baseURIPublic = $publicURI]))
then collection('prerendered_json')//json[projectConfig/baseURIPublic = $publicURI] update {insert node <cached type="boolean">true</cached> as first into ./projectConfig}
if (exists(try{collection('prerendered_json')} catch err:FODC0002 {()}))
then collection('prerendered_json')//json
update {insert node <cached type="boolean">true</cached> as first into ./projectConfig,
.//text()[contains(., '{{host_name}}')]!(replace value of node . with replace(., '{{host_name}}/{{path}}', $publicURI, 'q'))}
else vicav:project_config_json_as_xml($publicURI) update {insert node <cached type="boolean">false</cached> as first into ./json/projectConfig}
return serialize($jsonAsXML, map {"method": "json"})
else let $renderedMenu := xslt:transform($config/menu, 'xslt/menu.xslt')
Expand Down Expand Up @@ -186,8 +187,8 @@ declare
%rest:produces('application/problem+xml')
function vicav:prerender_project_config() {
let $accept-header := try { request:header("ACCEPT") } catch basex:http { 'application/xhtml+xml' },
$publicURI := try { replace(util:get-base-uri-public(), '/project', '') } catch basex:http { '' },
$prerenderedFileName := replace($publicURI, 'https?://', '') => translate(':', '_')||'/prerendered_json.xml',
$publicURI := '{{host_name}}/{{path}}',
$prerenderedFileName := $publicURI||'/prerendered_json.xml',
$jsonAsXml := api-problem:or_result (prof:current-ns(),
vicav:project_config_json_as_xml#1, [$publicURI], map:merge((cors:header(()), vicav:return_content_header()))
),
Expand Down

0 comments on commit f34e557

Please sign in to comment.