Loading configuration/defaultHtmlHeadTags.xml +104 Changes for configuration/defaultHtmlHeadTags.xml: 104 added lines, 0 removed lines. Original line number Diff line number Diff line <?xml version="1.0"?> <defaultHtmlHeadTags xmlns:xi="http://www.w3.org/2001/XInclude"> <!-- paramètres element => nom de l'élément html (<link>, <meta>, <title> attribute => valeur de l'attribut principal (name, property, etc.) key => id, basé sur l'attribut {name|property|rel|etc.} path => chemin de l'élément à afficher dans le doc xml ou le fragment html content => contenu par défaut (si pas de path) template => %valeur_a_remplacer% (voir htt.xqm) length => {empty|0|1+} substring + '...' si > 1 exemples : <tag key="icon" path="" default="/edition/core/ui/img/favicon.ico" template="" length=""/> <tag key="title" path="//*:h3" default="Demo Lorem" template="" length=""/> <tag element="meta" attribute="name" key="twitter:domain" path="" default="" template="%url%" length=""/> --> <!-- par edition --> <!--editions> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../editions/demo_lorem/demo_lorem_defaultHtmlHeadTags.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../editions/voces/voces_defaultHtmlHeadTags.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../editions/lmrs/lmrs_defaultHtmlHeadTags.xml"/> </editions--> <!-- commun --> <source type="base"> <!-- meta html --> <tag element="link" attribute="rel" key="icon" path="" default="" template="" length=""/> <tag element="title" key="title" path="//*:h3[1]" default="" template="%value% (%project%)" length=""/> <tag element="meta" attribute="name" key="description" path="//*:p[1]" default="" length="150"/> <tag element="meta" attribute="name" key="author" path="" default="" length=""/> <!-- opengraph --> <tag element="meta" attribute="property" key="og:title" path="//*:h3[1]" default="" template="%value% (%project%)" length=""/> <tag element="meta" attribute="property" key="og:description" path="//*:p[1]" default="" length=""/> <tag element="meta" attribute="property" key="og:type" path="" default="page" length=""/> <tag element="meta" attribute="property" key="og:url" path="" default="" template="%url%" length="150"/> <tag element="meta" attribute="property" key="og:image" path="" default="" length=""/> <!-- twitter --> <tag element="meta" attribute="name" key="twitter:card" path="" default="summary" length=""/> <tag element="meta" attribute="name" key="twitter:title" path="//*:h3[1]" default="" template="%value% (%project%)" length=""/> <tag element="meta" attribute="name" key="twitter:description" path="//*:p[1]" default="" length="150"/> <tag element="meta" attribute="name" key="twitter:creator" path="" default="" length=""/> <tag element="meta" attribute="name" key="twitter:site" path="" default="" length=""/> <tag element="meta" attribute="name" key="twitter:image:src" path="" default="" length=""/> <tag element="meta" attribute="name" key="twitter:domain" path="" default="" template="%url%" length="150"/> <!-- dublin core --> <tag element="meta" attribute="property" key="dc:title" path="//*:h3[1]" default="" template="%value% (%project%)"/> <tag element="meta" attribute="property" key="dc:description" path="//*:p[1]" default="" length="150"/> <tag element="meta" attribute="property" key="dc:creator" path="" default="" length=""/> <tag element="meta" attribute="property" key="dc:type" path="" default="Web page" length=""/> <tag element="meta" attribute="property" key="dc:relation" path="" default="" template="%url%" length=""/> <tag element="meta" attribute="property" key="dc:date" path="" default="" length=""/> <tag element="meta" attribute="property" key="dc:modified" path="" default="" length=""/> </source> <source type="tei"> <!-- meta html --> <tag element="link" attribute="rel" key="icon" path="" default="" template="" length=""/> <tag element="title" key="title" path="//*[self::*:head/parent::*:div[@xml:id='%id%'] | self::*:title[1]]" default="Titre" template="%value% (%project%)" length=""/> <tag element="meta" attribute="name" key="description" path="//*:div[@xml:id='%id%']/*:p[1]" default="" length="150"/> <tag element="meta" attribute="name" key="author" path="//*:teiHeader//descendant::*:persName" default="" length=""/> <!-- opengraph --> <tag element="meta" attribute="property" key="og:title" path="//*[self::*:head/parent::*:div[@xml:id='%id%'] | self::*:title[1]]" default="Titre" template="%value% (%project%)" length=""/> <tag element="meta" attribute="property" key="og:description" path="//*:div[@xml:id='%id%']/*:p[1]" default="" length="150"/> <tag element="meta" attribute="property" key="og:type" path="" default="article" length=""/> <tag element="meta" attribute="property" key="og:url" path="" default="" template="%url%" length=""/> <tag element="meta" attribute="property" key="og:image" path="" default="" length=""/> <!-- twitter --> <tag element="meta" attribute="name" key="twitter:card" path="" default="summary" length=""/> <tag element="meta" attribute="name" key="twitter:title" path="//*[self::*:head/parent::*:div[@xml:id='%id%'] | self::*:title[1]]" default="Titre" template="%value% (%project%)" length=""/> <tag element="meta" attribute="name" key="twitter:description" path="//*:div[@xml:id='%id%']/*:p[1]" default="" length="150"/> <tag element="meta" attribute="name" key="twitter:creator" path="//*:teiHeader//descendant::*:persName" default="" length=""/> <tag element="meta" attribute="name" key="twitter:site" path="" default="" length=""/> <tag element="meta" attribute="name" key="twitter:image:src" path="" default="" length=""/> <tag element="meta" attribute="name" key="twitter:domain" path="" default="" template="%url%" length=""/> <!-- dublin core --> <tag element="meta" attribute="property" key="dc:title" path="//*[self::*:head/parent::*:div[@xml:id='%id%'] | self::*:title[1]]" default="" template="%value% (%project%)" length=""/> <tag element="meta" attribute="property" key="dc:description" path="//*:div[@xml:id='%id%']/*:p[1]" default="" length="150"/> <tag element="meta" attribute="property" key="dc:creator" path="//*:teiHeader//descendant::*:persName" default="" length=""/> <tag element="meta" attribute="property" key="dc:type" path="" default="Web page" length=""/> <tag element="meta" attribute="property" key="dc:relation" path="" default="" template="%url%" length=""/> <tag element="meta" attribute="property" key="dc:date" path="" default="" length=""/> <tag element="meta" attribute="property" key="dc:modified" path="" default="" length=""/> </source> <source type="ead"></source> </defaultHtmlHeadTags> max.xq +26 −12 Changes for max.xq: 26 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -46,11 +46,6 @@ function max:projectHome($project){ web:redirect(request:uri() || '/accueil') }; (:gets a project's HTML page:) declare %rest:GET Loading @@ -59,33 +54,44 @@ declare %output:encoding("UTF-8") %rest:path( "/{$project}/{$page=[a-zA-Z0-9_]+}") function max:page($project, $page){ try{ switch($page) case "sommaire" return let $content := max.toc:getProjectTOC($project) return max.html:render($project, $page, $content) let $meta := max.config:getHtmlHeadTags($project, 'default', $page) return max.html:render($project, $page, $content, (), $meta) case "accueil" (:if 'accueil' frag does not exists -> display route list by default:) return try{ let $content := max.html:getHTMLFragment($project, $page) let $meta := max.config:getHtmlHeadTags($project, 'html', $page) let $contentWithFooter := <div> {$content} {max.html:getFooter($project)} </div> return max.html:render($project, $page, $contentWithFooter) return max.html:render($project, $page, $contentWithFooter, (), $meta) } catch *{ admin:write-log('Page/fragment "'||$page ||'" introuvable ou mal formé', 'INFO'), let $content := max.toc:getProjectTOC($project) return max.html:render($project, $page, $content) let $meta := max.config:getHtmlHeadTags($project, 'default', $page) return max.html:render($project, $page, $content, (), $meta) } default return try{ max.html:render($project, $page, max.html:getHTMLFragment($project,$page)) let $content := max.html:getHTMLFragment($project, $page) let $meta := max.config:getHtmlHeadTags($project, 'default', $page) return max.html:render($project, $page, $content, (), $meta) } catch err:FODC0002{ admin:write-log('Page/fragment "'||$page ||'" introuvable ou mal formé', 'INFO'), Loading @@ -94,6 +100,7 @@ function max:page($project, $page){ } catch err:config {max:max-error($err:description)} catch err:FODC0002 {<div>{$err:description} - {$err:module} - {$err:line-number}</div>} }; Loading @@ -104,7 +111,10 @@ declare %output:encoding("UTF-8") %rest:path("/{$project}/sommaire/{$doc=[^plugins].*\.xml|.*\.svg}") function max:documentTOC($project,$doc){ max.html:render($project, "sommaire", max.toc:getDocumentTOC($project, $doc)) let $content := max.toc:getDocumentTOC($project, $doc) let $meta := max.config:getHtmlHeadTags($project, 'xml', $doc) return max.html:render($project, "sommaire", $content, (), $meta) }; (:gets a project's XML fragment + a navigation bar(wrapped in an html skeleton):) Loading Loading @@ -134,7 +144,11 @@ function max:fragmentToHTMLPage($project, $routeDoc, $id){ return try{ let $html := xslt:transform($xml, $xsltDoc, $xsltParams) return max.html:render($project,$routeDoc, <div>{$html}</div>, $id) let $meta := max.config:getHtmlHeadTags($project, 'xml', $routeDoc, $id) return max.html:render($project, $routeDoc, <div>{$html}</div>, $id, $meta) } catch *{ admin:write-log('Error [' || $err:code || '/' || $err:module || '/' || $err:line-number ||']: ' || $err:description, 'ERROR'), Loading Loading @@ -313,7 +327,6 @@ declare "Max - ERROR: " || $desc }; declare %rest:GET %output:method("xml") Loading @@ -323,3 +336,4 @@ declare function max:buildSitemap($project){ max.html:getSitemap($project) }; plugins/search/search.xqm +4 −1 Changes for plugins/search/search.xqm: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ declare %rest:path("/{$project}/search") function max.plugin.search:searchPage($project){ let $routeList := for $d in collection( max.config:getProjectDBPath($project)) return base-uri($d) (:max.route:HTMLRouteList($project)//a/@href :) let $meta := max.config:getHtmlHeadTags($project, 'default', 'rechercher') let $routeSelect := <select id='searchSelect'>{ <option value='{$max.plugin.search:ALL_TXT}'>Dans tous les textes</option>, for $route in $routeList Loading Loading @@ -48,7 +49,9 @@ function max.plugin.search:searchPage($project){ </div> <div id='searchLoading'>{max.i18n:getText($project,'search.loading')}</div> <div id='searchResults'></div> </div>) </div>, (), $meta) }; declare Loading rxq/config.xqm +52 Changes for rxq/config.xqm: 52 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -4,10 +4,14 @@ module namespace max.config = 'pddn/max/config'; import module namespace rest = "http://exquery.org/ns/restxq"; import module namespace max.cons = 'pddn/max/cons' at 'cons.xqm'; import module namespace max.util = 'pddn/max/util' at 'util.xqm'; import module namespace max.hht = 'pddn/max/hht' at 'hht.xqm'; (: CONFIGURATION file path. :) declare variable $max.config:CONFIGURATION_FILE := "../configuration/configuration.xml"; (: DEFAULT HTML HEAD TAGS file path. :) declare variable $max.config:DEFAULT_HTML_HEAD_TAGS := "../configuration/defaultHtmlHeadTags.xml"; (::) declare %private function max.config:checkConfiguration($projectId){ Loading Loading @@ -255,3 +259,51 @@ declare function max.config:getTextOptionsFragment($project){ string(doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$project]/textOptions/htmlFragment/@file) }; (: get project data from config file :) declare function max.config:getProjectData($project){ map:merge( for $data in doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$project]/projectData/data return map{$data/@key : data($data)} ) }; (: get default html head tags :) declare function max.config:getHtmlHeadTags( $project as xs:string +, $pageType as xs:string +, $pageName as xs:string *){ max.config:getHtmlHeadTags($project, $pageType, $pageName, '' ) }; (: get default html head tags :) declare function max.config:getHtmlHeadTags( $project as xs:string +, $pageType as xs:string +, $pageName as xs:string *, $id as xs:string *){ try{ let $defaultHtmlHeadTags := doc($max.config:DEFAULT_HTML_HEAD_TAGS)//defaultHtmlHeadTags return try{ switch($pageType) case 'default' return max.hht:getHtmlHeadTags_Page($project, 'base', $pageName, $defaultHtmlHeadTags) case 'html' return max.hht:getHtmlHeadTags_HTML($project, 'base', $pageName, $defaultHtmlHeadTags) case 'xml' return max.hht:getHtmlHeadTags_XML($project, $pageType, $pageName, $id, $defaultHtmlHeadTags) default return map{"error" : "Le type doit être 'default', 'html' ou 'xml'"} } catch *{ map{"error" : "Une erreur est survenue. (1)"} } } catch *{ map{"error" : "Une erreur est survenue. (2)"} } }; rxq/hht.xqm +180 Changes for rxq/hht.xqm: 180 added lines, 0 removed lines. Original line number Diff line number Diff line (: For conditions of distribution and use, see the accompanying legal.txt file. :) module namespace max.hht = 'pddn/max/hht'; import module namespace max.cons = 'pddn/max/cons' at 'cons.xqm'; import module namespace max.util = 'pddn/max/util' at 'util.xqm'; import module namespace max.config = 'pddn/max/config' at 'config.xqm'; import module namespace request = "http://exquery.org/ns/request"; declare namespace functx = "http://www.functx.com"; (: 1.1 get default html head tags for pages without fragment nor xml doc :) declare function max.hht:getHtmlHeadTags_Page($project, $pageType, $pageName, $defaultHtmlHeadTags){ map:merge(( max.hht:mapHtmlHeadTags( $project, $pageName, max.hht:edition($defaultHtmlHeadTags, $project, $pageType) ), max.hht:mapHtmlHeadTags( $project, $pageName, max.hht:base($defaultHtmlHeadTags, $pageType) ) )) }; (: 1.2 get default html head tags for HTML fragment :) declare function max.hht:getHtmlHeadTags_HTML($project, $pageType, $pageName, $defaultHtmlHeadTags){ let $fragment := doc(max.util:maxHome() || "/editions/" || $project || "/fragments/" || $pageName || ".frag.html") return max.hht:metaFromFragment($project, $defaultHtmlHeadTags, $pageType, $fragment, '') }; (: 1.3 get default html head tags for XML document :) declare function max.hht:getHtmlHeadTags_XML($project, $pageType, $pageName, $id as xs:string *, $defaultHtmlHeadTags){ let $env := max.config:getXMLFormat($project) let $fragment := ( if($env = 'tei') then ( collection(concat(max.config:getProjectDBPath($project), '/', $pageName))//*:TEI ) else if ($env = 'ead') then ( "" ) else( "" ) ) return max.hht:metaFromFragment($project, $defaultHtmlHeadTags, $env, $fragment, $id) }; (: 1.4 get default html head tags for XML and HTML :) declare function max.hht:metaFromFragment($project, $defaultHtmlHeadTags, $type, $fragment, $id as xs:string *){ map:merge(( max.hht:mapHtmlHeadTagsWithFragment( $project, $fragment, max.hht:edition($defaultHtmlHeadTags, $project, $type), $id), max.hht:mapHtmlHeadTagsWithFragment( $project, $fragment, max.hht:base($defaultHtmlHeadTags, $type), $id) )) }; (: 2.1 default / common tags :) declare function max.hht:base($defaultHtmlHeadTags, $pageType) { $defaultHtmlHeadTags/source[@type=$pageType] }; (: 2.2 tags for edition :) declare function max.hht:edition($defaultHtmlHeadTags, $project, $pageType) { (:$defaultHtmlHeadTags/editions/edition[@xml:id=$project]/source[@type=$pageType]/tag:) doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$project]/htmlHeadTags/source[@type=$pageType] }; (: 3.1 map html head meta tags :) declare function max.hht:mapHtmlHeadTags($project, $pageName, $path){ for $defaultTag in $path/tag let $position := count($defaultTag/preceding-sibling::*) let $valueTmp :=( if(contains($defaultTag/@key, "title") ) then(concat(upper-case(substring($pageName, 1, 1)), lower-case(substring($pageName, 2)))) else(string($defaultTag/@default)) ) return max.hht:mapEntry($project, $defaultTag, $valueTmp, $position) }; (: 3.2 map html head meta tags for fragments and xml doc :) declare function max.hht:mapHtmlHeadTagsWithFragment($project, $fragment, $path, $id as xs:string *){ for $defaultTag in $path/tag let $position := count($defaultTag/preceding-sibling::*) let $valueTmp := ( if($defaultTag/@path != "") then( let $xpath := replace($defaultTag/@path, '%id%', $id) return try{ if($defaultTag/@length != "" and $defaultTag/@length > 0) then( concat(substring(max.hht:evalXpath($xpath, $fragment), 0, $defaultTag/@length), '...') ) else( max.hht:evalXpath($xpath, $fragment) ) } catch *{} ) else("") ) let $valueTmp := ( if($valueTmp = '...') then("") else($valueTmp) ) let $valueTmp2 :=( if($defaultTag/@default != "" and $valueTmp = "" ) then(data($defaultTag/@default)) else($valueTmp) ) return max.hht:mapEntry($project, $defaultTag, $valueTmp2, $position) }; (: 4 functions :) declare function max.hht:evalXpath($xpath, $fragment){ string-join(xquery:eval($xpath, map { '' : $fragment }), " | ") }; declare function max.hht:mapEntry($project, $defaultTag, $tempValue, $position){ let $value := string(max.hht:setValue($project, $defaultTag, $tempValue)) return if(string($defaultTag/@key) = 'title') then(map:entry('title', max.hht:cleanValue($value) )) else( map{ string($defaultTag/@key): map{ "value":max.hht:cleanValue($value), "attribute":string($defaultTag/@attribute) } } ) }; declare function max.hht:setValue($project, $defaultTag, $tempValue){ if($defaultTag/@template != "") then(max.hht:htmlHeadTagsTemplate($project, string($defaultTag/@template), $tempValue) ) else($tempValue) }; declare function max.hht:cleanValue($value){ let $value := replace($value, '
', ' ') let $value := replace($value, '	', ' ') let $value := replace($value, '\s{2,}', ' ') return $value }; (: 5 html head tags template:) declare function max.hht:htmlHeadTagsTemplate($project, $template, $value){ let $scheme := request:scheme() let $port := request:port() let $hostname := request:hostname() let $path := request:path() let $url := ( if(fn:exists(string($port)) = xs:boolean(1)) then() else() ) let $projectName := max.config:getProjectPrettyName($project) let $return := $template let $return := replace($return, "%value%", $value) let $return := replace($return, "%project%", string($projectName)) let $return := replace($return, "%url%", $value || $url || $path ) let $return := replace($return, "%image%", $url || $value ) return $return }; Loading
configuration/defaultHtmlHeadTags.xml +104 Changes for configuration/defaultHtmlHeadTags.xml: 104 added lines, 0 removed lines. Original line number Diff line number Diff line <?xml version="1.0"?> <defaultHtmlHeadTags xmlns:xi="http://www.w3.org/2001/XInclude"> <!-- paramètres element => nom de l'élément html (<link>, <meta>, <title> attribute => valeur de l'attribut principal (name, property, etc.) key => id, basé sur l'attribut {name|property|rel|etc.} path => chemin de l'élément à afficher dans le doc xml ou le fragment html content => contenu par défaut (si pas de path) template => %valeur_a_remplacer% (voir htt.xqm) length => {empty|0|1+} substring + '...' si > 1 exemples : <tag key="icon" path="" default="/edition/core/ui/img/favicon.ico" template="" length=""/> <tag key="title" path="//*:h3" default="Demo Lorem" template="" length=""/> <tag element="meta" attribute="name" key="twitter:domain" path="" default="" template="%url%" length=""/> --> <!-- par edition --> <!--editions> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../editions/demo_lorem/demo_lorem_defaultHtmlHeadTags.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../editions/voces/voces_defaultHtmlHeadTags.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../editions/lmrs/lmrs_defaultHtmlHeadTags.xml"/> </editions--> <!-- commun --> <source type="base"> <!-- meta html --> <tag element="link" attribute="rel" key="icon" path="" default="" template="" length=""/> <tag element="title" key="title" path="//*:h3[1]" default="" template="%value% (%project%)" length=""/> <tag element="meta" attribute="name" key="description" path="//*:p[1]" default="" length="150"/> <tag element="meta" attribute="name" key="author" path="" default="" length=""/> <!-- opengraph --> <tag element="meta" attribute="property" key="og:title" path="//*:h3[1]" default="" template="%value% (%project%)" length=""/> <tag element="meta" attribute="property" key="og:description" path="//*:p[1]" default="" length=""/> <tag element="meta" attribute="property" key="og:type" path="" default="page" length=""/> <tag element="meta" attribute="property" key="og:url" path="" default="" template="%url%" length="150"/> <tag element="meta" attribute="property" key="og:image" path="" default="" length=""/> <!-- twitter --> <tag element="meta" attribute="name" key="twitter:card" path="" default="summary" length=""/> <tag element="meta" attribute="name" key="twitter:title" path="//*:h3[1]" default="" template="%value% (%project%)" length=""/> <tag element="meta" attribute="name" key="twitter:description" path="//*:p[1]" default="" length="150"/> <tag element="meta" attribute="name" key="twitter:creator" path="" default="" length=""/> <tag element="meta" attribute="name" key="twitter:site" path="" default="" length=""/> <tag element="meta" attribute="name" key="twitter:image:src" path="" default="" length=""/> <tag element="meta" attribute="name" key="twitter:domain" path="" default="" template="%url%" length="150"/> <!-- dublin core --> <tag element="meta" attribute="property" key="dc:title" path="//*:h3[1]" default="" template="%value% (%project%)"/> <tag element="meta" attribute="property" key="dc:description" path="//*:p[1]" default="" length="150"/> <tag element="meta" attribute="property" key="dc:creator" path="" default="" length=""/> <tag element="meta" attribute="property" key="dc:type" path="" default="Web page" length=""/> <tag element="meta" attribute="property" key="dc:relation" path="" default="" template="%url%" length=""/> <tag element="meta" attribute="property" key="dc:date" path="" default="" length=""/> <tag element="meta" attribute="property" key="dc:modified" path="" default="" length=""/> </source> <source type="tei"> <!-- meta html --> <tag element="link" attribute="rel" key="icon" path="" default="" template="" length=""/> <tag element="title" key="title" path="//*[self::*:head/parent::*:div[@xml:id='%id%'] | self::*:title[1]]" default="Titre" template="%value% (%project%)" length=""/> <tag element="meta" attribute="name" key="description" path="//*:div[@xml:id='%id%']/*:p[1]" default="" length="150"/> <tag element="meta" attribute="name" key="author" path="//*:teiHeader//descendant::*:persName" default="" length=""/> <!-- opengraph --> <tag element="meta" attribute="property" key="og:title" path="//*[self::*:head/parent::*:div[@xml:id='%id%'] | self::*:title[1]]" default="Titre" template="%value% (%project%)" length=""/> <tag element="meta" attribute="property" key="og:description" path="//*:div[@xml:id='%id%']/*:p[1]" default="" length="150"/> <tag element="meta" attribute="property" key="og:type" path="" default="article" length=""/> <tag element="meta" attribute="property" key="og:url" path="" default="" template="%url%" length=""/> <tag element="meta" attribute="property" key="og:image" path="" default="" length=""/> <!-- twitter --> <tag element="meta" attribute="name" key="twitter:card" path="" default="summary" length=""/> <tag element="meta" attribute="name" key="twitter:title" path="//*[self::*:head/parent::*:div[@xml:id='%id%'] | self::*:title[1]]" default="Titre" template="%value% (%project%)" length=""/> <tag element="meta" attribute="name" key="twitter:description" path="//*:div[@xml:id='%id%']/*:p[1]" default="" length="150"/> <tag element="meta" attribute="name" key="twitter:creator" path="//*:teiHeader//descendant::*:persName" default="" length=""/> <tag element="meta" attribute="name" key="twitter:site" path="" default="" length=""/> <tag element="meta" attribute="name" key="twitter:image:src" path="" default="" length=""/> <tag element="meta" attribute="name" key="twitter:domain" path="" default="" template="%url%" length=""/> <!-- dublin core --> <tag element="meta" attribute="property" key="dc:title" path="//*[self::*:head/parent::*:div[@xml:id='%id%'] | self::*:title[1]]" default="" template="%value% (%project%)" length=""/> <tag element="meta" attribute="property" key="dc:description" path="//*:div[@xml:id='%id%']/*:p[1]" default="" length="150"/> <tag element="meta" attribute="property" key="dc:creator" path="//*:teiHeader//descendant::*:persName" default="" length=""/> <tag element="meta" attribute="property" key="dc:type" path="" default="Web page" length=""/> <tag element="meta" attribute="property" key="dc:relation" path="" default="" template="%url%" length=""/> <tag element="meta" attribute="property" key="dc:date" path="" default="" length=""/> <tag element="meta" attribute="property" key="dc:modified" path="" default="" length=""/> </source> <source type="ead"></source> </defaultHtmlHeadTags>
max.xq +26 −12 Changes for max.xq: 26 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -46,11 +46,6 @@ function max:projectHome($project){ web:redirect(request:uri() || '/accueil') }; (:gets a project's HTML page:) declare %rest:GET Loading @@ -59,33 +54,44 @@ declare %output:encoding("UTF-8") %rest:path( "/{$project}/{$page=[a-zA-Z0-9_]+}") function max:page($project, $page){ try{ switch($page) case "sommaire" return let $content := max.toc:getProjectTOC($project) return max.html:render($project, $page, $content) let $meta := max.config:getHtmlHeadTags($project, 'default', $page) return max.html:render($project, $page, $content, (), $meta) case "accueil" (:if 'accueil' frag does not exists -> display route list by default:) return try{ let $content := max.html:getHTMLFragment($project, $page) let $meta := max.config:getHtmlHeadTags($project, 'html', $page) let $contentWithFooter := <div> {$content} {max.html:getFooter($project)} </div> return max.html:render($project, $page, $contentWithFooter) return max.html:render($project, $page, $contentWithFooter, (), $meta) } catch *{ admin:write-log('Page/fragment "'||$page ||'" introuvable ou mal formé', 'INFO'), let $content := max.toc:getProjectTOC($project) return max.html:render($project, $page, $content) let $meta := max.config:getHtmlHeadTags($project, 'default', $page) return max.html:render($project, $page, $content, (), $meta) } default return try{ max.html:render($project, $page, max.html:getHTMLFragment($project,$page)) let $content := max.html:getHTMLFragment($project, $page) let $meta := max.config:getHtmlHeadTags($project, 'default', $page) return max.html:render($project, $page, $content, (), $meta) } catch err:FODC0002{ admin:write-log('Page/fragment "'||$page ||'" introuvable ou mal formé', 'INFO'), Loading @@ -94,6 +100,7 @@ function max:page($project, $page){ } catch err:config {max:max-error($err:description)} catch err:FODC0002 {<div>{$err:description} - {$err:module} - {$err:line-number}</div>} }; Loading @@ -104,7 +111,10 @@ declare %output:encoding("UTF-8") %rest:path("/{$project}/sommaire/{$doc=[^plugins].*\.xml|.*\.svg}") function max:documentTOC($project,$doc){ max.html:render($project, "sommaire", max.toc:getDocumentTOC($project, $doc)) let $content := max.toc:getDocumentTOC($project, $doc) let $meta := max.config:getHtmlHeadTags($project, 'xml', $doc) return max.html:render($project, "sommaire", $content, (), $meta) }; (:gets a project's XML fragment + a navigation bar(wrapped in an html skeleton):) Loading Loading @@ -134,7 +144,11 @@ function max:fragmentToHTMLPage($project, $routeDoc, $id){ return try{ let $html := xslt:transform($xml, $xsltDoc, $xsltParams) return max.html:render($project,$routeDoc, <div>{$html}</div>, $id) let $meta := max.config:getHtmlHeadTags($project, 'xml', $routeDoc, $id) return max.html:render($project, $routeDoc, <div>{$html}</div>, $id, $meta) } catch *{ admin:write-log('Error [' || $err:code || '/' || $err:module || '/' || $err:line-number ||']: ' || $err:description, 'ERROR'), Loading Loading @@ -313,7 +327,6 @@ declare "Max - ERROR: " || $desc }; declare %rest:GET %output:method("xml") Loading @@ -323,3 +336,4 @@ declare function max:buildSitemap($project){ max.html:getSitemap($project) };
plugins/search/search.xqm +4 −1 Changes for plugins/search/search.xqm: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ declare %rest:path("/{$project}/search") function max.plugin.search:searchPage($project){ let $routeList := for $d in collection( max.config:getProjectDBPath($project)) return base-uri($d) (:max.route:HTMLRouteList($project)//a/@href :) let $meta := max.config:getHtmlHeadTags($project, 'default', 'rechercher') let $routeSelect := <select id='searchSelect'>{ <option value='{$max.plugin.search:ALL_TXT}'>Dans tous les textes</option>, for $route in $routeList Loading Loading @@ -48,7 +49,9 @@ function max.plugin.search:searchPage($project){ </div> <div id='searchLoading'>{max.i18n:getText($project,'search.loading')}</div> <div id='searchResults'></div> </div>) </div>, (), $meta) }; declare Loading
rxq/config.xqm +52 Changes for rxq/config.xqm: 52 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -4,10 +4,14 @@ module namespace max.config = 'pddn/max/config'; import module namespace rest = "http://exquery.org/ns/restxq"; import module namespace max.cons = 'pddn/max/cons' at 'cons.xqm'; import module namespace max.util = 'pddn/max/util' at 'util.xqm'; import module namespace max.hht = 'pddn/max/hht' at 'hht.xqm'; (: CONFIGURATION file path. :) declare variable $max.config:CONFIGURATION_FILE := "../configuration/configuration.xml"; (: DEFAULT HTML HEAD TAGS file path. :) declare variable $max.config:DEFAULT_HTML_HEAD_TAGS := "../configuration/defaultHtmlHeadTags.xml"; (::) declare %private function max.config:checkConfiguration($projectId){ Loading Loading @@ -255,3 +259,51 @@ declare function max.config:getTextOptionsFragment($project){ string(doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$project]/textOptions/htmlFragment/@file) }; (: get project data from config file :) declare function max.config:getProjectData($project){ map:merge( for $data in doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$project]/projectData/data return map{$data/@key : data($data)} ) }; (: get default html head tags :) declare function max.config:getHtmlHeadTags( $project as xs:string +, $pageType as xs:string +, $pageName as xs:string *){ max.config:getHtmlHeadTags($project, $pageType, $pageName, '' ) }; (: get default html head tags :) declare function max.config:getHtmlHeadTags( $project as xs:string +, $pageType as xs:string +, $pageName as xs:string *, $id as xs:string *){ try{ let $defaultHtmlHeadTags := doc($max.config:DEFAULT_HTML_HEAD_TAGS)//defaultHtmlHeadTags return try{ switch($pageType) case 'default' return max.hht:getHtmlHeadTags_Page($project, 'base', $pageName, $defaultHtmlHeadTags) case 'html' return max.hht:getHtmlHeadTags_HTML($project, 'base', $pageName, $defaultHtmlHeadTags) case 'xml' return max.hht:getHtmlHeadTags_XML($project, $pageType, $pageName, $id, $defaultHtmlHeadTags) default return map{"error" : "Le type doit être 'default', 'html' ou 'xml'"} } catch *{ map{"error" : "Une erreur est survenue. (1)"} } } catch *{ map{"error" : "Une erreur est survenue. (2)"} } };
rxq/hht.xqm +180 Changes for rxq/hht.xqm: 180 added lines, 0 removed lines. Original line number Diff line number Diff line (: For conditions of distribution and use, see the accompanying legal.txt file. :) module namespace max.hht = 'pddn/max/hht'; import module namespace max.cons = 'pddn/max/cons' at 'cons.xqm'; import module namespace max.util = 'pddn/max/util' at 'util.xqm'; import module namespace max.config = 'pddn/max/config' at 'config.xqm'; import module namespace request = "http://exquery.org/ns/request"; declare namespace functx = "http://www.functx.com"; (: 1.1 get default html head tags for pages without fragment nor xml doc :) declare function max.hht:getHtmlHeadTags_Page($project, $pageType, $pageName, $defaultHtmlHeadTags){ map:merge(( max.hht:mapHtmlHeadTags( $project, $pageName, max.hht:edition($defaultHtmlHeadTags, $project, $pageType) ), max.hht:mapHtmlHeadTags( $project, $pageName, max.hht:base($defaultHtmlHeadTags, $pageType) ) )) }; (: 1.2 get default html head tags for HTML fragment :) declare function max.hht:getHtmlHeadTags_HTML($project, $pageType, $pageName, $defaultHtmlHeadTags){ let $fragment := doc(max.util:maxHome() || "/editions/" || $project || "/fragments/" || $pageName || ".frag.html") return max.hht:metaFromFragment($project, $defaultHtmlHeadTags, $pageType, $fragment, '') }; (: 1.3 get default html head tags for XML document :) declare function max.hht:getHtmlHeadTags_XML($project, $pageType, $pageName, $id as xs:string *, $defaultHtmlHeadTags){ let $env := max.config:getXMLFormat($project) let $fragment := ( if($env = 'tei') then ( collection(concat(max.config:getProjectDBPath($project), '/', $pageName))//*:TEI ) else if ($env = 'ead') then ( "" ) else( "" ) ) return max.hht:metaFromFragment($project, $defaultHtmlHeadTags, $env, $fragment, $id) }; (: 1.4 get default html head tags for XML and HTML :) declare function max.hht:metaFromFragment($project, $defaultHtmlHeadTags, $type, $fragment, $id as xs:string *){ map:merge(( max.hht:mapHtmlHeadTagsWithFragment( $project, $fragment, max.hht:edition($defaultHtmlHeadTags, $project, $type), $id), max.hht:mapHtmlHeadTagsWithFragment( $project, $fragment, max.hht:base($defaultHtmlHeadTags, $type), $id) )) }; (: 2.1 default / common tags :) declare function max.hht:base($defaultHtmlHeadTags, $pageType) { $defaultHtmlHeadTags/source[@type=$pageType] }; (: 2.2 tags for edition :) declare function max.hht:edition($defaultHtmlHeadTags, $project, $pageType) { (:$defaultHtmlHeadTags/editions/edition[@xml:id=$project]/source[@type=$pageType]/tag:) doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$project]/htmlHeadTags/source[@type=$pageType] }; (: 3.1 map html head meta tags :) declare function max.hht:mapHtmlHeadTags($project, $pageName, $path){ for $defaultTag in $path/tag let $position := count($defaultTag/preceding-sibling::*) let $valueTmp :=( if(contains($defaultTag/@key, "title") ) then(concat(upper-case(substring($pageName, 1, 1)), lower-case(substring($pageName, 2)))) else(string($defaultTag/@default)) ) return max.hht:mapEntry($project, $defaultTag, $valueTmp, $position) }; (: 3.2 map html head meta tags for fragments and xml doc :) declare function max.hht:mapHtmlHeadTagsWithFragment($project, $fragment, $path, $id as xs:string *){ for $defaultTag in $path/tag let $position := count($defaultTag/preceding-sibling::*) let $valueTmp := ( if($defaultTag/@path != "") then( let $xpath := replace($defaultTag/@path, '%id%', $id) return try{ if($defaultTag/@length != "" and $defaultTag/@length > 0) then( concat(substring(max.hht:evalXpath($xpath, $fragment), 0, $defaultTag/@length), '...') ) else( max.hht:evalXpath($xpath, $fragment) ) } catch *{} ) else("") ) let $valueTmp := ( if($valueTmp = '...') then("") else($valueTmp) ) let $valueTmp2 :=( if($defaultTag/@default != "" and $valueTmp = "" ) then(data($defaultTag/@default)) else($valueTmp) ) return max.hht:mapEntry($project, $defaultTag, $valueTmp2, $position) }; (: 4 functions :) declare function max.hht:evalXpath($xpath, $fragment){ string-join(xquery:eval($xpath, map { '' : $fragment }), " | ") }; declare function max.hht:mapEntry($project, $defaultTag, $tempValue, $position){ let $value := string(max.hht:setValue($project, $defaultTag, $tempValue)) return if(string($defaultTag/@key) = 'title') then(map:entry('title', max.hht:cleanValue($value) )) else( map{ string($defaultTag/@key): map{ "value":max.hht:cleanValue($value), "attribute":string($defaultTag/@attribute) } } ) }; declare function max.hht:setValue($project, $defaultTag, $tempValue){ if($defaultTag/@template != "") then(max.hht:htmlHeadTagsTemplate($project, string($defaultTag/@template), $tempValue) ) else($tempValue) }; declare function max.hht:cleanValue($value){ let $value := replace($value, '
', ' ') let $value := replace($value, '	', ' ') let $value := replace($value, '\s{2,}', ' ') return $value }; (: 5 html head tags template:) declare function max.hht:htmlHeadTagsTemplate($project, $template, $value){ let $scheme := request:scheme() let $port := request:port() let $hostname := request:hostname() let $path := request:path() let $url := ( if(fn:exists(string($port)) = xs:boolean(1)) then() else() ) let $projectName := max.config:getProjectPrettyName($project) let $return := $template let $return := replace($return, "%value%", $value) let $return := replace($return, "%project%", string($projectName)) let $return := replace($return, "%url%", $value || $url || $path ) let $return := replace($return, "%image%", $url || $value ) return $return };