diff --git a/app.py b/app.py index 5108529b..866b6308 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ from jinja2 import Environment, FileSystemLoader, environmentfilter from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash, send_from_directory, safe_join +from docutils.core import publish_parts import os.path import os import fileinput @@ -9,6 +10,7 @@ import codecs TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), 'pages') STATIC_DIR = os.path.join(os.path.dirname(__file__), 'static') +BLOG_DIR = os.path.join(os.path.dirname(__file__), 'blog') MEETINGS_DIR = os.path.join(os.path.dirname(__file__), 'meetings') app = application = Flask(__name__, template_folder=TEMPLATE_DIR, static_url_path='/_static', static_folder=STATIC_DIR) @@ -29,11 +31,6 @@ def after_this_request(f): @app.template_filter('restructuredtext') def restructuredtext(value): - try: - from docutils.core import publish_parts - except ImportError: - print u"Install docutils!!11" - raise parts = publish_parts(source=value, writer_name="html") return parts['html_body'] @@ -44,6 +41,15 @@ def pull_lang(endpoint, values): return g.lang=values.pop('lang', None) +@app.url_defaults +def set_lang(endpoint, values): + if not values: + return + if 'lang' in values: + return + if hasattr(g, 'lang'): + values['lang'] = g.lang + @app.before_request def detect_theme(): theme = 'light' @@ -63,15 +69,30 @@ def detect_theme(): return resp +@app.errorhandler(404) +def page_not_found(error): + return render_template('global/error_404.html'), 404 + @app.route('/') def main_index(): return redirect(url_for('site_show', lang='en')) + + @app.route('//site/') @app.route('//site/') -def site_show(page=''): - # TODO: set content_type - pass +def site_show(page='index'): + if page.endswith('.html'): + return redirect(url_for('site_show', page=page[:-5])) + name = 'site/%s.html' % page + page_file = safe_join(TEMPLATE_DIR, name) + + # bah! those damn users all the time! + if not os.path.exists(page_file): + abort(404) + + # hah! + return render_template(name, page=page) @app.route('//meetings/') def meetings_index(): @@ -131,8 +152,8 @@ def meetings_show_rst(id): @app.route('//download') def downloads_list(): - # TODO: implement - pass + # TODO: read mirror list or list of available files + return render_template('downloads/list.html') @app.route('//download/') def downloads_select(file): @@ -145,6 +166,28 @@ def downloads_redirect(protocol, file, mirror=None): # TODO: implement pass + + +def render_blog_entry(slug): + """ + Render the blog entry + TODO: + - caching + - move to own file + """ + # check if that file actually exists + path = safe_join(BLOG_DIR, slug + ".rst") + if not os.path.exists(path): + abort(404) + + # read file + with codecs.open(path, encoding='utf-8') as fd: + content = fd.read() + + return publish_parts(source=content, source_path=BLOG_DIR, writer_name="html") + + + @app.route('//blog/') @app.route('//blog/page/') def blog_index(page=0): @@ -153,8 +196,15 @@ def blog_index(page=0): @app.route('//blog/entry/') def blog_entry(slug): - # TODO: implement - pass + # try to render that blog entry.. throws 404 if it does not exist + parts = render_blog_entry(slug) + + if parts: + # now just pass to simple template file and we are done + return render_template('blog/entry.html', parts=parts, title=parts['title'], body=parts['fragment']) + else: + abort(404) + @app.route('/feed/blog/rss') def blog_rss(): @@ -181,8 +231,24 @@ def legacy_meeting(id): def legacy_status(year, month, day): return redirect(url_for('blog_entry', lang='en', slug=('%s/%s/%s/status' % (year, month, day)))) +LEGACY_MAP={ + 'download': 'downloads_list' +} +@app.route('/_') +@app.route('/_.html') @app.route('/') +@app.route('/.html') def legacy_show(f): - # TODO: redirect to correct new url - pass + lang = 'en' + if hasattr(g, 'lang') and g.lang: + lang = g.lang + if f in LEGACY_MAP: + return redirect(url_for(LEGACY_MAP[f], lang=lang)) + else: + return redirect(url_for('site_show', lang=lang, page=f)) + + + +if __name__ == '__main__': + app.run(debug=True) diff --git a/www.i2p2/pages/status-2006-10-10.html b/blog/2006/10/10/status.html similarity index 94% rename from www.i2p2/pages/status-2006-10-10.html rename to blog/2006/10/10/status.html index 6578b642..a3c787e3 100644 --- a/www.i2p2/pages/status-2006-10-10.html +++ b/blog/2006/10/10/status.html @@ -1,7 +1,5 @@ -{% extends "_layout.html" %} -{% block title %}I2P Status Notes for 2006-10-10{% endblock %} -{% block content %}

I2P Status Notes for 2006-10-10

