Skip to content

Commit

Permalink
Fulcrum: render excerpt as sub-headline [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
ping committed Jun 14, 2023
1 parent 757b41e commit 7477f7c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions recipes/fulcrum-sg.recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class FulcrumSg(WordPressNewsrackRecipe, BasicNewsRecipe):

extra_css = """
.headline { font-size: 1.8rem; margin-bottom: 0.4rem; }
.sub-headline { font-size: 1.2rem; font-style: italic; margin-bottom: 1rem; }
.sub-headline p { margin: 0; }
.article-meta { margin-top: 1rem; margin-bottom: 1rem; }
.article-meta .author { font-weight: bold; color: #444; margin-right: 0.5rem; }
.article-section { display: block; font-weight: bold; color: #444; }
Expand All @@ -50,7 +52,6 @@ class FulcrumSg(WordPressNewsrackRecipe, BasicNewsRecipe):
font-size: 0.8rem; display: block; margin-top: 0.2rem;
}
.caption p { margin-top: 0; }
.article-excerpt { font-size: 1.25rem; font-style: italic; }
.block--pullout-stat, .block--accordion { margin-left: 0.5rem; font-family: monospace; text-align: left; }
.block--pullout-stat .block--pullout-stat__title,
Expand Down Expand Up @@ -82,11 +83,6 @@ def _extract_featured_media(self, post, soup):
if not post.get("featured_media"):
return post_content

if post.get("excerpt", {}).get("rendered"):
container_ele = soup.new_tag("div", attrs={"class": "article-excerpt"})
container_ele.append(BeautifulSoup(post["excerpt"]["rendered"]))
post_content = str(container_ele) + post_content

feature_media_css = f"wp-image-{post['featured_media']}"
if feature_media_css in post_content:
# check already not embedded
Expand Down Expand Up @@ -129,6 +125,7 @@ def preprocess_raw_html(self, raw_html, url):
<article data-og-link="{post["link"]}">
{f'<span class="article-section">{" / ".join(categories)}</span>' if categories else ''}
<h1 class="headline">{post["title"]["rendered"]}</h1>
<h2 class="sub-headline"></h2>
<div class="article-meta">
{f'<span class="author">{", ".join(post_authors)}</span>' if post_authors else ''}
<span class="published-dt">
Expand All @@ -138,6 +135,14 @@ def preprocess_raw_html(self, raw_html, url):
</article>
</body></html>"""
)
sub_headline = soup.find("h2", class_="sub-headline")
if post.get("excerpt", {}).get("rendered"):
sub_headline.append(
BeautifulSoup(post["excerpt"]["rendered"], "html.parser")
)
else:
sub_headline.decompose()

soup.body.article.append(
BeautifulSoup(self._extract_featured_media(post, soup))
)
Expand Down

0 comments on commit 7477f7c

Please sign in to comment.