Merge branch 'feature/22-mail-share-link' of FSFE/fsfe-website into master
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Michael Weimann 2019-10-04 09:23:23 +02:00 committed by FSFE System
commit 8a67f4b596
4 changed files with 82 additions and 89 deletions

View File

@ -151,55 +151,10 @@
</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">
<xsl:value-of select="image/@url" />
</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 &gt; 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 &gt; 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>
@ -219,7 +174,7 @@
<!-- if there is a meta "image", take that -->
<xsl:when test="$metaimage != ''"><xsl:value-of select="$metaimage" /></xsl:when>
<xsl:otherwise>
https://fsfe.org/graphics/logo-text_square.png
<xsl:text>https://fsfe.org/graphics/logo-text_square.png</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
@ -234,19 +189,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 -->
@ -259,7 +202,7 @@
<!-- if there is a meta "image", take that -->
<xsl:when test="$metaimage != ''"><xsl:value-of select="$metaimage" /></xsl:when>
<xsl:otherwise>
https://fsfe.org/graphics/logo-text_square.png
<xsl:text>https://fsfe.org/graphics/logo-text_square.png</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
@ -282,19 +225,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 -->

View File

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings">
<xsl:template name="sharebuttons">
<!-- normalized article title -->
@ -134,7 +137,7 @@
</xsl:attribute>
<xsl:text>Reddit</xsl:text>
</xsl:element>
<!-- Flattr -->
<xsl:element name="button">
<xsl:attribute name="type">submit</xsl:attribute>
@ -165,6 +168,15 @@
<xsl:text>Hacker News</xsl:text>
</xsl:element>
<!-- 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'), '&amp;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>
</xsl:element>
<!-- Twitter -->
<xsl:element name="button">
<xsl:attribute name="type">submit</xsl:attribute>

View File

@ -18,6 +18,56 @@
<xsl:if test="/buildinfo/document/@external">https://fsfe.org</xsl:if>
</xsl:variable>
<!-- 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 as an extract -->
<xsl:variable name="extract">
<xsl:choose>
<!-- case 1: 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,155)" />
</xsl:variable>
<!-- define cases what happens with which extract length -->
<xsl:choose>
<!-- 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 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,155)" />
</xsl:variable>
<xsl:choose>
<!-- 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 3b: also second extract is too short, so take a default text -->
<xsl:otherwise>
<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>
</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" />

View File

@ -856,26 +856,26 @@ form.thankyou {
.share-button-top,
.share-button-sidebar,
.share-buttons.bottom a.button,
.share-buttons.bottom button.button,
.share-buttons.bottom label.button {
display: inline-block;
margin: 2.5px 5px 2.5px 0;
color: #fff;
font-weight: normal;
font-size: 1em;
line-height: normal;
text-align: center;
text-decoration: none;
padding: 7px 7px 7px 20px;
width: 19%;
min-width: 100px;
max-width: 110px;
border: none;
border-radius: 3px;
background-position: left 5px center;
background-repeat: no-repeat;
background-size: 20px auto;
border: none;
border-radius: 3px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 1em;
font-weight: normal;
line-height: normal;
margin: 2.5px 5px 2.5px 0;
min-width: 100px;
opacity: 0.9;
padding: 7px 7px 7px 30px;
text-align: center;
text-decoration: none;
vertical-align: top;
}