-
-----BEGIN PGP SIGNED MESSAGE-----
+
+-----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 Hi y'all, brief status notes this week
@@ -79,7 +77,4 @@ iD8DBQFFK6hgzgi8JTPcjUkRAuG2AJ46vK/13GIEngzQe05KRuEP2ZYvRQCeJB3j
 VmEzybBbtZSpSrFcU4qdvks=
 =QlDy
 -----END PGP SIGNATURE-----
-
-
 
-{% endblock %} diff --git a/blog/2006/10/10/status.rst b/blog/2006/10/10/status.rst new file mode 100644 index 00000000..b77847b7 --- /dev/null +++ b/blog/2006/10/10/status.rst @@ -0,0 +1,6 @@ +=============================== +I2P STATUS NOTES FOR 2006-10-10 +=============================== + +.. raw:: html + :file: blog/2006/10/10/status.html diff --git a/www.i2p2/pages/download.html b/pages/downloads/list.html similarity index 99% rename from www.i2p2/pages/download.html rename to pages/downloads/list.html index 7f5f9201..f7e5667f 100644 --- a/www.i2p2/pages/download.html +++ b/pages/downloads/list.html @@ -1,4 +1,4 @@ -{% extends "_layout.html" %} +{% extends "global/layout.html" %} {% block title %}Download{% endblock %} {% block content %}

Download I2P

diff --git a/pages/global/error_404.html b/pages/global/error_404.html new file mode 100644 index 00000000..d8563c03 --- /dev/null +++ b/pages/global/error_404.html @@ -0,0 +1,21 @@ +{% extends "global/layout.html" %} +{% block title -%} +{% if g.lang == 'de' %} +Nicht gefunden +{% elif g.lang == 'zh' %} +未找到 +{% else %} +Not found +{% endif %} +{%- endblock %} + +{% block content %} +{% if g.lang == 'de' %} +Yep... die Information nach der du suchst, nennt sich anders, existiert nicht oder wurde entfernt. +{% elif g.lang == 'zh' %} +您搜索的页面或资源的名称不正确或不存在或已被删除。 +{% else %} +Yep... the resource, you were searching for, is named differently, doesn't exist or was removed. +{% endif %} + +{% endblock %} diff --git a/pages/global/urlify b/pages/global/urlify index 59ffe02c..e8c9cd78 100644 --- a/pages/global/urlify +++ b/pages/global/urlify @@ -1,7 +1,9 @@ {% macro urlify(url, title, suffix) %} + {% autoescape false %} {% if static %} {{title}} {% else %} {{title}} {% endif %} + {% endautoescape %} {% endmacro %} \ No newline at end of file diff --git a/www.i2p2/pages/index.html b/pages/site/index.html similarity index 94% rename from www.i2p2/pages/index.html rename to pages/site/index.html index 4c6debbf..c3df28ee 100644 --- a/www.i2p2/pages/index.html +++ b/pages/site/index.html @@ -1,10 +1,11 @@ -{% extends "_layout.html" %} +{% extends "global/layout.html" %} +{% from "global/urlify" import urlify as urlify %} {% block title %}I2P Anonymous Network{% endblock %} {% block content %}
Latest version:
-2012-05-02 - I2P 0.9 - {{ urlify("release-0.9", "Announcement", "html")}} +2012-05-02 - I2P 0.9 - Announcement - Download
2007-09-28 - Syndie 1.101a - diff --git a/www.i2p2/pages/not_found.html b/www.i2p2/pages/not_found.html deleted file mode 100644 index a6c2a3fd..00000000 --- a/www.i2p2/pages/not_found.html +++ /dev/null @@ -1,5 +0,0 @@ -{% extends "_layout.html" %} -{% block title %}Not found{% endblock %} -{% block content %} -Yep... the resource, you were searching for, is named differently, doesn't exist or was removed. -{% endblock %} diff --git a/www.i2p2/pages/not_found_de.html b/www.i2p2/pages/not_found_de.html deleted file mode 100644 index 42fa6929..00000000 --- a/www.i2p2/pages/not_found_de.html +++ /dev/null @@ -1,5 +0,0 @@ -{% extends "_layout_de.html" %} -{% block title %}Nicht gefunden{% endblock %} -{% block content %} -Yep... die Information nach der du suchst, nennt sich anders, existiert nicht oder wurde entfernt. -{% endblock %} diff --git a/www.i2p2/pages/not_found_zh.html b/www.i2p2/pages/not_found_zh.html deleted file mode 100644 index 95b66982..00000000 --- a/www.i2p2/pages/not_found_zh.html +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "_layout_zh.html" %} -{% block title %} -未找到 -{% endblock %} -{% block content %} -您搜索的页面或资源的名称不正确或不存在或已被删除。 -{% endblock %} \ No newline at end of file