]> git.ipfire.org Git - ipfire.org.git/commitdiff
blog: Add index page
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Jul 2018 12:33:26 +0000 (13:33 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Jul 2018 12:33:26 +0000 (13:33 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/templates/blog/index.html [new file with mode: 0644]
src/templates/blog/modules/posts.html [new file with mode: 0644]
src/web/__init__.py
src/web/blog.py

index f69cbcc4e67337941e9fd18e172fea148be648a5..289cf1aff31379917733ba69a3122daccedc558a 100644 (file)
@@ -113,12 +113,14 @@ templatesdir = $(datadir)/templates
 templates_blog_DATA = \
        src/templates/blog/author.html \
        src/templates/blog/base.html \
+       src/templates/blog/index.html \
        src/templates/blog/post.html
 
 templates_blogdir = $(templatesdir)/blog
 
 templates_blog_modules_DATA = \
-       src/templates/blog/modules/post.html
+       src/templates/blog/modules/post.html \
+       src/templates/blog/modules/posts.html
 
 templates_blog_modulesdir = $(templates_blogdir)/modules
 
diff --git a/src/templates/blog/index.html b/src/templates/blog/index.html
new file mode 100644 (file)
index 0000000..4ea3622
--- /dev/null
@@ -0,0 +1,11 @@
+{% extends "base.html" %}
+
+{% block title %}{{ _("Welcome!") }}{% end block %}
+
+{% block main %}
+       <div class="card">
+               <div class="card-body">
+                       {% module BlogPosts(posts) %}
+               </div>
+       </div>
+{% end block %}
diff --git a/src/templates/blog/modules/posts.html b/src/templates/blog/modules/posts.html
new file mode 100644 (file)
index 0000000..fc81b48
--- /dev/null
@@ -0,0 +1,7 @@
+{% for i, post in enumerate(posts) %}
+    {% module BlogPost(post) %}
+
+    {% if i < (len(posts) - 1) %}
+        <div class="divider"></div>
+    {% end %}
+{% end %}
index 63cd2b10e29225314d1a6c70efb20cf5d99b0bd3..b4037c93fba6db41209886abea0a460c85efd56d 100644 (file)
@@ -40,6 +40,7 @@ class Application(tornado.web.Application):
                        },
                        "ui_modules" : {
                                "BlogPost"             : blog.PostModule,
+                               "BlogPosts"            : blog.PostsModule,
 
                                # Old modules
                                "Advertisement"        : AdvertisementModule,
@@ -124,6 +125,7 @@ class Application(tornado.web.Application):
 
                # blog.ipfire.org
                self.add_handlers(r"blog(\.dev)?\.ipfire\.org", [
+                       (r"/", blog.IndexHandler),
                        (r"/authors/(\w+)", blog.AuthorHandler),
                        (r"/post/(.*)", blog.PostHandler),
                ])
index 59e9d845581314b79d5cdde37b711fad955e209b..5ace7a8d963aac83d4d5615450126ae31c0eb238 100644 (file)
@@ -6,6 +6,13 @@ import handlers_base as base
 
 from . import ui_modules
 
+class IndexHandler(base.BaseHandler):
+       def get(self):
+               posts = self.planet.get_entries(limit=3)
+
+               self.render("blog/index.html", posts=posts)
+
+
 class AuthorHandler(base.BaseHandler):
        def get(self, uid):
                author = self.accounts.get_by_uid(uid)
@@ -32,3 +39,8 @@ class PostHandler(base.BaseHandler):
 class PostModule(ui_modules.UIModule):
        def render(self, post):
                return self.render_string("blog/modules/post.html", post=post)
+
+
+class PostsModule(ui_modules.UIModule):
+       def render(self, posts):
+               return self.render_string("blog/modules/posts.html", posts=posts)