Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Content field from _all.yml files are now loaded. #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions statik/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class ContentLoadable(object):
loading content and metadata from a Markdown file.
"""
def __init__(self, filename=None, file_type=None, from_string=None, from_dict=None,
name=None, markdown_config=None, encoding='utf-8', error_context=None):
name=None, markdown_config=None, encoding='utf-8', error_context=None,
content_field=None):
self.vars = None
self.content = None
self.file_content = None
Expand Down Expand Up @@ -102,7 +103,6 @@ def __init__(self, filename=None, file_type=None, from_string=None, from_dict=No
"filename", "from_string", "from_dict",
context=self.error_context
)

if name is not None:
self.name = name
elif self.filename is not None:
Expand All @@ -112,7 +112,27 @@ def __init__(self, filename=None, file_type=None, from_string=None, from_dict=No
"name", "filename",
context=self.error_context
)

markdown_ext = [
MarkdownYamlMetaExtension(),
MarkdownLoremIpsumExtension(error_context=self.error_context)
]
if self.markdown_config:
if self.markdown_config.enable_permalinks:
markdown_ext.append(
MarkdownPermalinkExtension(
permalink_text=self.markdown_config.permalink_text,
permalink_class=self.markdown_config.permalink_class,
permalink_title=self.markdown_config.permalink_title,
)
)
markdown_ext.extend(self.markdown_config.extensions)
markdown_ext_configs = self.markdown_config.extension_config
else:
markdown_ext_configs = None
md = Markdown(
extensions=markdown_ext,
extension_configs=markdown_ext_configs
)
# if it wasn't loaded from a dictionary
if self.vars is None:
if self.file_type is None:
Expand All @@ -127,26 +147,11 @@ def __init__(self, filename=None, file_type=None, from_string=None, from_dict=No
if not isinstance(self.vars, dict):
self.vars = {}
else:
markdown_ext = [
MarkdownYamlMetaExtension(),
MarkdownLoremIpsumExtension(error_context=self.error_context)
]
if self.markdown_config.enable_permalinks:
markdown_ext.append(
MarkdownPermalinkExtension(
permalink_text=self.markdown_config.permalink_text,
permalink_class=self.markdown_config.permalink_class,
permalink_title=self.markdown_config.permalink_title,
)
)
markdown_ext.extend(self.markdown_config.extensions)

md = Markdown(
extensions=markdown_ext,
extension_configs=self.markdown_config.extension_config
)
self.content = md.convert(self.file_content)
self.vars = md.meta
else:
if (content_field is not None) and (content_field in self.vars):
self.content = md.convert(self.vars[content_field])

if isinstance(self.vars, dict):
self.vars = dict_strip(self.vars)
3 changes: 2 additions & 1 deletion statik/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ def shutdown(self):
class StatikDatabaseInstance(ContentLoadable):

def __init__(self, model=None, session=None, **kwargs):
super(StatikDatabaseInstance, self).__init__(**kwargs)
super(StatikDatabaseInstance, self).__init__(content_field=model.content_field,
**kwargs)
if model is None:
raise MissingParameterError("model", context=self.error_context)
self.model = model
Expand Down