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	Thu May 05 18:31:47 2022 +0100
+++ b/GNUmakefile	Tue May 10 18:07:27 2022 +0400
@@ -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 @@
 		xslt/style.xslt						\
 		xslt/body.xslt						\
 		xslt/menu.xslt						\
+		xslt/banner.xslt					\
 		xslt/ga.xslt						\
 		xslt/content.xslt					\
 
@@ -313,14 +315,15 @@
 	$(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					\
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/banner/banner.html	Tue May 10 18:07:27 2022 +0400
@@ -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	Thu May 05 18:31:47 2022 +0100
+++ b/xsls/article.xsls	Tue May 10 18:07:27 2022 +0400
@@ -26,6 +26,7 @@
 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 @@
 
     !style (lang="@lang")
 
+    !banner ()
+
     !ga ()
 
     </head>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xsls/banner.xsls	Tue May 10 18:07:27 2022 +0400
@@ -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	Thu May 05 18:31:47 2022 +0100
+++ b/xsls/body.xsls	Tue May 10 18:07:27 2022 +0400
@@ -18,9 +18,6 @@
     <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	Thu May 05 18:31:47 2022 +0100
+++ b/xsls/error.xsls	Tue May 10 18:07:27 2022 +0400
@@ -26,6 +26,7 @@
 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 @@
 
     !style (lang="@lang")
 
+    !banner ()
+
     !ga ()
 
     </head>
--- a/xsls/news.xsls	Thu May 05 18:31:47 2022 +0100
+++ b/xsls/news.xsls	Tue May 10 18:07:27 2022 +0400
@@ -27,6 +27,7 @@
 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 @@
 
     !style (lang="@lang")
 
+    !banner ()
+
     !ga ()
 
     </head>
--- a/xslt/article.xslt	Thu May 05 18:31:47 2022 +0100
+++ b/xslt/article.xslt	Tue May 10 18:07:27 2022 +0400
@@ -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>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xslt/banner.xslt	Tue May 10 18:07:27 2022 +0400
@@ -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	Thu May 05 18:31:47 2022 +0100
+++ b/xslt/body.xslt	Tue May 10 18:07:27 2022 +0400
@@ -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	Thu May 05 18:31:47 2022 +0100
+++ b/xslt/error.xslt	Tue May 10 18:07:27 2022 +0400
@@ -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	Thu May 05 18:31:47 2022 +0100
+++ b/xslt/news.xslt	Tue May 10 18:07:27 2022 +0400
@@ -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>