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:
@@ -47,3 +47,11 @@ def markdown(s):
|
||||
attributes=ALLOWED_ATTRIBUTES,
|
||||
styles=ALLOWED_STYLES)
|
||||
return safe_html
|
||||
|
||||
|
||||
def cache_field_name(field_name: str) -> str:
|
||||
"""Return the field name containing the cached HTML.
|
||||
|
||||
See ValidateCustomFields._normalize_coerce_markdown().
|
||||
"""
|
||||
return f'_{field_name}_html'
|
||||
|
Reference in New Issue
Block a user