ORDER BY ts_rank(search_index.document, to_tsquery('english', %s)) DESC \
LIMIT %s", query, query, limit)
- def create_post(self, title, text, author, tags=[]):
+ def create_post(self, title, text, author, tags=[], lang="markdown"):
"""
Creates a new post and returns the resulting Post object
"""
- return self._get_post("INSERT INTO blog(title, slug, text, author_uid, tags) \
- VALUES(%s, %s, %s, %s, %s) RETURNING *", title, self._make_slug(title),
- text, author.uid, list(tags))
+ # Pre-render HTML
+ html = self._render_text(text, lang=lang)
+
+ return self._get_post("INSERT INTO blog(title, slug, text, html, lang, author_uid, tags) \
+ VALUES(%s, %s, %s, %s, %s, %s, %s) RETURNING *", title, self._make_slug(title), text,
+ html, lang, author.uid, list(tags))
def _make_slug(self, s):
# Remove any non-ASCII characters
slug = self.backend.blog._make_slug(title) \
if not self.is_published() and not self.title == title else self.slug
- # XXX render HTML
+ # Render and cache HTML
+ html = self.backend.blog._render_text(text, lang=self.lang)
- self.db.execute("UPDATE blog SET title = %s, slug = %s, text = %s, \
+ self.db.execute("UPDATE blog SET title = %s, slug = %s, text = %s, html = %s, \
tags = %s, updated_at = CURRENT_TIMESTAMP WHERE id = %s",
- title, slug, text, list(tags), self.id)
+ title, slug, text, html, list(tags), self.id)
# Update cache
self.data.update({