1/2 of blog implementation done!
This commit is contained in:
94
app.py
94
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('/<string:lang>/site/')
|
||||
@app.route('/<string:lang>/site/<path:page>')
|
||||
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('/<string:lang>/meetings/')
|
||||
def meetings_index():
|
||||
@@ -131,8 +152,8 @@ def meetings_show_rst(id):
|
||||
|
||||
@app.route('/<string:lang>/download')
|
||||
def downloads_list():
|
||||
# TODO: implement
|
||||
pass
|
||||
# TODO: read mirror list or list of available files
|
||||
return render_template('downloads/list.html')
|
||||
|
||||
@app.route('/<string:lang>/download/<path:file>')
|
||||
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('/<string:lang>/blog/')
|
||||
@app.route('/<string:lang>/blog/page/<int:page>')
|
||||
def blog_index(page=0):
|
||||
@@ -153,8 +196,15 @@ def blog_index(page=0):
|
||||
|
||||
@app.route('/<string:lang>/blog/entry/<path:slug>')
|
||||
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('/<string:f>_<string:lang>')
|
||||
@app.route('/<string:f>_<string:lang>.html')
|
||||
@app.route('/<string:f>')
|
||||
@app.route('/<string:f>.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)
|
||||
|
@@ -1,7 +1,5 @@
|
||||
{% extends "_layout.html" %}
|
||||
{% block title %}I2P Status Notes for 2006-10-10{% endblock %}
|
||||
{% block content %}<h3>I2P Status Notes for 2006-10-10</h3>
|
||||
<pre>-----BEGIN PGP SIGNED MESSAGE-----
|
||||
<pre>
|
||||
-----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-----
|
||||
|
||||
|
||||
</pre>
|
||||
{% endblock %}
|
6
blog/2006/10/10/status.rst
Normal file
6
blog/2006/10/10/status.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
===============================
|
||||
I2P STATUS NOTES FOR 2006-10-10
|
||||
===============================
|
||||
|
||||
.. raw:: html
|
||||
:file: blog/2006/10/10/status.html
|
@@ -1,4 +1,4 @@
|
||||
{% extends "_layout.html" %}
|
||||
{% extends "global/layout.html" %}
|
||||
{% block title %}Download{% endblock %}
|
||||
{% block content %}
|
||||
<h1>Download I2P</h1>
|
21
pages/global/error_404.html
Normal file
21
pages/global/error_404.html
Normal file
@@ -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 %}
|
@@ -1,7 +1,9 @@
|
||||
{% macro urlify(url, title, suffix) %}
|
||||
{% autoescape false %}
|
||||
{% if static %}
|
||||
<a href="{{url}}.{{suffix}}">{{title}}</a>
|
||||
{% else %}
|
||||
<a href="{{url}}">{{title}}</a>
|
||||
{% endif %}
|
||||
{% endautoescape %}
|
||||
{% endmacro %}
|
@@ -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 %}
|
||||
<table cellspacing="10" class="announce"><tr class="announce"><td valign="top" class="announce">
|
||||
<div class="version">
|
||||
<b>Latest version:</b><div class="underline"></div>
|
||||
2012-05-02 - <strong>I2P 0.9</strong> - {{ urlify("release-0.9", "Announcement", "html")}}
|
||||
2012-05-02 - <strong>I2P 0.9</strong> - <a href="{{ url_for('site_show', page='release-0.9') }}">Announcement</a>
|
||||
- <a href="download">Download</a><br /><div class="underline"></div>
|
||||
2007-09-28 - <strong>Syndie 1.101a</strong> -
|
||||
<!-- <a href="http://dev.i2p.net/pipermail/i2p/2007-September/001355.html">Announcement</a> -->
|
@@ -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 %}
|
@@ -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 %}
|
@@ -1,7 +0,0 @@
|
||||
{% extends "_layout_zh.html" %}
|
||||
{% block title %}
|
||||
未找到
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
您搜索的页面或资源的名称不正确或不存在或已被删除。
|
||||
{% endblock %}
|
Reference in New Issue
Block a user