Skip to content

Instantly share code, notes, and snippets.

@hampusn
Created April 3, 2019 11:01
Show Gist options
  • Save hampusn/7672a8b3f5e288af96b8bbc327fb872e to your computer and use it in GitHub Desktop.
Save hampusn/7672a8b3f5e288af96b8bbc327fb872e to your computer and use it in GitHub Desktop.
Söklistning: Standardmall med "skapad av"
##
## Utility API
#set ($outputUtil = $sitevisionUtils.outputUtil)
#set ($portletContextUtil = $sitevisionUtils.portletContextUtil)
#set ($resourceLocatorUtil = $sitevisionUtils.resourceLocatorUtil)
#set ($scriptUtil = $sitevisionUtils.scriptUtil)
#set ($docTypeUtil = $sitevisionUtils.docTypeUtil)
##
## Portlet properties
#set ($headingNode = $propertyUtil.getNode($portlet, 'searchHitHeadingFont'))
#set ($headingClass = $propertyUtil.getString($headingNode, 'selectorText'))
#set ($excerptClass = $propertyUtil.getNestedString($portlet, 'searchHitExcerptFont', 'selectorText'))
#set ($infoClass = $propertyUtil.getNestedString($portlet, 'searchHitInfoFont', 'selectorText'))
#set ($excerptLength = $propertyUtil.getInt($portlet, 'searchHitExcerptLength', 250))
#set ($showSearchHitExcerpt = $propertyUtil.getBoolean($portlet, 'showSearchHitExcerpt'))
#set ($showSearchHitInfo = $propertyUtil.getBoolean($portlet, 'showSearchHitInfo'))
#set ($showSearchHitPath = $propertyUtil.getBoolean($portlet, 'showSearchHitPath'))
#set ($displayHitNumbering = $propertyUtil.getBoolean($portlet, 'showSearchHitNumbering', false))
#set ($headingField = $propertyUtil.getString($portlet, 'headingField'))
##
## Index field names
#set ($displayField = $propertyUtil.getString($portlet, $headingField))
#set ($urlField = $propertyUtil.getString($portlet, 'urlField'))
#set ($uriField = $propertyUtil.getString($portlet, 'uriField'))
#set ($siteField = $propertyUtil.getString($portlet, 'siteField'))
#set ($summaryField = $propertyUtil.getString($portlet, 'summaryField'))
#set ($lastUpdatedField = $propertyUtil.getString($portlet, 'lastPublishedField'))
#set ($sizeField = $propertyUtil.getString($portlet, 'sizeField'))
#set ($mimtypeField = $propertyUtil.getString($portlet, 'mimetypeField'))
#set ($thisSiteId = $resourceLocatorUtil.site.identifier)
#if ($thisSiteId.endsWith("_site"))
#set ($idEnd = $thisSiteId.length() - 5)
#set ($thisSiteId = $thisSiteId.substring(0, $idEnd))
#end
## Init background coloring and left padding for list item
#if ($propertyUtil.getBoolean($portlet, 'useSearchHitBackgroundColor'))
#set ($colorNode = $propertyUtil.getNode($portlet, 'searchHitBackgroundColor'))
#set ($flipColors = "true")
#set ($oddColor = "; background-color:${propertyUtil.getString($colorNode, 'htmlHexValue')}")
#set ($bgColor = $oddColor)
#set ($itemLeftPadding = '0.5em')
#else
#set ($bgColor = '')
#set ($itemLeftPadding = '0')
#end
## Init link+icon renderers and counter class
#set ($linkRenderer = $sitevisionUtils.linkRenderer)
#set ($linkRendererClass = $headingClass)
#set ($counterClass = $headingClass)
#set ($renderIcons = $propertyUtil.getBoolean($portlet, 'showFileIcons', false))
#if ($renderIcons)
#set ($iconRenderer = $sitevisionUtils.fileIconRenderer)
$iconRenderer.clearUseSmallIcons()
#set ($renderIcons = $iconRenderer.loadDefaultIconByFileExtension('default'))
#if ($renderIcons)
$iconRenderer.setFontClass('sv-noborder-vamiddle')
$linkRenderer.clearUseResourceDecorationSettings()
#set ($linkRendererClass = $linkRendererClass + ' sv-vamiddle')
#set ($counterClass = $counterClass + ' sv-vamiddle')
#end
#end
$linkRenderer.setFontClass($linkRendererClass)
#set ($datePattern = $scriptUtil.getFormatPattern(${portletContextUtil.currentLocale}))
#set ($itemSpacing = '0.5em')
#set ($startIsValid = !$docTypeUtil.isXhtmlStrict())
<ol#if($startIsValid) start="1"#end class="sv-search-result sv-defaultlist-noleft">
#foreach ($hit in $searchResult.hits)
<li class="sv-search-hit sv-corner-all" style="margin-left:0; padding-left:${itemLeftPadding}; padding-top:0.5em; padding-bottom:0.5em${bgColor}">
##
## Heading
#set ($hitHeading = $scriptUtil.getNonNull($hit.getField($displayField)))
#if ($hitHeading)
<div class="sv-notopmargin">
#set ($target = $scriptUtil.getNonNull($hit.getField($urlField)))
#if ($target)
#if ($thisSiteId == $hit.getField($siteField))
#set ($target = $scriptUtil.getNonNull($hit.getField($uriField), $target))
#end
$linkRenderer.setStringTarget($target)
$linkRenderer.setText($hitHeading)
#if ($renderIcons)
$scriptUtil.swallow($iconRenderer.loadIconByContentType($hit.getField($mimtypeField)))
$iconRenderer.render()
#end
#if ($displayHitNumbering)
<span class="$counterClass">${velocityCount}.</span>
#end
$linkRenderer.render()
#else
#if ($displayHitNumbering)
<span class="$counterClass">${velocityCount}.</span>
#end
$outputUtil.getEscapedHtmlText($hitHeading, $headingNode)
#end
</div>
#end
#if ($showSearchHitExcerpt)
##
## Summary is never highlighted, we just use getHighlightedField to get value properly encoded and truncated...
#set ($summaryFieldValue = $scriptUtil.getNonNull(${hit.getHighlightedField($summaryField, $excerptLength)}))
#if ($summaryFieldValue)
<p class="$excerptClass" style="margin-top:${itemSpacing}">$summaryFieldValue</p>
#end
#end
#set ($infoText = '')
#if ($showSearchHitInfo)
#if ($hit.getDateField($lastUpdatedField))
#set ($modifiedDate = $hit.getDateField($lastUpdatedField))
#if ($lastModifiedText)
## Do nothing, modified text already extracted!
#else
#set ($lastModifiedText = $propertyUtil.getNestedString($portlet, 'bundle', 'lastModifiedText'))
#end
#set ($infoText = $lastModifiedText + ' ' + $scriptUtil.getDateAsString($datePattern, $modifiedDate))
#end
#if ($hit.getLongField($sizeField))
#set ($longSize = $hit.getLongField($sizeField))
#set ($humanSize = $scriptUtil.getHumanPresentableSize($longSize))
#if ($sizeText)
## Do nothing, size text already extracted!
#else
#set ($sizeText = $propertyUtil.getNestedString($portlet, 'bundle', 'sizeText'))
#end
#if ($infoText != '')
#set ($infoText = $infoText + ' &bull; ' + $sizeText + ' ' + $humanSize)
#else
#set ($infoText = $sizeText + ' ' + $humanSize)
#end
#end
#end
#set ($createdBy = $hit.getFieldEscaped('createdby', ''))
#if ($createdBy != '')
#if ($infoText != '')
#set ($infoText = $infoText + ' &bull; Skapad av: ' + $createdBy)
#else
#set ($infoText = 'Skapad av: ' + $createdBy)
#end
#end
#set ($pathText = '')
#if ($showSearchHitPath)
#if ($hit.node)
#if ($pathLinkRenderer)
## Do nothing, renderer and path class already created!
#else
#set ($pathLinkRenderer = $sitevisionUtils.linkRenderer)
$pathLinkRenderer.forceUseCrossSiteTargetChecking()
$pathLinkRenderer.clearUseLinkDecorationSettings()
#set ($pathClass = $propertyUtil.getNestedString($portlet, 'searchHitPathFont', 'selectorText'))
#end
#set ($pathText = $outputUtil.renderWebPathNodes($hit.node, $pathLinkRenderer, ' / '))
#end
#end
#if ($infoText != '' && $pathText != '')
<div style="margin-top:${itemSpacing}">
<span class="$infoClass">$infoText</span><br />
<span class="$pathClass">$pathText</span>
</div>
#elseif ($infoText != '')
<p class="$infoClass" style="margin-top:${itemSpacing}">$infoText</p>
#elseif ($pathText != '')
<p class="$pathClass" style="margin-top:${itemSpacing}">$pathText</p>
#end
</li>
#if ($flipColors)
#if ($bgColor == '')
#set ($bgColor = $oddColor)
#else
#set ($bgColor = '')
#end
#end
#end
</ol>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment