feat: Add static rendering for article pages

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2025-12-04 18:01:00 +00:00
parent 7c600dcfba
commit 32cbf47d95
2 changed files with 51 additions and 15 deletions

View File

@@ -171,9 +171,9 @@ def static_story(sid):
except NotFound:
pass
story = database.get_story(sid)
if not story: return abort(404)
story = json.loads(story.full_json)
story_obj = database.get_story(sid)
if not story_obj: return abort(404)
story = json.loads(story_obj.full_json)
score = story['score']
num_comments = story['num_comments']
@@ -182,7 +182,7 @@ def static_story(sid):
score, 's' if score != 1 else '',
num_comments, 's' if num_comments != 1 else '',
source)
url = urlparse(story['url']).hostname or urlparse(story['link']).hostname or ''
url = urlparse(story.get('url') or story.get('link') or '').hostname or ''
url = url.replace('www.', '')
return render_template('index.html',
@@ -190,6 +190,8 @@ def static_story(sid):
url=url,
description=description,
robots='noindex',
story=story,
show_comments=request.path.endswith('/c'),
)
http_server = WSGIServer(('', 33842), flask_app)

View File

@@ -46,18 +46,52 @@
<body>
<div class="nojs">
<noscript>
You need to enable JavaScript to run this app because it's written in React.
I was planning on writing a server-side version, but I've become distracted
by other projects -- sorry!
<br/>
I originally wrote this for myself, and of course I whitelist JavaScript on
all my own domains.
<br/><br/>
Alternatively, try activex.news.t0.vc for an ActiveX™ version.
</noscript>
<noscript></noscript>
</div>
<div id="root">
{% if story %}
<div class="container article">
<div class="header">
{% if show_comments %}
<h1>{{ story.title }}</h1>
{% else %}
<h1><a href="{{ story.url or story.link }}">{{ story.title }}</a></h1>
{% endif %}
<div class="info">
{{ story.score }} points
by <a href="{{ story.author_link }}">{{ story.author }}</a>
on <a href="{{ story.link }}">{{ story.source }}</a> |
<a href="/{{ story.id }}/c">
{{ story.num_comments }} comment{{ 's' if story.num_comments != 1 }}
</a>
</div>
<div class='dot toggleDot'>
<div class='button'>
<a href="/{{ story.id }}{{ '/c' if not show_comments else '' }}">
{{ '' if not show_comments else '' }}
</a>
</div>
</div>
</div>
{% if not show_comments %}
<div class="text">{{ story.text | safe }}</div>
{% else %}
{% macro render_comment(comment, level) %}
<div class="comment" style="margin-left: {{ level * 20 }}px">
<div class="c-info"><a href="{{ comment.author_link }}">{{ comment.author }}</a></div>
<div class="c-text">{{ comment.text | safe }}</div>
{% for reply in comment.comments %}
{{ render_comment(reply, level + 1) }}
{% endfor %}
</div>
{% endmacro %}
<div class="comments">
{% for comment in story.comments %}{{ render_comment(comment, 0) }}{% endfor %}
</div>
{% endif %}
</div>
{% endif %}
</div>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.