Skip to content

Commit

Permalink
Merge pull request #565 from openSUSE/trim-text
Browse files Browse the repository at this point in the history
XHTML: Trim text for twitter:* metadata
  • Loading branch information
tomschr authored Aug 10, 2023
2 parents 83b4557 + 0078396 commit 716b0d2
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions suse2022-ns/xhtml/meta.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@
<xsl:when test="$meta.nodes[@name='social-descr']">
<xsl:choose>
<xsl:when test="string-length($meta.nodes[@name='social-descr']) &lt; $socialmedia.description.length">
<xsl:value-of select="$meta.nodes[@name='social-descr']"/>
<xsl:call-template name="trim.text">
<xsl:with-param name="contents" select="$meta.nodes[@name = 'social-descr']" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="log.message">
Expand All @@ -237,20 +239,26 @@
<xsl:value-of select="concat($socialmedia.description.length, ' characters!')"/>
</xsl:with-param>
</xsl:call-template>
<xsl:value-of select="substring(normalize-space($meta.nodes[@name = 'social-descr']), 1, $socialmedia.description.length)" />
<xsl:value-of select="normalize-space(substring($meta.nodes[@name = 'social-descr'], 1, $socialmedia.description.length))" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$socialmedia.description">
<xsl:choose>
<xsl:when test="string-length($socialmedia.description) > $socialmedia.description.length">
<xsl:call-template name="ellipsize.text">
<xsl:with-param name="input" select="$socialmedia.description"/>
<xsl:with-param name="input">
<xsl:call-template name="trim.text">
<xsl:with-param name="contents" select="$socialmedia.description"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="ellipsize.after" select="$socialmedia.description.length"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$socialmedia.description"/>
<xsl:call-template name="trim.text">
<xsl:with-param name="contents" select="$socialmedia.description" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
Expand All @@ -268,7 +276,11 @@
<xsl:variable name="title">
<xsl:choose>
<xsl:when test="$meta.nodes[@name='title']">
<xsl:variable name="tmp" select="normalize-space($meta.nodes[@name='title'][last()])"/>
<xsl:variable name="tmp">
<xsl:call-template name="trim.text">
<xsl:with-param name="contents" select="$meta.nodes[@name='title'][last()]" />
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$tmp = ''">
<xsl:call-template name="log.message">
Expand Down Expand Up @@ -298,7 +310,9 @@
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$socialmedia.title"/>
<xsl:call-template name="trim.text">
<xsl:with-param name="contents" select="$socialmedia.title" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Expand Down

0 comments on commit 716b0d2

Please sign in to comment.