Improve feed page
This commit is contained in:
@ -451,20 +451,18 @@ def create_html_for_feed(entries: Iterable[Entry]) -> str:
|
|||||||
|
|
||||||
entry_id: str = urllib.parse.quote(entry.id)
|
entry_id: str = urllib.parse.quote(entry.id)
|
||||||
to_disord_html: str = f"<a class='text-muted' href='/post_entry?entry_id={entry_id}'>Send to Discord</a>"
|
to_disord_html: str = f"<a class='text-muted' href='/post_entry?entry_id={entry_id}'>Send to Discord</a>"
|
||||||
|
image_html: str = f"<img src='{first_image}' class='img-fluid' alt='{first_image_text}'>" if first_image else ""
|
||||||
|
|
||||||
html += f"""
|
html += f"""<div class="p-2 mb-2 border border-dark">
|
||||||
<div class="p-2 mb-2 border border-dark">
|
{blacklisted}{whitelisted}<a class="text-muted text-decoration-none" href="{entry.link}"><h2>{entry.title}</h2></a>
|
||||||
{blacklisted}
|
|
||||||
{whitelisted}
|
|
||||||
|
|
||||||
<a class="text-muted text-decoration-none" href="{entry.link}"><h2>{entry.title}</h2></a>
|
|
||||||
|
|
||||||
{f"By { entry.author } @" if entry.author else ""}{published} - {to_disord_html}
|
{f"By { entry.author } @" if entry.author else ""}{published} - {to_disord_html}
|
||||||
|
|
||||||
{text}
|
{text}
|
||||||
{f"<img src='{first_image}' class='img-fluid' alt='{first_image_text}'>" if first_image else ""}
|
{image_html}
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
return html
|
|
||||||
|
return html.strip()
|
||||||
|
|
||||||
|
|
||||||
@app.get("/webhooks", response_class=HTMLResponse)
|
@app.get("/webhooks", response_class=HTMLResponse)
|
||||||
|
@ -52,9 +52,9 @@ def convert_html_to_md(html: str) -> str:
|
|||||||
for tag in soup.find_all(True):
|
for tag in soup.find_all(True):
|
||||||
tag.replace_with(tag.text)
|
tag.replace_with(tag.text)
|
||||||
|
|
||||||
# If the text ends with a newline, remove it
|
# Remove all leading and trailing whitespace
|
||||||
# return soup.text[:-1] if soup.text.endswith("\n") else soup.text
|
soup_text = soup.text
|
||||||
return soup.text
|
return soup_text.strip()
|
||||||
|
|
||||||
|
|
||||||
# Test the function
|
# Test the function
|
||||||
|
@ -38,5 +38,7 @@
|
|||||||
<a class="text-muted" href="/custom?feed_url={{ feed.url|encode_url }}">Custom message</a>
|
<a class="text-muted" href="/custom?feed_url={{ feed.url|encode_url }}">Custom message</a>
|
||||||
</div>
|
</div>
|
||||||
{# HTML is created in main.create_html_for_feed #}
|
{# HTML is created in main.create_html_for_feed #}
|
||||||
|
<pre>
|
||||||
{{ html|safe }}
|
{{ html|safe }}
|
||||||
|
</pre>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
Reference in New Issue
Block a user