From a897e201ba7a3035b3b45a6105c8eeb46f315706 Mon Sep 17 00:00:00 2001 From: Tobias Johansson Date: Thu, 22 Nov 2018 14:39:25 +0100 Subject: [PATCH] Timeline Fix: Attachment in post did not work --- pillar/api/timeline.py | 15 +++++++++++++++ src/scripts/js/es6/common/templates/posts.js | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pillar/api/timeline.py b/pillar/api/timeline.py index 602275e5..a4271223 100644 --- a/pillar/api/timeline.py +++ b/pillar/api/timeline.py @@ -8,6 +8,8 @@ import bson import pymongo from flask import Blueprint, current_app, request, url_for +import pillar +from pillar import shortcodes from pillar.api.utils import jsonify, pretty_duration, str2id from pillar.web.utils import pretty_date @@ -211,6 +213,10 @@ class TimeLineBuilder: duration_seconds = node['properties'].get('duration_seconds') if duration_seconds is not None: node['properties']['duration'] = pretty_duration(duration_seconds) + if node['node_type'] == 'post': + html = _get_markdowned_html(node['properties'], 'content') + html = shortcodes.render_commented(html, context=node['properties']) + node['properties']['pretty_content'] = html return node @classmethod @@ -240,6 +246,15 @@ def _public_project_ids() -> typing.List[bson.ObjectId]: return [p['_id'] for p in result] +def _get_markdowned_html(document: dict, field_name: str) -> str: + cache_field_name = pillar.markdown.cache_field_name(field_name) + html = document.get(cache_field_name) + if html is None: + markdown_src = document.get(field_name) or '' + html = pillar.markdown.markdown(markdown_src) + return html + + @blueprint.route('/', methods=['GET']) def global_timeline(): continue_from_str = request.args.get('from') diff --git a/src/scripts/js/es6/common/templates/posts.js b/src/scripts/js/es6/common/templates/posts.js index 9f86babe..77cefa41 100644 --- a/src/scripts/js/es6/common/templates/posts.js +++ b/src/scripts/js/es6/common/templates/posts.js @@ -14,7 +14,7 @@ class Posts extends NodesFactoryInterface { content, $('
') .addClass('node-details-description mx-auto') - .html(post['properties']['_content_html']) + .html(post['properties']['pretty_content']) ); return $post;