Skip to content

Commit

Permalink
Rename content_md to content in models
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément committed Jun 28, 2024
1 parent ed4e41c commit bda91cc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion content/templates/django/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
Publié le {{ object.timestamp|date:"Y-m-d" }}.

<h1>{{ object.title }}</h1>
{{ object.content_md|safe }}
{{ object.content|safe }}
{% endblock %}
2 changes: 1 addition & 1 deletion content/templates/jinja2/page.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% extends "base.html" %}
{% block content %}{{ object.content_md|safe }}{% endblock %}
{% block content %}{{ object.content|safe }}{% endblock %}
2 changes: 1 addition & 1 deletion content/templates/jinja2/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
Publié le {{ object.timestamp.strftime("%Y-%m-%d") }}.

<h1>{{ object.title }}</h1>
{{ object.content_md|safe }}
{{ object.content|safe }}
{% endblock %}
12 changes: 6 additions & 6 deletions jssg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def __init__(self, content: str, **metadata: Mapping[str, str]) -> None:
:param content: The content (body) of the document
:param metadata: Associated metadata
"""
self.content = content
self.body = content
self.metadata = dict(metadata)
self.path = metadata["path"]
self.data = {}

@property
def content_md(self) -> str:
def content(self) -> str:
"""Render the content as markdown to html.
Note: the content will be processed by the django template engine
Expand All @@ -70,15 +70,15 @@ def content_md(self) -> str:
# }}}
def convert_case(match_obj):
return match_obj.group(2).replace("\n", " ")
self.content = re.sub("({{{TO-1-LINE)(((?!TO-1-LINE}}}).)*)(TO-1-LINE}}})", convert_case, self.content, flags=re.DOTALL)
self.body = re.sub("({{{TO-1-LINE)(((?!TO-1-LINE}}}).)*)(TO-1-LINE}}})", convert_case, self.body, flags=re.DOTALL)

# INFO - D.A. - Original code is below and is returned a markdown-based processed content
# this works only with unindented HTML templates because markdown interprets indentation
#
# Expected: allow to process both HTML and markdown content types
#
# return markdown2.markdown(
# Template(self.content).render(
# Template(self.body).render(
# Context(
# {
# "posts": sorted(
Expand All @@ -92,7 +92,7 @@ def convert_case(match_obj):
# )

if "engine" in self.metadata.keys() and self.metadata["engine"] == "jinja2" :
return engines["jinja2"].from_string(self.content).render(
return engines["jinja2"].from_string(self.body).render(
{
"posts": sorted(
Post.load_glob(), key=lambda p: p.timestamp, reverse=True
Expand All @@ -101,7 +101,7 @@ def convert_case(match_obj):
}
)
else :
return Template(self.content).render(
return Template(self.body).render(
Context(
{
"posts": sorted(
Expand Down
2 changes: 1 addition & 1 deletion jssg/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def item_title(self, post: Post) -> str:
return post.title

def item_description(self, item: Post):
return item.content_md
return item.content

def item_link(self, post: Post) -> str:
return reverse("post", args=(post.slug,))
Expand Down

0 comments on commit bda91cc

Please sign in to comment.