forked from jacobian/djangobook.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
37 lines (31 loc) · 1.33 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
The simplest possible app that can serve these Sphinx docs and issue
redirects for the previous URLs.
"""
import static
import selector
from unipath import FSPath as Path
app = selector.Selector()
def redirect(to):
"""
Create a 301 redirect WSGI app.
`to` may contain str.format-style formatting which'll be formatted against
the routing arguments (wsgiorg.routing_args).
"""
def _redirect(environ, start_response):
args, kwargs = environ['wsgiorg.routing_args']
start_response('301 MOVED PERMANENTLY',
[('Location', to.format(*args, **kwargs))])
return []
return _redirect
# Redirects for old doc URLs, since Cool URIs Don't Change.
app.add('/', GET=redirect('/en/2.0/index.html'))
app.add('/license/', GET=redirect('/en/2.0/license.html'))
app.add('/about/', GET=redirect('/en/2.0/frontmatter.html'))
app.add('/en/1.0/', GET=redirect('/en/2.0/index.html'))
app.add('/en/1.0/{doc:chunk}/', GET=redirect('/en/2.0/{doc}.html'))
app.add('/en/2.0/{doc:chunk}/', GET=redirect('/en/2.0/{doc}.html'))
# Serve docs at "/en/2.0" still, to leave room for the future.
# One of these days I'll actually do this, not just talk about it!
docs = static.Cling(Path(__file__).parent.child('_build', 'html'))
app.add("/en/2.0|", GET=docs)