-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add social-media-opengraph & social-media-twitter
- Loading branch information
Showing
3 changed files
with
142 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:d="http://docbook.org/ns/docbook" | ||
xmlns:dm="urn:x-suse:ns:docmanager" | ||
xmlns:exsl="http://exslt.org/common" | ||
xmlns:date="http://exslt.org/dates-and-times" | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
exclude-result-prefixes="exsl date d dm"> | ||
|
||
<xsl:template match="d:meta[@name='productname']" mode="meta"> | ||
<xsl:variable name="productname" select="normalize-space(string(d:productname[1]))"/> | ||
<xsl:value-of select="$productname"/> | ||
</xsl:template> | ||
|
||
<xsl:template match="d:meta[@name='productname']/d:productname[1]/@version" mode="meta"> | ||
<xsl:value-of select="."/> | ||
</xsl:template> | ||
|
||
|
||
<xsl:template name="social-media-opengraph"> | ||
<xsl:param name="node" select="."/> | ||
<xsl:param name="socialmedia.title"/> | ||
<xsl:param name="socialmedia.description"/> | ||
<xsl:param name="socialmedia.preview"/> | ||
<xsl:param name="canonical-url-base"/> | ||
<xsl:variable name="ischunk"> | ||
<xsl:call-template name="chunk"/> | ||
</xsl:variable> | ||
<xsl:variable name="filename"> | ||
<xsl:choose> | ||
<xsl:when test="$ischunk = 1"> | ||
<xsl:apply-templates mode="chunk-filename" select="."/> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:value-of select="concat($root.filename,$html.ext)"/> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:variable> | ||
<xsl:variable name="canonical.url" select="concat($canonical-url-base,'/',$filename)"/> | ||
<xsl:variable name="meta.nodes" select="d:info/d:meta|ancestor::*/d:info/d:meta"/> | ||
|
||
<xsl:if test="$canonical-url-base != ''"> | ||
<!-- These Open Graph and Twitter Cards properties need a canonical URL --> | ||
<link rel="canonical" href="{$canonical.url}"/> | ||
<xsl:text> </xsl:text> | ||
<!-- These Open Graph and Twitter Cards properties need a canonical URL --> | ||
<meta property="og:url" content="{$canonical.url}"/> | ||
<xsl:text> </xsl:text> | ||
<meta property="og:image" content="{concat($canonical-url-base,'/',$socialmedia.preview)}"/> | ||
<xsl:text> </xsl:text> | ||
<xsl:call-template name="meta-generator"/> | ||
</xsl:if> | ||
|
||
<xsl:message>social-media-opengraph: <xsl:value-of select="local-name($node)"/></xsl:message> | ||
|
||
<xsl:choose> | ||
<xsl:when test="$meta.nodes[@name='title']"> | ||
<xsl:message>#############: <xsl:value-of select="normalize-space($meta.nodes[@name='title'][last()])"/></xsl:message> | ||
<meta property="og:title" content="{normalize-space($meta.nodes[@name='title'][last()])}"/> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<meta property="og:title" content="{$socialmedia.title}"/> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
<xsl:text> </xsl:text> | ||
|
||
<xsl:choose> | ||
<xsl:when test="$meta.nodes[@name='description']"> | ||
<meta property="og:description" content="{normalize-space($meta.nodes[@name='description'][last()])}" /> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<meta property="og:description" content="{$socialmedia.description}"/> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
<xsl:text> </xsl:text> | ||
|
||
<meta property="og:type" content="{$opengraph.type}"/> | ||
<xsl:text> </xsl:text> | ||
</xsl:template> | ||
|
||
|
||
<xsl:template name="social-media-twitter"> | ||
<xsl:param name="node" select="."/> | ||
<xsl:param name="socialmedia.title"/> | ||
<xsl:param name="socialmedia.description"/> | ||
<xsl:param name="socialmedia.preview"/> | ||
<xsl:param name="canonical-url-base"/> | ||
<xsl:variable name="meta.nodes" select="d:info/d:meta|ancestor::*/d:info/d:meta"/> | ||
|
||
<meta name="twitter:card" content="{$twittercards.type}"/> | ||
<xsl:text> </xsl:text> | ||
|
||
<xsl:if test="$canonical-url-base != ''"> | ||
<meta name="twitter:image" content="{concat($canonical-url-base,'/',$socialmedia.preview)}"/> | ||
<xsl:text> </xsl:text> | ||
</xsl:if> | ||
|
||
<xsl:choose> | ||
<xsl:when test="$meta.nodes[@name='title']"> | ||
<meta property="twitter:title" content="{normalize-space($meta.nodes[@name='title'][last()])}" /> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<meta name="twitter:title" content="{$socialmedia.title}"/> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
<xsl:text> </xsl:text> | ||
|
||
<xsl:choose> | ||
<xsl:when test="$meta.nodes[@name='description']"> | ||
<meta name="twitter:description" content="{normalize-space($meta.nodes[@name='description'][last()])}" /> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<meta name="twitter:description" content="{$socialmedia.description}"/> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
<xsl:text> </xsl:text> | ||
|
||
<xsl:if test="string-length($twittercards.twitter.account) > 0"> | ||
<meta name="twitter:site" content="{$twittercards.twitter.account}"/> | ||
<xsl:text> </xsl:text> | ||
</xsl:if> | ||
</xsl:template> | ||
|
||
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters