From df55feeeb75452d4e04b2a494eb4260204c00e00 Mon Sep 17 00:00:00 2001 From: Ee Durbin Date: Thu, 26 Sep 2024 15:29:48 -0400 Subject: [PATCH 1/4] move redirects to their own file --- salt/docs/config/nginx.docs-backend.conf | 211 +-------------------- salt/docs/config/nginx.docs-redirects.conf | 210 ++++++++++++++++++++ salt/docs/init.sls | 10 + 3 files changed, 221 insertions(+), 210 deletions(-) create mode 100644 salt/docs/config/nginx.docs-redirects.conf diff --git a/salt/docs/config/nginx.docs-backend.conf b/salt/docs/config/nginx.docs-backend.conf index b71eac0d..30cf67ee 100644 --- a/salt/docs/config/nginx.docs-backend.conf +++ b/salt/docs/config/nginx.docs-backend.conf @@ -16,221 +16,12 @@ server { autoindex on; - # Python 3 docs are the default at the root. - location = / { - return 302 $scheme://$host/3/; - } - - # Python 3 docs are the default at the root of each translations. - location ~ ^/(es|fr|id|it|ja|ko|pl|pt-br|tr|uk|zh-cn|zh-tw)/$ { - return 302 $scheme://$host/$1/3/; - } - # Pretty 404 for archives telling to wait for them to be built. location ~ \.(pdf|zip|epub|bz2)$ { error_page 404 /404.html; } - # Some doc download pages link to docs.python.org/ftp instead of www.python.org/ftp. - location ^~ /ftp/ { - return 301 https://www.python.org$request_uri; - } - - location ~ /py3k(.*)$ { - return 301 https://$host/3$1; - } - - # Smooth the switch between versions by mapping old files to their new location - location ~ ^/([a-z-]*/)?(3|3.6|3.7|3.8)/library/email.util.html$ { - return 301 https://$host/$1$2/library/email.utils.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/c-api/(class|cobject|int|string).html$ { - return 301 https://$host/$1$2/c-api/; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/howto/(doanddont|webservers).html$ { - return 301 https://$host/$1$2/; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/(aepack|aetools|aetypes|al|autogil|bastion|bsddb|carbon|cd|colorpicker|commands|compiler|dbhash|dircache|dl|dummy_thread|easydialogs|fl|fm|fpectl|fpformat|framework|future_builtins|gensuitemodule|gl|hotshot|htmllib|ic|imageop|imgfile|imputil|jpeg|mac|macos|macosa|macostools|md5|mhlib|mimetools|mimewriter|mimify|miniaeframe|multifile|mutex|new|popen2|posixfile|restricted|rexec|rfc822|sgi|sgmllib|sha|someos|statvfs|sun|sunaudio|user).html$ { - return 301 https://$host/$1$2/; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/strings.html$ { - return 301 https://$host/$1$2/library/text.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/stringio.html$ { - return 301 https://$host/$1$2/library/io.html#io.StringIO; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/sets.html$ { - return 301 https://$host/$1$2/library/stdtypes.html#set-types-set-frozenset; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/userdict.html$ { - return 301 https://$host/$1$2/library/collections.html#userdict-objects; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/repr.html$ { - return 301 https://$host/$1$2/library/reprlib.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/copy_reg.html$ { - return 301 https://$host/$1$2/library/copyreg.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/anydbm.html$ { - return 301 https://$host/$1$2/library/dbm.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/whichdb.html$ { - return 301 https://$host/$1$2/library/dbm.html#dbm.whichdb; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/dumbdbm.html$ { - return 301 https://$host/$1$2/library/dbm.html#module-dbm.dumb; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/gdbm.html$ { - return 301 https://$host/$1$2/library/dbm.html#module-dbm.gnu; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/robotparser.html$ { - return 301 https://$host/$1$2/library/urllib.robotparser.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/thread.html$ { - return 301 https://$host/$1$2/library/_thread.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/email-examples.html$ { - return 301 https://$host/$1$2/library/email.examples.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/htmlparser.html$ { - return 301 https://$host/$1$2/library/html.parser.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/urllib2.html$ { - return 301 https://$host/$1$2/library/urllib.request.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/httplib.html$ { - return 301 https://$host/$1$2/library/http.client.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/urlparse.html$ { - return 301 https://$host/$1$2/library/urllib.parse.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/basehttpserver.html$ { - return 301 https://$host/$1$2/library/http.server.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/simplehttpserver.html$ { - return 301 https://$host/$1$2/library/http.server.html#http.server.SimpleHTTPRequestHandler; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/cgihttpserver.html$ { - return 301 https://$host/$1$2/library/http.server.html#http.server.CGIHTTPRequestHandler; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/cookielib.html$ { - return 301 https://$host/$1$2/library/http.cookiejar.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/cookie.html$ { - return 301 https://$host/$1$2/library/http.cookies.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/xmlrpclib.html$ { - return 301 https://$host/$1$2/library/xmlrpc.client.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/simplexmlrpcserver.html$ { - return 301 https://$host/$1$2/library/xmlrpc.server.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/docxmlrpcserver.html$ { - return 301 https://$host/$1$2/library/xmlrpc.server.html#documenting-xmlrpc-server; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/ttk.html$ { - return 301 https://$host/$1$2/library/tkinter.ttk.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/tix.html$ { - return 301 https://$host/$1$2/library/tkinter.tix.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/scrolledtext.html$ { - return 301 https://$host/$1$2/library/tkinter.scrolledtext.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/__builtin__.html$ { - return 301 https://$host/$1$2/library/builtins.html; - } - location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/_winreg.html$ { - return 301 https://$host/$1$2/library/winreg.html; - } - location ~ ^/([a-z-]*/)?(3|3.12|3.13|3.14)/library/(asynchat|asyncore|smtpd).html$ { - return 301 https://$host/$1$2/; - } - location ~ ^/([a-z-]*/)?(3.13|3.14)/library/(2to3|aifc|audioop|cgi|cgitb|chunk|crypt|imghdr|mailcap|msilib|nis|nntplib|ossaudiodev|pipes|sndhdr|spwd|sunau|telnetlib|tkinter.tix|uu|xdrlib).html$ { - return 301 https://$host/$1$2/; - } - - # Map /documenting to the devguide. - location ~ ^/devguide/(.*)$ { - return 301 https://devguide.python.org/$1; - } - location = /documenting/ { - return 301 https://devguide.python.org/documentation/start-documenting/; - } - location = /documenting/index.html { - return 301 https://devguide.python.org/documentation/start-documenting/; - } - location = /documenting/intro.html { - return 301 https://devguide.python.org/documentation/start-documenting/#introduction; - } - location = /documenting/style.html { - return 301 https://devguide.python.org/documentation/style-guide/; - } - location = /documenting/rest.html { - return 301 https://devguide.python.org/documentation/markup/; - } - location = /documenting/markup.html { - return 301 https://devguide.python.org/documentation/markup/; - } - location = /documenting/fromlatex.html { - return 301 https://devguide.python.org/documentation/markup/; - } - location = /documenting/building.html { - return 301 https://devguide.python.org/documentation/start-documenting/#building-the-documentation; - } - - # Map toplevel URIs to Python 3 docs. - location ~ ^/((archives|c-api|distutils|extending|faq|howto|install|library|reference|tutorial|using|whatsnew|_images|_sources|_static)(/.*)?)$ { - return 301 https://$host/3/$1; - } - location ~ ^/(about|bugs|contents|copyright|download|genindex.*|glossary|index|license|py-modindex|search)(.html)?$ { - return 301 https://$host/3/$1.html; - } - location ~ ^/(searchindex.js|objects.inv)$ { - return 301 https://$host/3/$1; - } - - # Emulate Apache's content-negotiation. Was a temporary measure, - # but now people are using it like a feature. - # Redirect ``$request_uri`` -> ``$request_uri.html``, - # where the latter is a valid webpage. - location ~ ^/((2|3)(\.[0-9]+)?|dev)/\w+/[\d\w\.]+(?!\.html)$ { - if (-f "${request_filename}.html") { - return 301 https://$host:$request_uri.html; - } - } - - # Map old, 2.5-and-earlier directory names to 2.6-and-later names. - location = /lib/ { - return 301 https://$host/library/; - } - location ~ ^/lib/module-([a-zA-Z0-9.]+)\.html$ { - return 301 https://$host/library/$1.html; - } - location = /tut/ { - return 301 https://$host/tutorial/; - } - location = /tut/tut.html { - return 301 https://$host/tutorial/; - } - location = /api/ { - return 301 https://$host/c-api/; - } - location = /ext/ { - return 301 https://$host/extending/; - } - location = /dist/ { - return 301 https://docs.python.org/distutils/; - } - location = /inst/ { - return 301 https://$host/install/; - } - location = /doc/ { - return 301 https://devguide.python.org/documenting.html; - } - location = /ref/ { - return 301 https://$host/reference/; - } + include docs-redirects.conf; } server { diff --git a/salt/docs/config/nginx.docs-redirects.conf b/salt/docs/config/nginx.docs-redirects.conf new file mode 100644 index 00000000..447b5118 --- /dev/null +++ b/salt/docs/config/nginx.docs-redirects.conf @@ -0,0 +1,210 @@ +# Python 3 docs are the default at the root. +location = / { + return 302 $scheme://$host/3/; +} + +# Python 3 docs are the default at the root of each translations. +location ~ ^/(es|fr|id|it|ja|ko|pl|pt-br|tr|uk|zh-cn|zh-tw)/$ { + return 302 $scheme://$host/$1/3/; +} + +# Some doc download pages link to docs.python.org/ftp instead of www.python.org/ftp. +location ^~ /ftp/ { + return 301 https://www.python.org$request_uri; +} + +location ~ /py3k(.*)$ { + return 301 https://$host/3$1; +} + +# Smooth the switch between versions by mapping old files to their new location +location ~ ^/([a-z-]*/)?(3|3.6|3.7|3.8)/library/email.util.html$ { + return 301 https://$host/$1$2/library/email.utils.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/c-api/(class|cobject|int|string).html$ { + return 301 https://$host/$1$2/c-api/; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/howto/(doanddont|webservers).html$ { + return 301 https://$host/$1$2/; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/(aepack|aetools|aetypes|al|autogil|bastion|bsddb|carbon|cd|colorpicker|commands|compiler|dbhash|dircache|dl|dummy_thread|easydialogs|fl|fm|fpectl|fpformat|framework|future_builtins|gensuitemodule|gl|hotshot|htmllib|ic|imageop|imgfile|imputil|jpeg|mac|macos|macosa|macostools|md5|mhlib|mimetools|mimewriter|mimify|miniaeframe|multifile|mutex|new|popen2|posixfile|restricted|rexec|rfc822|sgi|sgmllib|sha|someos|statvfs|sun|sunaudio|user).html$ { + return 301 https://$host/$1$2/; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/strings.html$ { + return 301 https://$host/$1$2/library/text.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/stringio.html$ { + return 301 https://$host/$1$2/library/io.html#io.StringIO; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/sets.html$ { + return 301 https://$host/$1$2/library/stdtypes.html#set-types-set-frozenset; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/userdict.html$ { + return 301 https://$host/$1$2/library/collections.html#userdict-objects; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/repr.html$ { + return 301 https://$host/$1$2/library/reprlib.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/copy_reg.html$ { + return 301 https://$host/$1$2/library/copyreg.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/anydbm.html$ { + return 301 https://$host/$1$2/library/dbm.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/whichdb.html$ { + return 301 https://$host/$1$2/library/dbm.html#dbm.whichdb; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/dumbdbm.html$ { + return 301 https://$host/$1$2/library/dbm.html#module-dbm.dumb; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/gdbm.html$ { + return 301 https://$host/$1$2/library/dbm.html#module-dbm.gnu; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/robotparser.html$ { + return 301 https://$host/$1$2/library/urllib.robotparser.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/thread.html$ { + return 301 https://$host/$1$2/library/_thread.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/email-examples.html$ { + return 301 https://$host/$1$2/library/email.examples.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/htmlparser.html$ { + return 301 https://$host/$1$2/library/html.parser.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/urllib2.html$ { + return 301 https://$host/$1$2/library/urllib.request.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/httplib.html$ { + return 301 https://$host/$1$2/library/http.client.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/urlparse.html$ { + return 301 https://$host/$1$2/library/urllib.parse.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/basehttpserver.html$ { + return 301 https://$host/$1$2/library/http.server.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/simplehttpserver.html$ { + return 301 https://$host/$1$2/library/http.server.html#http.server.SimpleHTTPRequestHandler; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/cgihttpserver.html$ { + return 301 https://$host/$1$2/library/http.server.html#http.server.CGIHTTPRequestHandler; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/cookielib.html$ { + return 301 https://$host/$1$2/library/http.cookiejar.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/cookie.html$ { + return 301 https://$host/$1$2/library/http.cookies.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/xmlrpclib.html$ { + return 301 https://$host/$1$2/library/xmlrpc.client.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/simplexmlrpcserver.html$ { + return 301 https://$host/$1$2/library/xmlrpc.server.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/docxmlrpcserver.html$ { + return 301 https://$host/$1$2/library/xmlrpc.server.html#documenting-xmlrpc-server; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/ttk.html$ { + return 301 https://$host/$1$2/library/tkinter.ttk.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/tix.html$ { + return 301 https://$host/$1$2/library/tkinter.tix.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/scrolledtext.html$ { + return 301 https://$host/$1$2/library/tkinter.scrolledtext.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/__builtin__.html$ { + return 301 https://$host/$1$2/library/builtins.html; +} +location ~ ^/([a-z-]*/)?(3|3.5|3.6|3.7|3.8|3.9|3.10)/library/_winreg.html$ { + return 301 https://$host/$1$2/library/winreg.html; +} +location ~ ^/([a-z-]*/)?(3|3.12|3.13|3.14)/library/(asynchat|asyncore|smtpd).html$ { + return 301 https://$host/$1$2/; +} +location ~ ^/([a-z-]*/)?(3.13|3.14)/library/(2to3|aifc|audioop|cgi|cgitb|chunk|crypt|imghdr|mailcap|msilib|nis|nntplib|ossaudiodev|pipes|sndhdr|spwd|sunau|telnetlib|tkinter.tix|uu|xdrlib).html$ { + return 301 https://$host/$1$2/; +} + +# Map /documenting to the devguide. +location ~ ^/devguide/(.*)$ { + return 301 https://devguide.python.org/$1; +} +location = /documenting/ { + return 301 https://devguide.python.org/documentation/start-documenting/; +} +location = /documenting/index.html { + return 301 https://devguide.python.org/documentation/start-documenting/; +} +location = /documenting/intro.html { + return 301 https://devguide.python.org/documentation/start-documenting/#introduction; +} +location = /documenting/style.html { + return 301 https://devguide.python.org/documentation/style-guide/; +} +location = /documenting/rest.html { + return 301 https://devguide.python.org/documentation/markup/; +} +location = /documenting/markup.html { + return 301 https://devguide.python.org/documentation/markup/; +} +location = /documenting/fromlatex.html { + return 301 https://devguide.python.org/documentation/markup/; +} +location = /documenting/building.html { + return 301 https://devguide.python.org/documentation/start-documenting/#building-the-documentation; +} + +# Map toplevel URIs to Python 3 docs. +location ~ ^/((archives|c-api|distutils|extending|faq|howto|install|library|reference|tutorial|using|whatsnew|_images|_sources|_static)(/.*)?)$ { + return 301 https://$host/3/$1; +} +location ~ ^/(about|bugs|contents|copyright|download|genindex.*|glossary|index|license|py-modindex|search)(.html)?$ { + return 301 https://$host/3/$1.html; +} +location ~ ^/(searchindex.js|objects.inv)$ { + return 301 https://$host/3/$1; +} + +# Emulate Apache's content-negotiation. Was a temporary measure, +# but now people are using it like a feature. +# Redirect ``$request_uri`` -> ``$request_uri.html``, +# where the latter is a valid webpage. +location ~ ^/((2|3)(\.[0-9]+)?|dev)/\w+/[\d\w\.]+(?!\.html)$ { + if (-f "${request_filename}.html") { + return 301 https://$host:$request_uri.html; + } +} + +# Map old, 2.5-and-earlier directory names to 2.6-and-later names. +location = /lib/ { + return 301 https://$host/library/; +} +location ~ ^/lib/module-([a-zA-Z0-9.]+)\.html$ { + return 301 https://$host/library/$1.html; +} +location = /tut/ { + return 301 https://$host/tutorial/; +} +location = /tut/tut.html { + return 301 https://$host/tutorial/; +} +location = /api/ { + return 301 https://$host/c-api/; +} +location = /ext/ { + return 301 https://$host/extending/; +} +location = /dist/ { + return 301 https://docs.python.org/distutils/; +} +location = /inst/ { + return 301 https://$host/install/; +} +location = /doc/ { + return 301 https://devguide.python.org/documenting.html; +} +location = /ref/ { + return 301 https://$host/reference/; +} diff --git a/salt/docs/init.sls b/salt/docs/init.sls index 41532123..6310d318 100644 --- a/salt/docs/init.sls +++ b/salt/docs/init.sls @@ -110,6 +110,15 @@ docsbuild-quick: - group: root - mode: "0644" +/etc/nginx/conf.d/docs-redirects.conf: + file.managed: + - source: salt://docs/config/nginx.docs-redirects.conf + - user: root + - group: root + - mode: "0644" + - require: + - pkg: nginx + /etc/nginx/sites.d/docs-backend.conf: file.managed: - source: salt://docs/config/nginx.docs-backend.conf @@ -119,6 +128,7 @@ docsbuild-quick: - require: - file: /etc/nginx/sites.d/ - file: /etc/nginx/fastly_params + - file: /etc/nginx/conf.d/docs-redirects.conf /etc/consul.d/service-docs.json: From 7d556846656c7cbdabb0799ecc3f5f22d09cc4b0 Mon Sep 17 00:00:00 2001 From: Ee Durbin Date: Thu, 26 Sep 2024 16:16:14 -0400 Subject: [PATCH 2/4] a very basic PoC for testing docs redirects --- tests/docs/redirects/nginx.conf | 4 ++++ tests/docs/redirects/run.sh | 19 +++++++++++++++++++ tests/docs/redirects/tests.hurl | 6 ++++++ 3 files changed, 29 insertions(+) create mode 100644 tests/docs/redirects/nginx.conf create mode 100644 tests/docs/redirects/run.sh create mode 100644 tests/docs/redirects/tests.hurl diff --git a/tests/docs/redirects/nginx.conf b/tests/docs/redirects/nginx.conf new file mode 100644 index 00000000..3e08c32b --- /dev/null +++ b/tests/docs/redirects/nginx.conf @@ -0,0 +1,4 @@ +server { + listen 10000; + include docs-redirects.conf; +} diff --git a/tests/docs/redirects/run.sh b/tests/docs/redirects/run.sh new file mode 100644 index 00000000..944f9574 --- /dev/null +++ b/tests/docs/redirects/run.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +docker stop docs-redirects-nginx + +set -ex # Do this after making sure the image is stopped + +docker run -d --rm -t \ + --name docs-redirects-nginx \ + -v $PWD/tests/docs/redirects/nginx.conf:/etc/nginx/conf.d/docs.conf \ + -v $PWD/salt/docs/config/nginx.docs-redirects.conf:/etc/nginx/docs-redirects.conf \ + -p 10000:10000 \ + nginx:1.26.1 + +# Let nginx start.... +sleep 1 + +hurl --test --no-output $PWD/tests/docs/redirects/tests.hurl + +docker stop docs-redirects-nginx diff --git a/tests/docs/redirects/tests.hurl b/tests/docs/redirects/tests.hurl new file mode 100644 index 00000000..609adcc1 --- /dev/null +++ b/tests/docs/redirects/tests.hurl @@ -0,0 +1,6 @@ + +# Test top level redirect +GET http://localhost:10000/ +HTTP 302 +[Asserts] +header "Location" == "http://localhost/3/" From 8baa9fbcc382d45b4dce06958bd00ab9b1f50c4d Mon Sep 17 00:00:00 2001 From: Ee Durbin Date: Thu, 26 Sep 2024 16:21:11 -0400 Subject: [PATCH 3/4] run in GHA --- .github/workflows/docs-redirects.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/docs-redirects.yml diff --git a/.github/workflows/docs-redirects.yml b/.github/workflows/docs-redirects.yml new file mode 100644 index 00000000..006446b3 --- /dev/null +++ b/.github/workflows/docs-redirects.yml @@ -0,0 +1,24 @@ +name: docs-redirects + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + docs-redirects: + name: Docs Redirects + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: install hurl + run: curl --location --remote-name https://github.com/Orange-OpenSource/hurl/releases/download/5.0.1/hurl_5.0.1_amd64.deb && sudo apt install -y ./hurl_5.0.1_amd64.deb + + - name: Run Tests + run: bash tests/docs/redirects/run.sh From 1cbd0b704d51e815ef3d5726592fa6f1b66e2a58 Mon Sep 17 00:00:00 2001 From: Ee Durbin Date: Thu, 26 Sep 2024 16:56:29 -0400 Subject: [PATCH 4/4] add a few more example tests --- tests/docs/redirects/tests.hurl | 66 ++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/tests/docs/redirects/tests.hurl b/tests/docs/redirects/tests.hurl index 609adcc1..c9ab80d3 100644 --- a/tests/docs/redirects/tests.hurl +++ b/tests/docs/redirects/tests.hurl @@ -1,6 +1,68 @@ - -# Test top level redirect +# Test: Python 3 docs are the default at the root. GET http://localhost:10000/ HTTP 302 [Asserts] header "Location" == "http://localhost/3/" + + +# Test: Python 3 docs are the default at the root of each translations. +GET http://localhost:10000/es/ +HTTP 302 +[Asserts] +header "Location" == "http://localhost/es/3/" + +GET http://localhost:10000/zh-tw/ +HTTP 302 +[Asserts] +header "Location" == "http://localhost/zh-tw/3/" + + +# Test: Some doc download pages link to docs.python.org/ftp instead of www.python.org/ftp. +GET http://localhost:10000/ftp/ +HTTP 301 +[Asserts] +header "Location" == "https://www.python.org/ftp/" + +GET http://localhost:10000/ftp/some/url +HTTP 301 +[Asserts] +header "Location" == "https://www.python.org/ftp/some/url" + + +# Test: py3k +GET http://localhost:10000/py3k +HTTP 301 +[Asserts] +header "Location" == "https://localhost/3" + +GET http://localhost:10000/py3k/some/url +HTTP 301 +[Asserts] +header "Location" == "https://localhost/3/some/url" + + +# Test: Smooth the switch between versions by mapping old files to their new location +GET http://localhost:10000/3/library/email.util.html +HTTP 301 +[Asserts] +header "Location" == "https://localhost/3/library/email.utils.html" + +GET http://localhost:10000/es/3/library/email.util.html +HTTP 301 +[Asserts] +header "Location" == "https://localhost/es/3/library/email.utils.html" + +GET http://localhost:10000/foobar/3/library/email.util.html +HTTP 301 +[Asserts] +header "Location" == "https://localhost/foobar/3/library/email.utils.html" + +GET http://localhost:10000/3.8/library/email.util.html +HTTP 301 +[Asserts] +header "Location" == "https://localhost/3.8/library/email.utils.html" + +GET http://localhost:10000/es/3.8/library/email.util.html +HTTP 301 +[Asserts] +header "Location" == "https://localhost/es/3.8/library/email.utils.html"