Skip to content

Commit

Permalink
Support feed URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
omo committed Dec 19, 2019
1 parent b2a04f2 commit be015e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion main.py
Expand Up @@ -10,17 +10,22 @@
def _redirect_to_fallback():
return flask.redirect('https://anemone.dodgson.org/')

def _redirect_to_feed():
return flask.redirect('https://anemone.dodgson.org/index.xml')

@app.route('/<path:path>')
def all(path):
if path in ['atom.xml', 'index.rdf', 'no_comments.rdf']:
return _redirect_to_feed()

# All the relevant URL is (shold be able to) categorized solely based on the path part.
# You don't have to look at the host name.

# Handle tDiary-like, e.g: http://stepped.dodgson.org/?date=20110417
# http://www.dodgson.org/omo/t/?date=20080316
date_param = flask.request.args.get('date', None)
if date_param:
match = re.match('(\d\d\d\d)(\d\d)(\d\d)', date_param)
match = re.match(r'(\d\d\d\d)(\d\d)(\d\d)', date_param)
if not match:
return _redirect_to_fallback()
yyyy, mm, dd = match.group(1, 2, 3)
Expand Down
3 changes: 3 additions & 0 deletions main_test.py
Expand Up @@ -29,3 +29,6 @@ def test_octopress():

def test_octopress_pages():
_assert_redirect('/blog/archives/', 'https://blog.dodgson.org/blog/archives/')

def test_feed():
_assert_redirect('/atom.xml', 'https://anemone.dodgson.org/index.xml')

0 comments on commit be015e0

Please sign in to comment.