Highlight OP comment
This commit is contained in:
parent
1b4d734ae0
commit
1ecec6d3f6
@ -151,6 +151,14 @@ h1 {
|
|||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.op {
|
||||||
|
background: #0055df;
|
||||||
|
color: white;
|
||||||
|
font-weight: 700;
|
||||||
|
padding: 0px 4px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
border: 1px solid #1abc9c60;
|
border: 1px solid #1abc9c60;
|
||||||
color: #1abc9c;
|
color: #1abc9c;
|
||||||
|
17
utilities.py
17
utilities.py
@ -191,22 +191,25 @@ def create_post_page_html(post, post_html):
|
|||||||
comments_html = []
|
comments_html = []
|
||||||
post.comments.replace_more(limit=0)
|
post.comments.replace_more(limit=0)
|
||||||
for comment in post.comments:
|
for comment in post.comments:
|
||||||
comments_html.append(get_comment_html(comment))
|
comments_html.append(get_comment_html(comment, op=post.author.name))
|
||||||
html = html.replace("<!--comments-->", "\n".join(comments_html))
|
html = html.replace("<!--comments-->", "\n".join(comments_html))
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
def get_comment_html(comment, children=True):
|
def get_comment_html(comment, children=True, op=None):
|
||||||
"""Takes a post object and creates a HTML for it - it will get its children
|
"""Takes a post object and creates a HTML for it - it will get its children
|
||||||
too unless you specify otherwise."""
|
too unless you specify otherwise."""
|
||||||
|
|
||||||
with open(os.path.join("html", "comment-div.html")) as f:
|
with open(os.path.join("html", "comment-div.html")) as f:
|
||||||
html = f.read()
|
html = f.read()
|
||||||
dt = datetime.utcfromtimestamp(comment.created_utc)
|
dt = datetime.utcfromtimestamp(comment.created_utc)
|
||||||
html = html.replace(
|
author = "[deleted]"
|
||||||
"<!--user-->",
|
if comment.author:
|
||||||
f"/u/{comment.author.name}" if comment.author else "[deleted]"
|
if comment.author == op:
|
||||||
)
|
author = f'<span class="op">/u/{comment.author.name}</span>'
|
||||||
|
else:
|
||||||
|
author = f"/u/{comment.author.name}"
|
||||||
|
html = html.replace("<!--user-->", author)
|
||||||
html = html.replace("<!--body-->", comment.body_html or "")
|
html = html.replace("<!--body-->", comment.body_html or "")
|
||||||
html = html.replace("<!--score-->", str(comment.score))
|
html = html.replace("<!--score-->", str(comment.score))
|
||||||
html = html.replace("<!--link-->", f"https://reddit.com{comment.permalink}")
|
html = html.replace("<!--link-->", f"https://reddit.com{comment.permalink}")
|
||||||
@ -216,6 +219,6 @@ def get_comment_html(comment, children=True):
|
|||||||
if children:
|
if children:
|
||||||
children_html = []
|
children_html = []
|
||||||
for child in comment.replies:
|
for child in comment.replies:
|
||||||
children_html.append(get_comment_html(child, children=False))
|
children_html.append(get_comment_html(child, children=False, op=op))
|
||||||
html = html.replace("<!--children-->", "\n".join(children_html))
|
html = html.replace("<!--children-->", "\n".join(children_html))
|
||||||
return html
|
return html
|
Loading…
Reference in New Issue
Block a user