Browse Source

improve logic of extraction and combination

pull/1088/head
Max Mehl 1 week ago
parent
commit
3ece269932
Signed by: max.mehl <max.mehl@fsfe.org> GPG Key ID: 2704E4AB371E2E92
1 changed files with 15 additions and 21 deletions
  1. 15
    21
      fsfe.xsl

+ 15
- 21
fsfe.xsl View File

@@ -18,16 +18,16 @@
<xsl:if test="/buildinfo/document/@external">https://fsfe.org</xsl:if>
</xsl:variable>

<!-- EXTRACT -->
<!-- EXTRACT / DESCRIPTION of each page -->
<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 -->
<!-- if there is a meta description, take that as an extract -->
<xsl:variable name="extract">
<xsl:choose>
<!-- if there is a meta description, take that -->
<!-- case 1: if there is a meta description, take that -->
<xsl:when test="$metadesc != ''">
<xsl:value-of select="$metadesc" />
</xsl:when>
@@ -35,37 +35,31 @@
<!-- 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:value-of select="substring(normalize-space(/buildinfo/document/body/h1[1]/following::p[1]),1,155)" />
</xsl:variable>
<!-- define cases what happens with which extract length -->
<xsl:choose>
<!-- case: first extract is long enough -->
<xsl:when test="$extractlength1 &gt; 50">
<!-- case 2: first paragraph is long enough -->
<xsl:when test="string-length($extract1) &gt; 50">
<xsl:value-of select="$extract1" />
<xsl:text>...</xsl:text>
</xsl:when>
<!-- case: first extract is too short -->
<!-- case 3: first paragraph 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:value-of select="substring(normalize-space(/buildinfo/document/body/h1[1]/following::p[2]),1,155)" />
</xsl:variable>
<xsl:choose>
<!-- case: second extract is long enough -->
<xsl:when test="$extractlength2 &gt; 50">
<xsl:value-of select="$extract2" />
<!-- case 3a: second paragraph is long enough -->
<xsl:when test="string-length($extract2) &gt; 50">
<!-- Combine $extract1 and $extract2 with max. 155 characters -->
<xsl:value-of select="substring(normalize-space(concat($extract1, ' ', $extract2)),1,155)" />
<xsl:text>...</xsl:text>
</xsl:when>
<!-- case: second extract is too short, so take default text -->
<!-- case 3b: also second extract is too short, so take a default text -->
<xsl:otherwise>
Non profit organisation working to create general understanding and support for software freedom. Includes news, events, and campaigns.
<xsl:text>Free Software Foundation Europe is a charity that empowers users to control technology. We enable people to use, understand, adapt and share software.</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>

Loading…
Cancel
Save