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

View File

@@ -46,18 +46,52 @@
<body> <body>
<div class="nojs"> <div class="nojs">
<noscript> <noscript></noscript>
You need to enable JavaScript to run this app because it's written in React. </div>
I was planning on writing a server-side version, but I've become distracted <div id="root">
by other projects -- sorry! {% if story %}
<br/> <div class="container article">
I originally wrote this for myself, and of course I whitelist JavaScript on <div class="header">
all my own domains. {% if show_comments %}
<br/><br/> <h1>{{ story.title }}</h1>
Alternatively, try activex.news.t0.vc for an ActiveX™ version. {% else %}
</noscript> <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>
<div id="root"></div>
<!-- <!--
This HTML file is a template. This HTML file is a template.
If you open it directly in the browser, you will see an empty page. If you open it directly in the browser, you will see an empty page.