new version of the template

This commit is contained in:
Francesco Mangiacrapa 2024-06-24 14:16:03 +02:00
parent 53a60b110e
commit 987dc4f378
1 changed files with 30 additions and 12 deletions

View File

@ -6,15 +6,29 @@
<#assign tags=[]>
<#assign extras=[]>
<#function sanitizeString(value)>
<#if value??>
<#return value?trim?replace('\n','')?replace('\"','')>
</#if>
<#return "">
</#function>
<#function onlyAlphanumericString(value)>
<#if value??>
<#return value?trim?replace('\n','')?replace('\"','')?replace("[^\\w]+", "-", "r")>
</#if>
<#return "">
</#function>
<#-- Macro to assign Tags -->
<#macro assignTag in_tags>
<#if in_tags??>
<#if in_tags?is_sequence>
<#list in_tags as my_tag>
<#assign tags = tags + [my_tag] />
<#assign tags = tags + [onlyAlphanumericString(my_tag)] />
</#list>
<#else>
<#assign tags = tags + [in_tags] />
<#assign tags = tags + [onlyAlphanumericString(in_tags)] />
</#if>
</#if>
</#macro>
@ -26,7 +40,7 @@
<#assign description = ""/>
</#if>
<#if url??>
<#assign resource = {"name": name, "url": url, "description": description, "format": format}>
<#assign resource = {"name": name, "url": url, "description": sanitizeString(description), "format": format}>
<#assign resources = resources + [resource]/>
</#if>
</#macro>
@ -47,7 +61,11 @@
<#-- Macro to assign Extras field -->
<#macro assignExtraField key value asObject>
<#if key??>
<#assign extra = {"key": key, "value": value, "asObject": asObject}>
<#assign checkedValue = value/>
<#if key != "spatial">
<#assign checkedValue = sanitizeString(value)/>
</#if>
<#assign extra = {"key": sanitizeString(key), "value": checkedValue, "asObject": asObject}>
<#assign extras = extras + [extra]/>
</#if>
</#macro>
@ -120,17 +138,17 @@
</#macro>
<#--
Starting document mapping to Catalogue
-->
<#compress>
{
"name": "${jsonProj._id}",
"title": "${theDocument.nome}",
"license_id": "CC-BY-SA-4.0",
"private": false,
<#assign description = theDocument.introduzione?trim />
<#assign sanitizedNotes = description?replace("\\n", "")>
<#assign sanitizedNotes = sanitizeString(theDocument.introduzione) />
"notes": "${sanitizedNotes}",
<#--
@ -263,10 +281,10 @@ Starting document mapping to Catalogue
<#if theDocument.contestoIndagine??>
<#if theDocument.contestoIndagine?is_sequence>
<#list theDocument.contestoIndagine as my_extra>
<@assignExtraField key="Definizione del contesto d'indagine" value=my_extra asObject=false></@assignExtraField>
<@assignExtraField key="Contesto Indagine" value=my_extra asObject=false></@assignExtraField>
</#list>
<#else>
<@assignExtraField key="Definizione del contesto d'indagine" value=theDocument.contestoIndagine asObject=false></@assignExtraField>
<@assignExtraField key="Contesto Indagine" value=theDocument.contestoIndagine asObject=false></@assignExtraField>
</#if>
</#if>
@ -281,10 +299,10 @@ Starting document mapping to Catalogue
<#if theDocument.cronologiaMacrofase??>
<#if theDocument.cronologiaMacrofase?is_sequence>
<#list theDocument.cronologiaMacrofase as my_extra>
<@assignExtraField key="Cronologia (Macrofase)" value=my_extra asObject=false></@assignExtraField>
<@assignExtraField key="Cronologia Macrofase" value=my_extra asObject=false></@assignExtraField>
</#list>
<#else>
<@assignExtraField key="Cronologia (Macrofase)" value=theDocument.cronologiaMacrofase asObject=false></@assignExtraField>
<@assignExtraField key="Cronologia Macrofase" value=theDocument.cronologiaMacrofase asObject=false></@assignExtraField>
</#if>
</#if>
@ -304,4 +322,4 @@ Starting document mapping to Catalogue
<@buildExtrasFields the_extras=extras></@buildExtrasFields>
}
</#compress>