move declaration of $extract to fsfe.xsl to make it available for all XSL templates
This commit is contained in:
parent
d2c7688fdb
commit
0d4285a717
@ -151,56 +151,11 @@
|
||||
</xsl:for-each>
|
||||
|
||||
<!-- Twitter and Facebook sharing cards -->
|
||||
<xsl:variable name="metadesc">
|
||||
<!-- Get the meta element description -->
|
||||
<xsl:value-of select="head/meta[@name = 'description']/@content" />
|
||||
</xsl:variable>
|
||||
<xsl:variable name="metaimage">
|
||||
<!-- Get the meta element description -->
|
||||
<xsl:value-of select="head/meta[@name = 'image']/@content" />
|
||||
</xsl:variable>
|
||||
|
||||
<!-- EXTRACT -->
|
||||
<!-- take a first extract which should be sufficient for most pages -->
|
||||
<xsl:variable name="extract1">
|
||||
<!-- retrieve the first 200 letters of the first p element after h1 -->
|
||||
<xsl:value-of select="substring(normalize-space(body/h1[1]/following::p[1]),1,200)" />
|
||||
</xsl:variable>
|
||||
<!-- measure first extract length -->
|
||||
<xsl:variable name="extractlength1">
|
||||
<xsl:value-of select="string-length($extract1)" />
|
||||
</xsl:variable>
|
||||
<!-- define cases what happens with which extract length -->
|
||||
<xsl:variable name="extract">
|
||||
<xsl:choose>
|
||||
<!-- case: first extract is long enough -->
|
||||
<xsl:when test="$extractlength1 > 50">
|
||||
<xsl:value-of select="$extract1" />
|
||||
</xsl:when>
|
||||
<!-- case: first extract is too short -->
|
||||
<xsl:otherwise>
|
||||
<xsl:variable name="extract2">
|
||||
<!-- retrieve the first 200 letters of the *second* p element after h1 -->
|
||||
<xsl:value-of select="substring(normalize-space(body/h1[1]/following::p[2]),1,200)" />
|
||||
</xsl:variable>
|
||||
<!-- measure *second* extract length -->
|
||||
<xsl:variable name="extractlength2">
|
||||
<xsl:value-of select="string-length($extract2)" />
|
||||
</xsl:variable>
|
||||
<xsl:choose>
|
||||
<!-- case: second extract is long enough -->
|
||||
<xsl:when test="$extractlength2 > 50">
|
||||
<xsl:value-of select="$extract2" />
|
||||
</xsl:when>
|
||||
<!-- case: second extract is too short, so take default text -->
|
||||
<xsl:otherwise>
|
||||
Non profit organisation working to create general understanding and support for software freedom. Includes news, events, and campaigns.
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<!-- Twitter cards -->
|
||||
<xsl:element name="meta">
|
||||
<xsl:attribute name="name">twitter:card</xsl:attribute>
|
||||
@ -235,19 +190,7 @@
|
||||
<xsl:element name="meta">
|
||||
<xsl:attribute name="name">twitter:description</xsl:attribute>
|
||||
<xsl:attribute name="content">
|
||||
<xsl:choose>
|
||||
<!-- if there is a meta description, take that -->
|
||||
<xsl:when test="$metadesc != ''"><xsl:value-of select="$metadesc" /></xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:choose>
|
||||
<!-- if not, try to get the short extract -->
|
||||
<xsl:when test="$extract != ''"><xsl:value-of select="$extract" /><xsl:text>...</xsl:text></xsl:when>
|
||||
<!-- if even that isn't available, return a default text
|
||||
(not language sensitive). This should never be the case... -->
|
||||
<xsl:otherwise>Non profit organisation working to create general understanding and support for software freedom. Includes news, events, and campaigns.</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:value-of select="$extract" />
|
||||
</xsl:attribute>
|
||||
</xsl:element>
|
||||
<!-- Facebook sharing cards -->
|
||||
@ -283,19 +226,7 @@
|
||||
<xsl:element name="meta">
|
||||
<xsl:attribute name="property">og:description</xsl:attribute>
|
||||
<xsl:attribute name="content">
|
||||
<xsl:choose>
|
||||
<!-- if there is a meta description, take that -->
|
||||
<xsl:when test="$metadesc != ''"><xsl:value-of select="$metadesc" /></xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:choose>
|
||||
<!-- if not, try to get the short extract -->
|
||||
<xsl:when test="$extract != ''"><xsl:value-of select="$extract" /><xsl:text>...</xsl:text></xsl:when>
|
||||
<!-- if even that isn't available, return a default text
|
||||
(not language sensitive). This should never be the case... -->
|
||||
<xsl:otherwise>Non profit organisation working to create general understanding and support for software freedom. Includes news, events, and campaigns.</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:value-of select="$extract" />
|
||||
</xsl:attribute>
|
||||
</xsl:element> <!-- / Sharing cards -->
|
||||
|
||||
|
@ -171,7 +171,7 @@
|
||||
<!-- e-mail -->
|
||||
<xsl:element name="a">
|
||||
<xsl:attribute name="href">
|
||||
<xsl:value-of select="concat('mailto:?subject=', str:encode-uri($share-title, 'true', 'UTF-8'), '&body=', str:encode-uri($share-url, 'true', 'UTF-8'))"/>
|
||||
<xsl:value-of select="concat('mailto:?subject=', str:encode-uri($share-title, 'true', 'UTF-8'), '&body=', str:encode-uri($extract, 'true', 'UTF-8'), '%0A%0A', str:encode-uri($share-url, 'true', 'UTF-8'))"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="class">button share-mail</xsl:attribute>
|
||||
<xsl:text>E-Mail</xsl:text>
|
||||
|
56
fsfe.xsl
56
fsfe.xsl
@ -18,6 +18,62 @@
|
||||
<xsl:if test="/buildinfo/document/@external">https://fsfe.org</xsl:if>
|
||||
</xsl:variable>
|
||||
|
||||
<!-- EXTRACT -->
|
||||
<xsl:variable name="metadesc">
|
||||
<!-- Get the meta element description -->
|
||||
<xsl:value-of select="/buildinfo/document/head/meta[@name = 'description']/@content" />
|
||||
</xsl:variable>
|
||||
|
||||
<!-- if there is a meta description, take that -->
|
||||
<xsl:variable name="extract">
|
||||
<xsl:choose>
|
||||
<!-- if there is a meta description, take that -->
|
||||
<xsl:when test="$metadesc != ''">
|
||||
<xsl:value-of select="$metadesc" />
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<!-- take a first extract which should be sufficient for most pages -->
|
||||
<xsl:variable name="extract1">
|
||||
<!-- retrieve the first 200 letters of the first p element after h1 -->
|
||||
<xsl:value-of select="substring(normalize-space(/buildinfo/document/body/h1[1]/following::p[1]),1,200)" />
|
||||
</xsl:variable>
|
||||
<!-- measure first extract length -->
|
||||
<xsl:variable name="extractlength1">
|
||||
<xsl:value-of select="string-length($extract1)" />
|
||||
</xsl:variable>
|
||||
<!-- define cases what happens with which extract length -->
|
||||
<xsl:choose>
|
||||
<!-- case: first extract is long enough -->
|
||||
<xsl:when test="$extractlength1 > 50">
|
||||
<xsl:value-of select="$extract1" />
|
||||
<xsl:text>...</xsl:text>
|
||||
</xsl:when>
|
||||
<!-- case: first extract is too short -->
|
||||
<xsl:otherwise>
|
||||
<xsl:variable name="extract2">
|
||||
<!-- retrieve the first 200 letters of the *second* p element after h1 -->
|
||||
<xsl:value-of select="substring(normalize-space(/buildinfo/document/body/h1[1]/following::p[2]),1,200)" />
|
||||
</xsl:variable>
|
||||
<!-- measure *second* extract length -->
|
||||
<xsl:variable name="extractlength2">
|
||||
<xsl:value-of select="string-length($extract2)" />
|
||||
</xsl:variable>
|
||||
<xsl:choose>
|
||||
<!-- case: second extract is long enough -->
|
||||
<xsl:when test="$extractlength2 > 50">
|
||||
<xsl:value-of select="$extract2" />
|
||||
</xsl:when>
|
||||
<!-- case: second extract is too short, so take default text -->
|
||||
<xsl:otherwise>
|
||||
Non profit organisation working to create general understanding and support for software freedom. Includes news, events, and campaigns.
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:include href="build/xslt/fsfe_document.xsl" />
|
||||
<xsl:include href="build/xslt/fsfe_headings.xsl" />
|
||||
<xsl:include href="build/xslt/fsfe_localmenu.xsl" />
|
||||
|
Loading…
Reference in New Issue
Block a user