Skip to content

Commit

Permalink
Fix boolean-ish logic for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
parente committed Dec 26, 2024
1 parent 9513676 commit d0e96df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@


class Page(TypedDict):
"""A page on the site."""
"""A page on the site.
Reminder: All types are parsed as strings by python-markdown.
"""

# Allow comments on the page
allow_comments: NotRequired[bool]
allow_comments: NotRequired[str | bool]
# Author of the page, if different from SITE_AUTHOR
author: NotRequired[str]
# Brief introductory comment above the start of a page *in HTML*
Expand All @@ -52,7 +55,7 @@ class Page(TypedDict):
# The next page in chronological series of pages
next: "Page"
# Flag to skip rendering the page
skip: NotRequired[bool]
skip: NotRequired[str | bool]
# The URL slug of the page
slug: str
# The path containing the source document of the page
Expand Down Expand Up @@ -202,6 +205,12 @@ def execute(self, path: str, page: Page):
page["excerpt"] = self._build_excerpt(text)
if "allow_comments" not in page:
page["allow_comments"] = True
else:
page["allow_comments"] = page["allow_comments"].lower() in (
"true",
"yes",
"1",
)
page["src"] = path
page["slug"] = self._build_page_slug(page)
page["html"] = html
Expand Down
2 changes: 1 addition & 1 deletion templates/page.mako
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</%block>

<%block name="pageMeta">
% if 'allow_comments' in page:
% if page['allow_comments']:
<div class="footerSection" id="userComments">
<script src="https://utteranc.es/client.js"
repo="parente/blog"
Expand Down

0 comments on commit d0e96df

Please sign in to comment.