Shortlinks for blog posts

This commit is contained in:
str4d
2015-05-28 21:48:16 +00:00
parent 54a58794fc
commit 9bf4f790ab
5 changed files with 34 additions and 1 deletions

View File

@ -43,6 +43,11 @@ with this suffix will be visible at their post URL, but will not be shown in
the blog index. To publish the draft post, change the filename to remove the
'.draft' suffix.
Creating shortlinks
-------------------
See the comments in shortlinks.py.
How to make a release notice
----------------------------

View File

@ -0,0 +1,12 @@
############
# Shortlinks
#
# To create the URL https://geti2p.net/b/<shortlink>
# linking to https://geti2p.net/en/blog/post/<slug>,
# add a new line below containing
#
# '<shortlink>': '<slug>',
BLOG_SHORTLINKS = {
'toronto': '2015/05/25/Toronto-Meetup',
}

View File

@ -1,8 +1,9 @@
from flask import abort, render_template, request
from flask import abort, g, redirect, render_template, request, url_for
from werkzeug.contrib.atom import AtomFeed
from i2p2www import BLOG_DIR, BLOG_POSTS_PER_FEED, BLOG_POSTS_PER_PAGE, cache
from i2p2www.blog.helpers import get_blog_posts, get_blog_feed_items, get_date_from_slug, get_metadata_from_meta, render_blog_post
from i2p2www.blog.shortlinks import BLOG_SHORTLINKS
from i2p2www.helpers import Pagination, get_for_page
@ -38,6 +39,19 @@ def blog_post(slug):
else:
abort(404)
@cache.memoize(600)
def blog_post_shortlink(shortlink):
lang = 'en'
if hasattr(g, 'lang') and g.lang:
lang = g.lang
try:
slug = BLOG_SHORTLINKS[shortlink]
except KeyError:
abort(404)
return redirect(url_for('blog_post', lang=lang, slug=slug))
def blog_rss():
# TODO: implement
pass

View File

@ -5,6 +5,7 @@
{%- else -%}{{ url_for('blog_index', lang=lang) }}
{%- endif -%}
{%- elif request.endpoint == 'blog_post' -%}{{ url_for('blog_post', lang=lang, slug=slug) }}
{%- elif request.endpoint == 'blog_post_shortlink' -%}{{ url_for('blog_post_shortlink', lang=lang, shortlink=shortlink) }}
{%- elif request.endpoint == 'meetings_show' -%}{{ url_for('meetings_show', lang=lang, id=id) }}
{%- elif request.endpoint == 'downloads_debian' -%}{{ url_for('downloads_debian', lang=lang) }}
{%- elif request.endpoint == 'downloads_select' -%}{{ url_for('downloads_select', lang=lang, version=version, file=file) }}

View File

@ -59,6 +59,7 @@ url('/<lang:lang>/blog/post/<path:slug>', 'blog.views.blog_post')
url('/<lang:lang>/feed/blog/rss', 'blog.views.blog_rss')
url('/<lang:lang>/feed/blog/atom', 'blog.views.blog_atom')
url('/<lang:lang>/feed/blog/category/<string:category>/atom', 'blog.views.blog_atom')
url('/b/<string:shortlink>', 'blog.views.blog_post_shortlink')
url('/<lang:lang>/meetings/', 'meetings.views.meetings_index', defaults={'page': 1})
url('/<lang:lang>/meetings/page/<int:page>', 'meetings.views.meetings_index')