From: Michael Tremer Date: Wed, 4 Mar 2026 16:38:51 +0000 (+0000) Subject: blog: Refactor the index page X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1da30daaa2a916fc75e20584785496c192edbc66;p=ipfire.org.git blog: Refactor the index page Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 9ebe2409..c13a9f9d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -186,7 +186,8 @@ templates_blog_messagesdir = $(templates_blogdir)/messages templates_blog_modules_DATA = \ src/templates/blog/modules/history-navigation.html \ - src/templates/blog/modules/list.html + src/templates/blog/modules/list.html \ + src/templates/blog/modules/tag.html templates_blog_modulesdir = $(templates_blogdir)/modules diff --git a/src/backend/blog.py b/src/backend/blog.py index 597b6308..1f3ee13e 100644 --- a/src/backend/blog.py +++ b/src/backend/blog.py @@ -307,7 +307,7 @@ class Post(misc.Object): @property def excerpt(self): - paragraphs = self.plaintext.split("\n\n") + paragraphs = self.text.replace("\r", "").split("\n\n") excerpt = [] diff --git a/src/templates/blog/index.html b/src/templates/blog/index.html index 71d16530..2f336fbe 100644 --- a/src/templates/blog/index.html +++ b/src/templates/blog/index.html @@ -13,27 +13,20 @@ {% end %} {% block container %} -
+
- +

+ IPFire Blog +

-

{{ _("IPFire Blog") }}

- - {% if q %} -
+
+ {% if q %} {{ _("Search Results for '%s'") % q }} -
- {% end %} + {% else %} + Releases, security updates, and stories from the IPFire community + {% end %} +
@@ -41,35 +34,17 @@
-
- {% if latest_post %} -
-

- - {{ _("Latest: %s") % latest_post.title }} - -

- -
- {{ latest_post.excerpt }} -
- -

- {{ _("Read More") }} -

-
- {% end %} - +
{% if q and not posts %}
{{ _("No Results Found For '%s'") % q }}
{% end %} - {% module BlogList(posts, relative=True) %} + {% module BlogList(posts, latest=latest_post) %}
-
+
{# Show a button to sign up for anonymous users #} {% if not current_user %}
diff --git a/src/templates/blog/modules/history-navigation.html b/src/templates/blog/modules/history-navigation.html index 0d82502c..fce3dee2 100644 --- a/src/templates/blog/modules/history-navigation.html +++ b/src/templates/blog/modules/history-navigation.html @@ -1,13 +1,23 @@ -
-
-
- {{ _("Archive") }} -
+ diff --git a/src/templates/blog/modules/list.html b/src/templates/blog/modules/list.html index 33ba7bf8..99e8fa66 100644 --- a/src/templates/blog/modules/list.html +++ b/src/templates/blog/modules/list.html @@ -1,23 +1,80 @@ {% for post in posts %} -

-

- - {{ post.title }} - -
- -
- {% if post.published_at %} - {{ locale.format_date(post.published_at, shorter=True, relative=relative) }} - {% elif post.created_at %} - {{ _("Created %s") % locale.format_date(post.created_at, shorter=True, relative=True) }} - {% end %} + {# Highlight the latest post #} + {% set highlighted = (post == latest) %} - {% if "lightningwirelabs.com" in post.tags %} - {{ _("by Lightning Wire Labs") }} - {% elif show_author and post.author %} - {{ _("by %s") % post.author }} +
+
+ {% if highlighted %} +

+ {{ _("Latest Post") }} +

+ {% else %} + {% module BlogTag(post) %} {% end %} -
-

+ +
+ + + {% if not highlighted and post.published_at %} +
+
+ + {{ locale.format_date(post.published_at, shorter=True, relative=False) }} + +
+
+ {% end %} +
+ +
+ {% module Markdown(post.excerpt) %} +
+ +
+
+
+ + {% if "lightningwirelabs.com" in post.tags %} + + {{ _("by Lightning Wire Labs") }} + + {% elif show_author and post.author %} + + + {% module Avatar(post.author, size=24) %} + + + + {{ post.author }} + + + {% end %} + +
+ + {% if highlighted %} + {% if post.published_at %} +
+ + {{ locale.format_date(post.published_at, shorter=True, relative=True) }} + +
+ {% end %} + +
+ {% module BlogTag(post) %} +
+ {% end %} +
+
+
+ {% end %} diff --git a/src/templates/blog/modules/tag.html b/src/templates/blog/modules/tag.html new file mode 100644 index 00000000..4da796d2 --- /dev/null +++ b/src/templates/blog/modules/tag.html @@ -0,0 +1,19 @@ +
+ {% if "release" in post.tags %} + + {{ _("Release") }} + + {% elif "testing" in post.tags %} + + {{ _("Testing") }} + + {% elif "security" in post.tags %} + + {{ _("Security") }} + + {% elif "community" in post.tags %} + + {{ _("Community") }} + + {% end %} +
diff --git a/src/web/__init__.py b/src/web/__init__.py index c89b1efb..2397379b 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -78,6 +78,7 @@ class Application(tornado.web.Application): # Blog "BlogHistoryNavigation": blog.HistoryNavigationModule, "BlogList" : blog.ListModule, + "BlogTag" : blog.TagModule, # Boot "BootMenuConfig" : boot.MenuConfigModule, diff --git a/src/web/blog.py b/src/web/blog.py index 9c2bb071..453de7d2 100644 --- a/src/web/blog.py +++ b/src/web/blog.py @@ -24,7 +24,8 @@ class IndexHandler(base.AnalyticsMixin, base.BaseHandler): posts = self.backend.blog.get_newest(limit=10) # Extract the latest post - latest_post = posts.pop(0) + if posts: + latest_post = posts[0] self.render("blog/index.html", q=q, posts=posts, latest_post=latest_post) @@ -237,6 +238,11 @@ class HistoryNavigationModule(ui_modules.UIModule): class ListModule(ui_modules.UIModule): - def render(self, posts, relative=False, show_author=True): + def render(self, posts, latest=None, show_author=True): return self.render_string("blog/modules/list.html", - posts=posts, relative=relative, show_author=show_author) + posts=posts, latest=latest, show_author=show_author) + + +class TagModule(ui_modules.UIModule): + def render(self, post): + return self.render_string("blog/modules/tag.html", post=post)