如何使用 Mirage2 为主题在侧边栏中应用徽章
How to apply badges in the sidebar counts using Mirage2 as theme
我想将徽章应用到在边栏方面找到的数字。
来自:
为此:
我似乎找不到要编辑的正确文件。我试图在第 248 行和第 260 行编辑 SidebarFacetsTransformer.java
:
if (i < shownFacets - 1) {
String displayedValue = value.getDisplayedValue();
String filterQuery = value.getAsFilterQuery();
String filterType = value.getFilterType();
if (fqs.contains(getSearchService().toFilterQuery(context, field.getIndexFieldName(), value.getFilterType(), value.getAsFilterQuery()).getFilterQuery())) {
filterValsList.addItem(Math.random() + "", "selected").addContent(displayedValue + " <span class=\"badge\">" + value.getCount() + "</span>");
} else {
String paramsQuery = retrieveParameters(request);
filterValsList.addItem().addXref(
contextPath +
(dso == null ? "" : "/handle/" + dso.getHandle()) +
"/discover?" +
paramsQuery +
"filtertype=" + field.getIndexFieldName() +
"&filter_relational_operator="+ filterType +
"&filter=" + encodeForURL(filterQuery),
displayedValue + " <span class=\"badge\">" + value.getCount() + "</span>"
);
}
}
但重建DSpace后,标签<span class="badge">
也显示出来了:
那么我应该编辑什么文件来将徽章应用于侧边栏计数?我见过一个存储库使用 Mirage2 作为其基本主题并在侧边栏中应用徽章计数:University of Waikato Research Commons.
提前致谢!
更新
应用@schweerelos 回答中的代码后,我得到了想要的结果,除了有文件 的侧边栏。而不是数字,它只是显示 No.
此时,我认为您只需要设置 span.badge 元素的样式。
查看怀卡托大学公共研究中心,我看到以下 CSS。
list-group-item>.badge {
float: right;
}
.badge {
display: inline-block;
min-width: 10px;
padding: 3px 7px;
font-size: 12px;
font-weight: bold;
color: #fff;
line-height: 1;
vertical-align: baseline;
white-space: nowrap;
text-align: center;
background-color: #777;
border-radius: 10px;
}
对于Research Commons徽章,我们修改了dspace-xmlui-mirage2/src/main/webapp/xsl/preprocess.xsl
,截取了对应元素的渲染,即
<!-- render frequency counts in sidebar facets as badges -->
<xsl:template match="dri:list[@id='aspect.discovery.Navigation.list.discovery']/dri:list/dri:item/dri:xref">
<xref>
<xsl:call-template name="copy-attributes"/>
<xsl:choose>
<xsl:when test="contains(text(), ' (') and contains(substring-after(text(), ' ('), ')')">
<xsl:variable name="title">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string" select="text()"/>
<xsl:with-param name="separator"><xsl:text> (</xsl:text></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="count">
<xsl:call-template name="remove-parens">
<xsl:with-param name="string" select="normalize-space(substring-after(text(), $title))"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$title"/>
<xsl:text> </xsl:text>
<hi rend="badge">
<xsl:value-of select="$count"/>
</hi>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xref>
</xsl:template>
以及当前选定构面值的类似模板(IIRC 不是 link):
<!-- better highlight active co-author/subject etc in facet list, incl show count as badge -->
<xsl:template match="dri:list[@id='aspect.discovery.Navigation.list.discovery']/dri:list/dri:item[@rend='selected']">
<item>
<xsl:call-template name="copy-attributes"/>
<xsl:attribute name="rend"><xsl:value-of select="@rend"/> disabled</xsl:attribute>
<xsl:choose>
<xsl:when test="contains(text(), ' (') and contains(substring-after(text(), ' ('), ')')">
<xsl:variable name="title">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string" select="text()"/>
<xsl:with-param name="separator"><xsl:text> (</xsl:text></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="count">
<xsl:call-template name="remove-parens">
<xsl:with-param name="string" select="normalize-space(substring-after(text(), $title))"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$title"/>
<xsl:text> </xsl:text>
<hi rend="badge">
<xsl:value-of select="$count"/>
</hi>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</item>
</xsl:template>
您会看到有一些 XSL/T 技巧涉及到处理方面值本身包含括号的情况,有几个实用程序模板:
<xsl:template name="substring-before-last">
<xsl:param name="string" select="''" />
<xsl:param name="separator" select="''" />
<xsl:if test="$string != '' and $separator != ''">
<xsl:variable name="head" select="substring-before($string, $separator)" />
<xsl:variable name="tail" select="substring-after($string, $separator)" />
<xsl:value-of select="$head" />
<xsl:if test="contains($tail, $separator)">
<xsl:value-of select="$separator" />
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string" select="$tail" />
<xsl:with-param name="separator" select="$separator" />
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template name="remove-parens">
<xsl:param name="string" select="''" />
<xsl:if test="starts-with($string, '(') and substring($string, string-length($string))=')'">
<xsl:value-of select="substring($string, 2, string-length($string) - 2)"/>
</xsl:if>
</xsl:template>
只需添加一个注释,我们在本地偏好修改主题 XSL 文件而不是修改 Java 代码。作为替代方案,您可以在 Java 代码中执行此操作,但您需要在 DRI API 中工作,例如 make .addHighlight("badge")
Java 方法调用与 addXref
(DRI hi
转换为 HTML span
)。请参阅 https://wiki.duraspace.org/display/DSDOC5x/DRI+Schema+Reference 的 DRI 文档(对于 5.x 但对于 6.x 没有改变)。
Cocoon 管道是 Java 产生 DRI (XML) -> preprocess.xsl 和相关文件修改 DRI,输出仍然是 DRI -> theme.xsl 和相关文件将 DRI 转换为 HTML。您正在尝试在管道中创建 HTML "too early"。您的原始 HTML 被转义到更远的轨道,这就是您在屏幕上看到标签的原因。
感谢@schweerelos 的回答,我设法应用她的代码并进行一些修改以解决 DSpace 版本中引入的 Has Files(s) facet 中的问题6.x.
我在 utils.xsl
中取消注释这段代码:
<xsl:template match="//dri:list[@id='aspect.discovery.SidebarFacetsTransformer.list.has_content_in_original_bundle']/dri:item//text()">
<xsl:choose>
<xsl:when test="contains(.,'true')">
<i18n:text>xmlui.ArtifactBrowser.AdvancedSearch.value_has_content_in_original_bundle_true</i18n:text>
</xsl:when>
<xsl:otherwise>
<i18n:text>xmlui.ArtifactBrowser.AdvancedSearch.value_has_content_in_original_bundle_false</i18n:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:value-of select="substring-after(.,' ')"/>
</xsl:template>
然后我修改了 Andrea 的代码以显示 No 或 Yes 用于具有原始包的记录:
<!-- render frequency counts in sidebar facets as badges -->
<xsl:template match="dri:list[@id='aspect.discovery.Navigation.list.discovery']/dri:list/dri:item/dri:xref" priority="9">
<xref>
<xsl:call-template name="copy-attributes"/>
<xsl:choose>
<xsl:when test="contains(text(), ' (') and contains(substring-after(text(), ' ('), ')')">
<xsl:variable name="title">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string" select="text()"/>
<xsl:with-param name="separator"><xsl:text> (</xsl:text></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="count">
<xsl:call-template name="remove-parens">
<xsl:with-param name="string" select="normalize-space(substring-after(text(), $title))"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(.,'true')">
<i18n:text>xmlui.ArtifactBrowser.AdvancedSearch.value_has_content_in_original_bundle_true</i18n:text>
</xsl:when>
<xsl:when test="contains(.,'false')">
<i18n:text>xmlui.ArtifactBrowser.AdvancedSearch.value_has_content_in_original_bundle_false</i18n:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$title"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<hi rend="badge">
<xsl:value-of select="$count"/>
</hi>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xref>
</xsl:template>
现在显示我想要的输出:
我想将徽章应用到在边栏方面找到的数字。
来自:
为此:
我似乎找不到要编辑的正确文件。我试图在第 248 行和第 260 行编辑 SidebarFacetsTransformer.java
:
if (i < shownFacets - 1) {
String displayedValue = value.getDisplayedValue();
String filterQuery = value.getAsFilterQuery();
String filterType = value.getFilterType();
if (fqs.contains(getSearchService().toFilterQuery(context, field.getIndexFieldName(), value.getFilterType(), value.getAsFilterQuery()).getFilterQuery())) {
filterValsList.addItem(Math.random() + "", "selected").addContent(displayedValue + " <span class=\"badge\">" + value.getCount() + "</span>");
} else {
String paramsQuery = retrieveParameters(request);
filterValsList.addItem().addXref(
contextPath +
(dso == null ? "" : "/handle/" + dso.getHandle()) +
"/discover?" +
paramsQuery +
"filtertype=" + field.getIndexFieldName() +
"&filter_relational_operator="+ filterType +
"&filter=" + encodeForURL(filterQuery),
displayedValue + " <span class=\"badge\">" + value.getCount() + "</span>"
);
}
}
但重建DSpace后,标签<span class="badge">
也显示出来了:
那么我应该编辑什么文件来将徽章应用于侧边栏计数?我见过一个存储库使用 Mirage2 作为其基本主题并在侧边栏中应用徽章计数:University of Waikato Research Commons.
提前致谢!
更新
应用@schweerelos 回答中的代码后,我得到了想要的结果,除了有文件 的侧边栏。而不是数字,它只是显示 No.
此时,我认为您只需要设置 span.badge 元素的样式。
查看怀卡托大学公共研究中心,我看到以下 CSS。
list-group-item>.badge {
float: right;
}
.badge {
display: inline-block;
min-width: 10px;
padding: 3px 7px;
font-size: 12px;
font-weight: bold;
color: #fff;
line-height: 1;
vertical-align: baseline;
white-space: nowrap;
text-align: center;
background-color: #777;
border-radius: 10px;
}
对于Research Commons徽章,我们修改了dspace-xmlui-mirage2/src/main/webapp/xsl/preprocess.xsl
,截取了对应元素的渲染,即
<!-- render frequency counts in sidebar facets as badges -->
<xsl:template match="dri:list[@id='aspect.discovery.Navigation.list.discovery']/dri:list/dri:item/dri:xref">
<xref>
<xsl:call-template name="copy-attributes"/>
<xsl:choose>
<xsl:when test="contains(text(), ' (') and contains(substring-after(text(), ' ('), ')')">
<xsl:variable name="title">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string" select="text()"/>
<xsl:with-param name="separator"><xsl:text> (</xsl:text></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="count">
<xsl:call-template name="remove-parens">
<xsl:with-param name="string" select="normalize-space(substring-after(text(), $title))"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$title"/>
<xsl:text> </xsl:text>
<hi rend="badge">
<xsl:value-of select="$count"/>
</hi>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xref>
</xsl:template>
以及当前选定构面值的类似模板(IIRC 不是 link):
<!-- better highlight active co-author/subject etc in facet list, incl show count as badge -->
<xsl:template match="dri:list[@id='aspect.discovery.Navigation.list.discovery']/dri:list/dri:item[@rend='selected']">
<item>
<xsl:call-template name="copy-attributes"/>
<xsl:attribute name="rend"><xsl:value-of select="@rend"/> disabled</xsl:attribute>
<xsl:choose>
<xsl:when test="contains(text(), ' (') and contains(substring-after(text(), ' ('), ')')">
<xsl:variable name="title">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string" select="text()"/>
<xsl:with-param name="separator"><xsl:text> (</xsl:text></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="count">
<xsl:call-template name="remove-parens">
<xsl:with-param name="string" select="normalize-space(substring-after(text(), $title))"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$title"/>
<xsl:text> </xsl:text>
<hi rend="badge">
<xsl:value-of select="$count"/>
</hi>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</item>
</xsl:template>
您会看到有一些 XSL/T 技巧涉及到处理方面值本身包含括号的情况,有几个实用程序模板:
<xsl:template name="substring-before-last">
<xsl:param name="string" select="''" />
<xsl:param name="separator" select="''" />
<xsl:if test="$string != '' and $separator != ''">
<xsl:variable name="head" select="substring-before($string, $separator)" />
<xsl:variable name="tail" select="substring-after($string, $separator)" />
<xsl:value-of select="$head" />
<xsl:if test="contains($tail, $separator)">
<xsl:value-of select="$separator" />
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string" select="$tail" />
<xsl:with-param name="separator" select="$separator" />
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template name="remove-parens">
<xsl:param name="string" select="''" />
<xsl:if test="starts-with($string, '(') and substring($string, string-length($string))=')'">
<xsl:value-of select="substring($string, 2, string-length($string) - 2)"/>
</xsl:if>
</xsl:template>
只需添加一个注释,我们在本地偏好修改主题 XSL 文件而不是修改 Java 代码。作为替代方案,您可以在 Java 代码中执行此操作,但您需要在 DRI API 中工作,例如 make .addHighlight("badge")
Java 方法调用与 addXref
(DRI hi
转换为 HTML span
)。请参阅 https://wiki.duraspace.org/display/DSDOC5x/DRI+Schema+Reference 的 DRI 文档(对于 5.x 但对于 6.x 没有改变)。
Cocoon 管道是 Java 产生 DRI (XML) -> preprocess.xsl 和相关文件修改 DRI,输出仍然是 DRI -> theme.xsl 和相关文件将 DRI 转换为 HTML。您正在尝试在管道中创建 HTML "too early"。您的原始 HTML 被转义到更远的轨道,这就是您在屏幕上看到标签的原因。
感谢@schweerelos 的回答,我设法应用她的代码并进行一些修改以解决 DSpace 版本中引入的 Has Files(s) facet 中的问题6.x.
我在 utils.xsl
中取消注释这段代码:
<xsl:template match="//dri:list[@id='aspect.discovery.SidebarFacetsTransformer.list.has_content_in_original_bundle']/dri:item//text()">
<xsl:choose>
<xsl:when test="contains(.,'true')">
<i18n:text>xmlui.ArtifactBrowser.AdvancedSearch.value_has_content_in_original_bundle_true</i18n:text>
</xsl:when>
<xsl:otherwise>
<i18n:text>xmlui.ArtifactBrowser.AdvancedSearch.value_has_content_in_original_bundle_false</i18n:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:value-of select="substring-after(.,' ')"/>
</xsl:template>
然后我修改了 Andrea 的代码以显示 No 或 Yes 用于具有原始包的记录:
<!-- render frequency counts in sidebar facets as badges -->
<xsl:template match="dri:list[@id='aspect.discovery.Navigation.list.discovery']/dri:list/dri:item/dri:xref" priority="9">
<xref>
<xsl:call-template name="copy-attributes"/>
<xsl:choose>
<xsl:when test="contains(text(), ' (') and contains(substring-after(text(), ' ('), ')')">
<xsl:variable name="title">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string" select="text()"/>
<xsl:with-param name="separator"><xsl:text> (</xsl:text></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="count">
<xsl:call-template name="remove-parens">
<xsl:with-param name="string" select="normalize-space(substring-after(text(), $title))"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(.,'true')">
<i18n:text>xmlui.ArtifactBrowser.AdvancedSearch.value_has_content_in_original_bundle_true</i18n:text>
</xsl:when>
<xsl:when test="contains(.,'false')">
<i18n:text>xmlui.ArtifactBrowser.AdvancedSearch.value_has_content_in_original_bundle_false</i18n:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$title"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<hi rend="badge">
<xsl:value-of select="$count"/>
</hi>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xref>
</xsl:template>
现在显示我想要的输出: