Skip to content

Commit

Permalink
Rename content_md to content in models (#28)
Browse files Browse the repository at this point in the history
* Rename content_md to content in models

* Delete multilines on Django templates

---------

Co-authored-by: Clément <[email protected]>
  • Loading branch information
ClmntBcqt and Clément authored Jul 8, 2024
1 parent 898496b commit 72281c2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
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 %}
13 changes: 5 additions & 8 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 @@ -68,17 +68,14 @@ def content_md(self) -> str:
# multiline text
# easy to read"
# }}}
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)

# 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 +89,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 +98,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 72281c2

Please sign in to comment.