Commit 22ca327c authored by Guillaume Porte's avatar Guillaume Porte 😶
Browse files

mise en place des métadonnées dans le <head>

parent b949e9cb
Loading
Loading
Loading
Loading
+81 −10
Changes for rxq/html.xqm: 81 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -16,7 +16,15 @@ declare function max.html:render(
  $projectId as xs:string,
  $pageId as xs:string,
  $wrapped as element()+)
  as element(html) {max.html:render($projectId, $pageId, $wrapped, ())};
  as element(html) {max.html:render($projectId, $pageId, $wrapped, (), ())};


declare function max.html:render(
  $projectId as xs:string,
  $pageId as xs:string,
  $wrapped as element()+,
  $fragmentId as xs:string ?
) as element(html) {max.html:render($projectId, $pageId, $wrapped, (), ())};

(:
 : Wraps fragment identified div in HTML template.
@@ -26,10 +34,11 @@ declare function max.html:render(
  $projectId as xs:string,
  $pageId as xs:string,
  $wrapped as element()+,
  $fragmentId as xs:string ?
  $fragmentId as xs:string ?,
  $meta as map(*)*
) as element(html) {

    let $head:=  max.html:generateHTMLHead($projectId)
    let $head:=  max.html:generateHTMLHead($projectId, $meta)
    let $jsImports := max.html:generateAllJSImports($projectId, $pageId, $fragmentId)
    let $baseuri := max.config:getBaseURI()
    let $aboutHref := $baseuri || "/about"
@@ -44,7 +53,8 @@ declare function max.html:render(
                                      'menu': $menu,
                                      'head': $head,
                                      'content' : $wrapped,
                                      'jsImports': $jsImports                                 
                                      'jsImports': $jsImports,
                                      'data' : max.config:getProjectData($projectId)                            
                                  }) 
        }
      catch err:FODC0002{
@@ -65,7 +75,7 @@ declare function max.html:wrapInSimpleHTML(
  $wrapped as element()+)
  as element(html) {
    
    let $head:=  max.html:generateHTMLHead($projectId)    
    let $head:=  max.html:generateHTMLHead($projectId, ())    
    let $jsImports := max.html:generateAllJSImports($projectId, "","")
    
    return <html>{$head}<body>{$wrapped}{$jsImports}</body></html>
@@ -73,15 +83,15 @@ declare function max.html:wrapInSimpleHTML(
}; 
  
  
declare %private function max.html:generateHTMLHead($projectId){
declare %private function max.html:generateHTMLHead($projectId, $meta as map(*)*){

  <head>
    <meta charset="utf-8"/>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content=""/>
    <meta name="author" content=""/>
    <title>PDDN MaX / {$projectId}</title>
    <!-- other head content -->
    {max.html:setHtmlHeadTags($projectId, $meta)}
    <!-- Bootstrap core & theme CSS -->
    <link rel="stylesheet" 
     href="{max.config:getBaseURI() || $projectId || '/core/ui/lib/bootstrap.min.css'}"/>                    
@@ -397,8 +407,69 @@ declare function max.html:renderTemplate($htmlDoc as document-node(), $map as ma
                     return "declare variable $" || $var || " external;")
 return  xquery:eval($declarations || serialize($htmlDoc),  $map)     
 
};



(: 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 (
      max.html:getHtmlTitle($project, $meta, $activeHtmlHeadTags),
      max.html:getHtmlMetas($project, $meta, $activeHtmlHeadTags),
      max.html:getHtmlLink($project, $meta, $activeHtmlHeadTags)
      (:,<test>{json:serialize($meta)}</test>:)
      )
};

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

    return
        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

    return (
      if( fn:empty($meta) = xs:boolean(0) 
        and fn:exists($meta($key)) = xs:boolean(1)
        and fn:exists($meta($key)('value')) = xs:boolean(1)
        and $meta($key)('value') != "")
      then(
        if($tag/@attribute = 'property')
        then(<meta property="{$key}" content="{$meta($key)('value')}"/>)
        else if($tag/@attribute = 'name')
        then(<meta name="{$key}" content="{$meta($key)('value')}"/>)
        else()
      )
      else()
    )
  };

(: 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

    return (
      if( fn:empty($meta) = xs:boolean(0) 
        and fn:exists($meta($key)) = xs:boolean(1)
        and fn:exists($meta($key)('value')) = xs:boolean(1)
        and $meta($key)('value') != "")
      then(
        if($tag/@attribute = 'rel')
        then(<link rel="{$key}" href="{$meta($key)('value')}"/>)
        else()
      )
      else()
    )
  };