Cache Markdown'ed HTML in database
This is done via coercion rules. To cache the field 'content' in the database, include this in your Eve schema: {'content': {'type': 'string', 'coerce': 'markdown'}, '_content_html': {'type': 'string'}} The `_content_html` field will be filled automatically when saving the document via Eve. To display the cached HTML, and fall back to display-time rendering if it is not there, use `{{ document | markdowned('content') }}` in your template. Still needs unit testing, a CLI command for regenerating the caches, and a CLI command for migrating the node type definitions in existing projects.
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
| {% if node.description %}
|
||||
.node-details-description#node-description
|
||||
| {{ node.description | markdown }}
|
||||
| {{ node | markdowned('description') }}
|
||||
| {% endif %}
|
||||
|
||||
include ../../_node_details
|
||||
|
@@ -18,7 +18,7 @@
|
||||
|
||||
| {% if node.description %}
|
||||
.node-details-description#node-description
|
||||
| {{ node.description | markdown }}
|
||||
| {{ node | markdowned('description') }}
|
||||
| {% endif %}
|
||||
|
||||
include ../../_node_details
|
||||
@@ -46,4 +46,3 @@ script.
|
||||
});
|
||||
|
||||
| {% endblock %}
|
||||
|
||||
|
@@ -46,7 +46,7 @@
|
||||
|
||||
| {% if node.description %}
|
||||
.node-details-description#node-description
|
||||
| {{ node.description | markdown }}
|
||||
| {{ node | markdowned('description') }}
|
||||
| {% endif %}
|
||||
|
||||
include ../../_node_details
|
||||
|
@@ -25,7 +25,7 @@ a.blog_index-header(href="{{ node.url }}")
|
||||
| {{ node.name }}
|
||||
|
||||
.item-content
|
||||
| {{ node.properties.content | markdown }}
|
||||
| {{ node.properties | markdowned('content') }}
|
||||
|
||||
| {% endmacro %}
|
||||
|
||||
|
@@ -11,7 +11,7 @@
|
||||
.comment-body
|
||||
p.comment-author {{ comment._user.full_name }}
|
||||
|
||||
span {{comment.properties.content_html | safe }}
|
||||
span {{comment.properties._content_html | safe }}
|
||||
|
||||
// TODO: Markdown preview when editing
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
| {% if node.description %}
|
||||
.node-details-description
|
||||
| {{ node.description | markdown }}
|
||||
| {{ node | markdowned('description') }}
|
||||
| {% endif %}
|
||||
|
||||
section.node-children.group
|
||||
|
@@ -12,7 +12,7 @@
|
||||
| {% if node.description %}
|
||||
section.node-row
|
||||
.node-details-description
|
||||
| {{ node.description | markdown }}
|
||||
| {{ node | markdowned('description') }}
|
||||
| {% endif %}
|
||||
|
||||
| {% if children %}
|
||||
|
@@ -12,7 +12,7 @@
|
||||
| {% if node.description %}
|
||||
section.node-row
|
||||
.node-details-description
|
||||
| {{ node.description | markdown }}
|
||||
| {{ node | markdowned('description') }}
|
||||
| {% endif %}
|
||||
|
||||
| {% if children %}
|
||||
|
@@ -93,7 +93,7 @@
|
||||
|
||||
| {% if node.description %}
|
||||
.node-details-description#node-description
|
||||
| {{ node.description | markdown }}
|
||||
| {{ node | markdowned('description') }}
|
||||
| {% endif %}
|
||||
|
||||
| {% if node.properties.license_notes %}
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
| {% if node.description %}
|
||||
.node-details-description#node-description
|
||||
| {{ node.description | markdown }}
|
||||
| {{ node | markdowned('description') }}
|
||||
| {% endif %}
|
||||
|
||||
.node-details-meta.footer
|
||||
|
@@ -39,7 +39,7 @@
|
||||
|
||||
| {% if project.description %}
|
||||
.node-details-description
|
||||
| {{ project.description | markdown }}
|
||||
| {{ project | markdowned('description') }}
|
||||
| {% endif %}
|
||||
|
||||
| {# Until we implement urls for pages
|
||||
@@ -84,9 +84,9 @@
|
||||
a.title(href="{{ url_for_node(node=n) }}") {{ n.name }}
|
||||
p.description(href="{{ url_for_node(node=n) }}")
|
||||
| {% if n.node_type == 'post' %}
|
||||
| {{ n.properties.content | markdown | striptags | truncate(140, end="... <small>read more</small>") | safe | hide_none }}
|
||||
| {{ n.properties | markdowned('content') | striptags | truncate(140, end="... <small>read more</small>") | safe | hide_none }}
|
||||
| {% else %}
|
||||
| {{ n.description | markdown | striptags | truncate(140, end="... <small>read more</small>") | safe | hide_none }}
|
||||
| {{ n | markdowned('description') | striptags | truncate(140, end="... <small>read more</small>") | safe | hide_none }}
|
||||
| {% endif %}
|
||||
span.details
|
||||
span.what {% if n.properties.content_type %}{{ n.properties.content_type | undertitle }}{% else %}{{ n.node_type | undertitle }}{% endif %} ·
|
||||
|
Reference in New Issue
Block a user