]> git.ipfire.org Git - ipfire.org.git/commitdiff
blog: Shorten index page and add more navigation
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Dec 2020 19:23:34 +0000 (19:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Dec 2020 19:23:34 +0000 (19:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/blog.py
src/templates/blog/author.html
src/templates/blog/index.html
src/templates/blog/modules/history-navigation.html
src/templates/blog/modules/list.html
src/web/__init__.py
src/web/blog.py

index b92b02767e3a392c67ee22de36fb9ed9b846d564..63d904630fb5eeafdfcef5c5711990ee7807aaef 100644 (file)
@@ -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()) \
index 75a0d73461e1045484f60ba79f114a0060ba2977..a7fb94f88ea0929fe13b6fbb3dd34bc9149ad780 100644 (file)
@@ -27,7 +27,7 @@
                <section>
                        <h3>{{ _("Posts") }}</h3>
 
-                       {% module BlogList(posts) %}
+                       {% module BlogList(posts, show_author=True) %}
                </section>
        </div>
 {% end block %}
index adff720804c5231d48debdc293782da35426a500..d11f7f036eda4a2fdc82b73d842886bced775b43 100644 (file)
@@ -6,6 +6,18 @@
        <meta name="description" content="{{ _("The IPFire Blog has the latest news from the IPFire Project about Development, Current Affairs, and many more interesting things.") }}" />
 {% end %}
 
-{% block main %}
-       {% module BlogPosts(posts) %}
+{% block container %}
+       <div class="header">
+               <div class="container">
+                       <h1>{{ _("IPFire Blog") }}</h1>
+               </div>
+       </div>
+
+       <div class="container">
+               <section>
+                       {% module BlogList(posts, relative=True) %}
+               </section>
+
+               {% module BlogHistoryNavigation() %}
+       </div>
 {% end block %}
index 1ff45de3e0ade7c4a056b2840617bb8a8407826a..96b3c1889208610f6114d14d8079c24c8c7aeaae 100644 (file)
@@ -1,14 +1,34 @@
-<p class="small text-uppercase text-muted ml-3">{{ _("History") }}</p>
-
-<nav class="mb-5">
-    <ul class="nav flex-column">
-
-        {% for year in years %}
-            <li class="nav-item">
-                <a class="nav-link {% if request.path == "/years/%s" % year %}active{% end %}" href="/years/{{ year }}">
-                    {{ year }}
-                </a>
-            </li>
-        {% end %}
-    </ul>
-</nav>
+<h5>{{ _("Read More") }}</h5>
+
+<h6>{{ _("Authors") }}</h6>
+
+<div class="row row-cols-1 row-cols-md-2 row-cols-lg-4">
+       {% for account in authors %}
+               <div class="col mb-4">
+                       <div class="row align-items-center">
+                               <div class="col-2 col-md-3">
+                                       <img class="img-fluid rounded-circle"
+                                               src="{{ account.avatar_url(size=64) }}">
+                               </div>
+
+                               <div class="col">
+                                       <h6 class="mb-0">
+                                               <a href="/blog/authors/{{ account.uid }}">
+                                                       {{ account.name or account.nickname }}
+                                               </a>
+                                       </h6>
+                               </div>
+                       </div>
+               </div>
+       {% end %}
+</div>
+
+<h6>{{ _("Years") }}</h6>
+
+<ul class="nav nav-pills nav-fill">
+       {% for year in years %}
+               <li class="nav-item">
+                       <a class="nav-link" href="/blog/years/{{ year }}">{{ year }}</a>
+               </li>
+       {% end %}
+</ul>
index 4b210d0245852ec0784af75f913ea6952ed49879..b874f89bf2b1b623186c29ca2a5fe045ed9b0789 100644 (file)
@@ -1,12 +1,15 @@
 {% for post in posts %}
-       <strong class="mb-0">
-               <a {% if "lightningwirelabs.com" in post.tags %}class="text-lwl"{% end %} href="/post/{{ post.slug }}">{{ post.title }}</a>
-       </strong>
+       <h6 class="mb-0">
+               <a {% if "lightningwirelabs.com" in post.tags %}class="text-lwl"{% end %} href="/blog/{{ post.slug }}">{{ post.title }}</a>
+       </h6>
+
        <p class="text-muted small">
-               {{ 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 %}
                        <span class="text-lwl">{{ _("by Lightning Wire Labs") }}</span>
+               {% elif show_author and post.author %}
+                       <a href="/blog/authors/{{ post.author.uid }}">{{ _("by %s") % post.author }}</a>
                {% end %}
        </p>
 {% end %}
index 32bade619944e1dd37b1dc6e04c8dbae42443b3c..9d87c7eaa434b92b098215932bdfaa5ac1dd3dc7 100644 (file)
@@ -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),
index ff90bdd009b8f18ba320ebeac53543958f1786d7..3ae550a1908f18ff2b423cec8f0a3222599831f0 100644 (file)
@@ -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):