Mercurial > hg > nginx-site
changeset 2846:fdf1464e1977
Moved banner to the external file to make partial rollout possible.
An idea is to have several banners and show them with different probability
specified by split directive in the nginx.conf
author | Sergey Budnevitch <sb@waeme.net> |
---|---|
date | Tue, 10 May 2022 18:07:27 +0400 |
parents | a3aee2697d4e |
children | f5e49925e9db |
files | GNUmakefile banner/banner.html xsls/article.xsls xsls/banner.xsls xsls/body.xsls xsls/error.xsls xsls/news.xsls xslt/article.xslt xslt/banner.xslt xslt/body.xslt xslt/error.xslt xslt/news.xslt |
diffstat | 12 files changed, 91 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/GNUmakefile +++ b/GNUmakefile @@ -1,6 +1,7 @@ OUT = libxslt TEXT = text +BANNER = banner ZIP = gzip NGINX_ORG = /data/www/nginx.org SHELL = ./umasked.sh @@ -45,6 +46,7 @@ COMMON_DEPS = \ xslt/style.xslt \ xslt/body.xslt \ xslt/menu.xslt \ + xslt/banner.xslt \ xslt/ga.xslt \ xslt/content.xslt \ @@ -313,14 +315,15 @@ gzip: rsync_gzip $(MAKE) do_gzip rsync_gzip: - $(CHMOD) $(OUT) $(TEXT) - $(RSYNC) --delete --exclude='*.gz' $(OUT)/ $(TEXT)/ $(ZIP)/ + $(CHMOD) $(OUT) $(TEXT) $(BANNER) + $(RSYNC) --delete --exclude='*.gz' $(OUT)/ $(TEXT)/ $(BANNER) $(ZIP)/ do_gzip: $(addsuffix .gz, $(wildcard $(ZIP)/*.html)) \ $(addsuffix .gz, \ $(foreach lang, $(LANGS), \ $(foreach dir, . docs docs/dev docs/faq docs/http docs/mail docs/njs docs/stream, \ $(wildcard $(ZIP)/$(lang)/$(dir)/*.html)))) \ + $(addsuffix .gz, $(wildcard $(ZIP)/$(BANNER)/*.html)) \ $(ZIP)/index.rss.gz \ $(ZIP)/LICENSE.gz \ $(ZIP)/en/CHANGES.gz \
new file mode 100644 --- /dev/null +++ b/banner/banner.html @@ -0,0 +1,2 @@ + Registration is now open for the free Microservices March Kubernetes event.<br/> + <a href="https://www.nginx.com/c/microservices-march-2022-kubernetes-networking/">Click here</a> to enroll.
--- a/xsls/article.xsls +++ b/xsls/article.xsls @@ -26,6 +26,7 @@ X:include href = "link.xslt"; X:include href = "style.xslt"; X:include href = "body.xslt"; X:include href = "menu.xslt"; +X:include href = "banner.xslt"; X:include href = "ga.xslt"; X:include href = "content.xslt"; X:include href = "books.xslt"; @@ -49,6 +50,8 @@ X:template = "/article | /module" { !style (lang="@lang") + !banner () + !ga () </head>
new file mode 100644 --- /dev/null +++ b/xsls/banner.xsls @@ -0,0 +1,34 @@ +<!-- + Copyright (C) Nginx, Inc. + --> + +X:stylesheet { + +X:var BANNER = "'/banner/banner.html'"; + +X:template banner_link () { + X:if "substring-after($DIRNAME, '/')" { + !{ concat($ROOT, $BANNER) } + } else { + !{ substring-after($BANNER, '/') } + } +} + +X:template banner () { + + <script> + window.addEventListener("load", function(e) \{ + fetch("!banner_link ()") + .then((response) => response.text()) + .then((resp) => \{ + document.getElementById("banner").innerHTML = resp; + \}) + .catch((error) => \{ + console.warn(error); + \}); + \}); + </script> + +} + +}
--- a/xsls/body.xsls +++ b/xsls/body.xsls @@ -18,9 +18,6 @@ X:template body (lang) { <body> <div id="banner"> - X:if "@lang = 'he'" { X:attribute "class" { X:text{ltr} } } - Registration is now open for the free Microservices March Kubernetes event.<br/> - <a href="https://www.nginx.com/c/microservices-march-2022-kubernetes-networking/">Click here</a> to enroll. </div> <div id="main">
--- a/xsls/error.xsls +++ b/xsls/error.xsls @@ -26,6 +26,7 @@ X:include href = "link.xslt"; X:include href = "style.xslt"; X:include href = "body.xslt"; X:include href = "menu.xslt"; +X:include href = "banner.xslt"; X:include href = "ga.xslt"; X:include href = "content.xslt"; @@ -35,6 +36,8 @@ X:template = "/error" { !style (lang="@lang") + !banner () + !ga () </head>
--- a/xsls/news.xsls +++ b/xsls/news.xsls @@ -27,6 +27,7 @@ X:include href = "link.xslt"; X:include href = "style.xslt"; X:include href = "body.xslt"; X:include href = "menu.xslt"; +X:include href = "banner.xslt"; X:include href = "ga.xslt"; X:include href = "content.xslt"; @@ -41,6 +42,8 @@ X:template = "/news" { !style (lang="@lang") + !banner () + !ga () </head>
--- a/xslt/article.xslt +++ b/xslt/article.xslt @@ -27,6 +27,7 @@ <xsl:include href="style.xslt"/> <xsl:include href="body.xslt"/> <xsl:include href="menu.xslt"/> +<xsl:include href="banner.xslt"/> <xsl:include href="ga.xslt"/> <xsl:include href="content.xslt"/> <xsl:include href="books.xslt"/> @@ -48,7 +49,7 @@ <title> <xsl:value-of select="@name"/> </title> - <xsl:call-template name="style"><xsl:with-param select="@lang" name="lang"/></xsl:call-template><xsl:call-template name="ga"/></head> + <xsl:call-template name="style"><xsl:with-param select="@lang" name="lang"/></xsl:call-template><xsl:call-template name="banner"/><xsl:call-template name="ga"/></head> <xsl:call-template name="body"><xsl:with-param select="@lang" name="lang"/></xsl:call-template></html> </xsl:template>
new file mode 100644 --- /dev/null +++ b/xslt/banner.xslt @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) Nginx, Inc. + --> + +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> + +<xsl:variable select="'/banner/banner.html'" name="BANNER"/> + +<xsl:template name="banner_link"> + <xsl:choose><xsl:when test="substring-after($DIRNAME, '/')"> + <xsl:value-of select=" concat($ROOT, $BANNER) "/> + </xsl:when><xsl:otherwise> + <xsl:value-of select=" substring-after($BANNER, '/') "/> + </xsl:otherwise></xsl:choose> +</xsl:template> + +<xsl:template name="banner"> + + <script> + window.addEventListener("load", function(e) { + fetch("<xsl:call-template name="banner_link"/>") + .then((response) => response.text()) + .then((resp) => { + document.getElementById("banner").innerHTML = resp; + }) + .catch((error) => { + console.warn(error); + }); + }); + </script> + +</xsl:template> + +</xsl:stylesheet>
--- a/xslt/body.xslt +++ b/xslt/body.xslt @@ -19,9 +19,6 @@ <body> <div id="banner"> - <xsl:if test="@lang = 'he'"> <xsl:attribute name="class"> <xsl:text>ltr</xsl:text> </xsl:attribute> </xsl:if> - Registration is now open for the free Microservices March Kubernetes event.<br/> - <a href="https://www.nginx.com/c/microservices-march-2022-kubernetes-networking/">Click here</a> to enroll. </div> <div id="main">
--- a/xslt/error.xslt +++ b/xslt/error.xslt @@ -27,6 +27,7 @@ <xsl:include href="style.xslt"/> <xsl:include href="body.xslt"/> <xsl:include href="menu.xslt"/> +<xsl:include href="banner.xslt"/> <xsl:include href="ga.xslt"/> <xsl:include href="content.xslt"/> @@ -34,7 +35,7 @@ <xsl:template match="/error"> <html><head><title> <xsl:value-of select="@name"/> </title> - <xsl:call-template name="style"><xsl:with-param select="@lang" name="lang"/></xsl:call-template><xsl:call-template name="ga"/></head> + <xsl:call-template name="style"><xsl:with-param select="@lang" name="lang"/></xsl:call-template><xsl:call-template name="banner"/><xsl:call-template name="ga"/></head> <xsl:call-template name="body"><xsl:with-param select="@lang" name="lang"/></xsl:call-template></html> </xsl:template>
--- a/xslt/news.xslt +++ b/xslt/news.xslt @@ -28,6 +28,7 @@ <xsl:include href="style.xslt"/> <xsl:include href="body.xslt"/> <xsl:include href="menu.xslt"/> +<xsl:include href="banner.xslt"/> <xsl:include href="ga.xslt"/> <xsl:include href="content.xslt"/> @@ -39,7 +40,7 @@ <title> <xsl:value-of select="@name"/> <xsl:if test="$YEAR"> <xsl:text>: </xsl:text> <xsl:value-of select="$YEAR"/> </xsl:if> </title> - <xsl:call-template name="style"><xsl:with-param select="@lang" name="lang"/></xsl:call-template><xsl:call-template name="ga"/></head> + <xsl:call-template name="style"><xsl:with-param select="@lang" name="lang"/></xsl:call-template><xsl:call-template name="banner"/><xsl:call-template name="ga"/></head> <xsl:call-template name="body"><xsl:with-param select="@lang" name="lang"/></xsl:call-template></html> </xsl:template>