Commit a8f4bd17 authored by Guillaume Porte's avatar Guillaume Porte 😶
Browse files

modification de l'appel et de la création des tags html (metadonnées)

parent 194d085c
Loading
Loading
Loading
Loading
+73 −17
Changes for rxq/html.xqm: 73 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -411,31 +411,52 @@ declare function max.html:renderTemplate($htmlDoc as document-node(), $map as ma




(: html head tags :)
declare function max.html:setHtmlHeadTags( $project, $meta as map(*)* ){
    let $activeHtmlHeadTags := doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$project]/htmlHeadTags

    return
    try{
      (:tri des balises metas:)
      let $keys:= 
        <metas>{
          map:for-each($meta, 
            function($k, $v){ 
              if($k != 'title')
              then(<key>{$k}</key>)
              else()
            }
          )
        }</metas>

      let $order := 
        for $key in $keys/key
        order by $key
        return $key


      return (
      max.html:getHtmlTitle($project, $meta, $activeHtmlHeadTags),
      max.html:getHtmlMetas($project, $meta, $activeHtmlHeadTags),
      max.html:getHtmlLink($project, $meta, $activeHtmlHeadTags)
      (:,<test>{json:serialize($meta)}</test>:)
        max.html:getHtmlTitle($project, $meta, $order),
        max.html:getHtmlMetas($project, $meta, $order),
        max.html:getHtmlLink($project, $meta, $order)
        (:,<test2>{json:serialize($meta)}</test2>:)
        )
    }
    catch *{}

};

(: html head tags : title :)
declare function max.html:getHtmlTitle($project, $meta as map(*)*, $activeHtmlHeadTags ){
    for $tag in $activeHtmlHeadTags//*:tag[@element = "title"]

    return
declare function max.html:getHtmlTitle($project, $meta as map(*)*, $order ){
    if(fn:exists($meta) = xs:boolean(1) and fn:exists($meta('title')) = xs:boolean(1))
    then(<title>{$meta('title')}</title>)
    else("")
};

(: html head tags : metas :)
declare function max.html:getHtmlMetas( $project, $meta as map(*)*, $activeHtmlHeadTags ){ 
  for $tag in $activeHtmlHeadTags//*:tag[@element = "meta"]
  let $key := $tag/@key
declare function max.html:getHtmlMetas( $project, $meta as map(*)*, $order ){ 
  for $key in $order

    return (
      if( fn:empty($meta) = xs:boolean(0) 
@@ -443,9 +464,9 @@ declare function max.html:getHtmlMetas( $project, $meta as map(*)*, $activeHtmlH
        and fn:exists($meta($key)('value')) = xs:boolean(1)
        and $meta($key)('value') != "")
      then(
        if($tag/@attribute = 'property')
        if($meta($key)('attribute') = 'property')
        then(<meta property="{$key}" content="{$meta($key)('value')}"/>)
        else if($tag/@attribute = 'name')
        else if($meta($key)('attribute') = 'name')
        then(<meta name="{$key}" content="{$meta($key)('value')}"/>)
        else()
      )
@@ -454,9 +475,8 @@ declare function max.html:getHtmlMetas( $project, $meta as map(*)*, $activeHtmlH
};

(: html head tags : link (favicon) :)
declare function max.html:getHtmlLink($project, $meta as map(*)*, $activeHtmlHeadTags ){
  for $tag in $activeHtmlHeadTags//*:tag[@element = "link"]
  let  $key := $tag/@key
declare function max.html:getHtmlLink($project, $meta as map(*)*, $order ){
  for $key in $order

    return (
      if( fn:empty($meta) = xs:boolean(0) 
@@ -464,7 +484,7 @@ declare function max.html:getHtmlLink($project, $meta as map(*)*, $activeHtmlHea
        and fn:exists($meta($key)('value')) = xs:boolean(1)
        and $meta($key)('value') != "")
      then(
        if($tag/@attribute = 'rel')
        if($meta($key)('attribute') = 'rel')
        then(<link rel="{$key}" href="{$meta($key)('value')}"/>)
        else()
      )
@@ -473,3 +493,39 @@ declare function max.html:getHtmlLink($project, $meta as map(*)*, $activeHtmlHea
  };


declare function max.html:getSitemap($project){

  let $baseUri := replace(request:uri(), concat($project, '/sitemap.xml'), '')
  return

   <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    
    {
      (: pages éditoriales :)
      for $entry in doc("../editions/" || $project || "/" || $max.cons:MENU_FILE)//*:entry[@type="main"]
        return 
          <url>
            <loc>{$baseUri}{$project}/{string($entry/*:target)}</loc>
          </url>
    }
    
    {
      (: pages xml :)
      let $docs := db:list(  max.config:getProjectDBPath($project)  )
      for $doc in $docs
        let $toc := max.toc:getDocumentTOC($project, $doc)
        let $urls := $toc//*:ul[@id="routeEntries"]/*:li/*:a
        for $url in $urls
          let $url := substring($url/@href, 2)
          return
            <url>
              <loc>{$baseUri}{$url}</loc>
            </url>

    }
    </urlset> 

};