Commit 194d085c authored by Guillaume Porte's avatar Guillaume Porte 😶
Browse files

modification du fonctionnement des métadonnées

parent 61603001
Loading
Loading
Loading
Loading
+36 −17
Changes for rxq/hht.xqm: 36 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ 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){
@@ -16,6 +18,7 @@ declare function max.hht:getHtmlHeadTags_Page($project, $pageType, $pageName, $d
      max.hht:mapHtmlHeadTags(
        $project, $pageName, max.hht:base($defaultHtmlHeadTags, $pageType) )
    ))

};

(: 1.2 get default html head tags for HTML fragment :)
@@ -49,33 +52,38 @@ declare function max.hht:metaFromFragment($project, $defaultHtmlHeadTags, $type,

(: 2.1 default / common tags  :)
declare function max.hht:base($defaultHtmlHeadTags, $pageType) {
  $defaultHtmlHeadTags/common/source[@type=$pageType]/tag
  $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
  (:$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){
  map:merge(

    for $defaultTag in $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)
  )
    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 *){
  map:merge(

    for $defaultTag in $path

    for $defaultTag in $path/tag
    let $position := count($defaultTag/preceding-sibling::*)

      let $valueTmp := (
        if($defaultTag/@path != "")
        then(
@@ -102,8 +110,9 @@ declare function max.hht:mapHtmlHeadTagsWithFragment($project, $fragment, $path,
        else($valueTmp)
      )

      return max.hht:mapEntry($project, $defaultTag, $valueTmp2)
  )
      return max.hht:mapEntry($project, $defaultTag, $valueTmp2, $position)


};

(: 4 functions :)
@@ -111,14 +120,23 @@ declare function max.hht:evalXpath($xpath, $fragment){
  string-join(xquery:eval($xpath, map { '' : $fragment }), " | ")
};

declare function max.hht:mapEntry($project, $defaultTag, $tempValue){
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:entry(string($defaultTag/@key), 
      map{"value" : 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){
@@ -144,18 +162,19 @@ declare function max.hht:htmlHeadTagsTemplate($project, $template, $value){

  let $url := (
    if(fn:exists(string($port)) = xs:boolean(1))
    then(concat($hostname, ":", string($port)))
    else(concat('', $hostname))
    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%", $url || $path )
  let $return := replace($return, "%url%", $value || $url || $path )
  let $return := replace($return, "%image%", $url || $value )

  return 
    $return

};