From: Michael Tremer Date: Mon, 28 Dec 2020 19:23:34 +0000 (+0000) Subject: blog: Shorten index page and add more navigation X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=feb245e0ec2761a8408d05d24d1d34b5a14be9c1;p=ipfire.org.git blog: Shorten index page and add more navigation Signed-off-by: Michael Tremer --- diff --git a/src/backend/blog.py b/src/backend/blog.py index b92b0276..63d90463 100644 --- a/src/backend/blog.py +++ b/src/backend/blog.py @@ -163,6 +163,29 @@ class Blog(misc.Object): for row in res: yield row.year + @property + def authors(self): + res = self.db.query(""" + SELECT + author_uid, + MAX(published_at) AS published_at + FROM + blog + WHERE + author_uid IS NOT NULL + AND + published_at IS NOT NULL + AND + published_at <= NOW() + GROUP BY + author_uid + ORDER BY + published_at DESC + """, + ) + + return [self.backend.accounts.get_by_uid(row.author_uid) for row in res] + async def announce(self): posts = self._get_posts("SELECT * FROM blog \ WHERE (published_at IS NOT NULL AND published_at <= NOW()) \ diff --git a/src/templates/blog/author.html b/src/templates/blog/author.html index 75a0d734..a7fb94f8 100644 --- a/src/templates/blog/author.html +++ b/src/templates/blog/author.html @@ -27,7 +27,7 @@

{{ _("Posts") }}

- {% module BlogList(posts) %} + {% module BlogList(posts, show_author=True) %}
{% end block %} diff --git a/src/templates/blog/index.html b/src/templates/blog/index.html index adff7208..d11f7f03 100644 --- a/src/templates/blog/index.html +++ b/src/templates/blog/index.html @@ -6,6 +6,18 @@ {% end %} -{% block main %} - {% module BlogPosts(posts) %} +{% block container %} +
+
+

{{ _("IPFire Blog") }}

+
+
+ +
+
+ {% module BlogList(posts, relative=True) %} +
+ + {% module BlogHistoryNavigation() %} +
{% end block %} diff --git a/src/templates/blog/modules/history-navigation.html b/src/templates/blog/modules/history-navigation.html index 1ff45de3..96b3c188 100644 --- a/src/templates/blog/modules/history-navigation.html +++ b/src/templates/blog/modules/history-navigation.html @@ -1,14 +1,34 @@ -

{{ _("History") }}

- - +
{{ _("Read More") }}
+ +
{{ _("Authors") }}
+ +
+ {% for account in authors %} + + {% end %} +
+ +
{{ _("Years") }}
+ + diff --git a/src/templates/blog/modules/list.html b/src/templates/blog/modules/list.html index 4b210d02..b874f89b 100644 --- a/src/templates/blog/modules/list.html +++ b/src/templates/blog/modules/list.html @@ -1,12 +1,15 @@ {% for post in posts %} - - {{ post.title }} - +
+ {{ post.title }} +
+

- {{ locale.format_date(post.published_at, shorter=True, relative=False) }} + {{ locale.format_date(post.published_at, shorter=True, relative=relative) }} {% if "lightningwirelabs.com" in post.tags %} {{ _("by Lightning Wire Labs") }} + {% elif show_author and post.author %} + {{ _("by %s") % post.author }} {% end %}

{% end %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 32bade61..9d87c7ea 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -124,6 +124,7 @@ class Application(tornado.web.Application): (r"/blog/feed.xml", blog.FeedHandler), (r"/blog/search", blog.SearchHandler), (r"/blog/tags/([0-9a-z\-\.]+)", blog.TagHandler), + (r"/blog/years/([0-9]{4})", blog.YearHandler), (r"/blog/([0-9a-z\-\._]+)", blog.PostHandler), (r"/blog/([0-9a-z\-\._]+)/delete", blog.DeleteHandler), (r"/blog/([0-9a-z\-\._]+)/edit", blog.EditHandler), diff --git a/src/web/blog.py b/src/web/blog.py index ff90bdd0..3ae550a1 100644 --- a/src/web/blog.py +++ b/src/web/blog.py @@ -11,7 +11,7 @@ from . import ui_modules class IndexHandler(auth.CacheMixin, base.BaseHandler): def get(self): - posts = self.backend.blog.get_newest(limit=3) + posts = self.backend.blog.get_newest(limit=10) # Allow this to be cached for 5 minutes if not self.current_user: @@ -245,12 +245,13 @@ class DeleteHandler(auth.CacheMixin, base.BaseHandler): class HistoryNavigationModule(ui_modules.UIModule): def render(self): return self.render_string("blog/modules/history-navigation.html", - years=self.backend.blog.years) + authors=self.backend.blog.authors, years=self.backend.blog.years) class ListModule(ui_modules.UIModule): - def render(self, posts): - return self.render_string("blog/modules/list.html", posts=posts) + def render(self, posts, relative=False, show_author=True): + return self.render_string("blog/modules/list.html", + posts=posts, relative=relative, show_author=show_author) class PostModule(ui_modules.UIModule):