diff --git a/blog.ini b/blog.ini index 7ead0a7..7a923c0 100755 --- a/blog.ini +++ b/blog.ini @@ -8,7 +8,7 @@ uid = http gid = http master = true -processes = 5 +processes = 7 socket = /tmp/blog.sock chown-socket = http:http diff --git a/blog.service b/blog.service index 0f5bc4c..d50660e 100644 --- a/blog.service +++ b/blog.service @@ -6,7 +6,7 @@ After=network.target User=http Group=http WorkingDirectory=/srv/http/riotblog -ExecStart=/usr/bin/uwsgi --ini /srv/http/riotblog/blog.ini +ExecStart=/usr/bin/uwsgi --single-interpreter --ini /srv/http/riotblog/blog.ini Environment="RIOTBLOG_SETTINGS=/srv/http/riotblog/riotblog_prod.cfg" [Install] diff --git a/requirements.txt b/requirements.txt index 035e928..05a41da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,6 +23,7 @@ Jinja2==2.9.4 lxml==3.7.2 MarkupSafe==0.23 marshmallow==2.13.5 +mistune==0.7.4 packaging==16.8 paramiko==2.1.1 pbr==1.10.0 @@ -34,6 +35,7 @@ python-dateutil==2.6.0 python-memcached==1.58 pyxdg==0.25 requests==2.18.3 +simplejson==3.11.1 six==1.10.0 stevedore==1.20.0 urllib3==1.22 diff --git a/src/posts.py b/src/posts.py index 5f88687..0000472 100644 --- a/src/posts.py +++ b/src/posts.py @@ -1,11 +1,21 @@ #! /usr/bin/python import couchdb +import mistune +from werkzeug.local import Local, LocalProxy, LocalManager from couchdb.http import ResourceConflict, ResourceNotFound -from flask import jsonify +from flask import jsonify, g from flask_marshmallow import Marshmallow +def get_mistune(): + markdown = getattr(g, "markdown", None) + if markdown is None: + markdown = g._markdown = mistune.Markdown() + return markdown + +markdown = LocalProxy(get_mistune) + class Posts: def __init__(self, user, password, host=None, port=None): if host is None: @@ -41,11 +51,19 @@ class Posts: results = self.db.iterview("blogPosts/blog-posts", 1, include_docs=True, startkey=_id) post = [result.doc for result in results][0] + + post["content"] = markdown(post["content"]) + return jsonify(post) if json else post def getinitial(self): results = list(self.db.iterview("blogPosts/blog-posts", 2, include_docs=True)) - return [result.doc for result in results][0] + + post = [result.doc for result in results][0] + + post["content"] = markdown(post["content"]) + + return post def iterpost(self, endkey=False, startkey=False, category="programming"): if startkey and not endkey: @@ -55,22 +73,25 @@ class Posts: else: results = self.db.iterview("blogPosts/blog-posts", 2, include_docs=True) - doc_ids = [result.doc for result in results] + docs = [result.doc for result in results] + + for doc in docs: + doc["content"] = markdown(doc["content"]) - if not doc_ids: + if not docs: return jsonify("end") if endkey and not startkey: - if len(doc_ids) < 2 or doc_ids[0] == endkey: + if len(docs) < 2 or docs[0] == endkey: return jsonify("start") - return jsonify(doc_ids[-2]) + return jsonify(docs[-2]) - if len(doc_ids) == 1: - return jsonify(doc_ids[0]) + if len(docs) == 1: + return jsonify(docs[0]) - if doc_ids: + if docs: # if no startkey or endkey were specified, return the 0th post - return jsonify(doc_ids[1 if startkey else 0]) + return jsonify(docs[1 if startkey else 0]) return jsonify("end") diff --git a/src/scripts/app.tag b/src/scripts/app.tag index 6d88a76..6c9e7fd 100644 --- a/src/scripts/app.tag +++ b/src/scripts/app.tag @@ -27,7 +27,7 @@ class="mobile-menu tab tab-block menu">