Commits

Eddie Flores committed 3d6e922

Adds blog index template. Implements the '$: rhind post myTitle' command.

Comments (0)

Files changed (6)

         # generate post objs
         posts = self.generate_posts(post_files)
 
-        # attach stuff that needs to persist to the stash object
+        # attach stuff that needs to persist over to the stash object
         self.stash.blog_dir = self.blog_dir
         self.stash.posts = posts
 
         Renders each post to html and creates its corresponding
         directory sructure.
         """
+        # the path to where the posts will be rendered (Ex: _site/blog_dir/)
+        parent_dir = os.path.join(self.out_dir, blog_dir)
+        
         for p in posts:
-            path = os.path.join(self.out_dir, blog_dir, p.permalink())
-            mkpath(path) # create directory structure.
-            with open(os.path.join(path, 'index.html'), 'w') as f:
+            post_path = os.path.join(parent_dir, p.permalink())
+            mkpath(post_path) # create directory structure.
+            with open(os.path.join(post_path, 'index.html'), 'w') as f:
                 f.write(self.serve_template('post.mako',
                                             post_content=p.html,
                                             post_date=p.date.worded(),
                                             post_title=p.title,
                                             post_permalink=p.link,
                                             rd=self.stash))
+        # render the blog's index page
+        with open(os.path.join(parent_dir, 'index.html'), 'w') as f:
+            f.write(self.serve_template('blog_index.mako', rd=self.stash))
 
     def gather_templates(self):
         """Returns list of template files."""
 
 from builder import Builder
 from server import Server
-from util import is_rhind_dir, is_empty_dir
+from util import is_rhind_dir, is_empty_dir, PrettyDate
 from stash import rd
 
 def main():
             print "Open it for details. The build process has been aborted."
             sys.exit()
         else:
-            builder = Builder(tpl_dir=tpls, out_dir=site, blog_dir=blog_path, stash=rd)
+            builder = Builder(tpl_dir=tpls,
+                              out_dir=site, 
+                              blog_dir=blog_path, 
+                              stash=rd)
             builder.run()
             print 'Your site has been compiled to the _site directory.'
     else:
         print "Error: Failed to build. This isn't a Rhind working directory."
 
 def do_post(args):
-    print 'Generating a new post...'
-    print "Created post titled '{0}' ".format(args.post_title)
-    print "Find it in the _posts directory as 0010-{0}.md".format(args.post_title)
+    if is_rhind_dir():
+        print 'Generating a new post...'
+        cwd = os.getcwd()
+        posts_path = os.path.join(cwd, '_posts')
+        yml_header = """---
+title: {0}
+date: {1}
+description:
+categories:
+tags:
+---""".format(args.post_title, PrettyDate.today())
+        with open(os.path.join(posts_path, args.post_title + '.md'), 'w') as f:
+            print>>f, yml_header
+
+        print "Created post titled '{0}' ".format(args.post_title)
+        print "Find it in the _posts directory as {0}.md".format(args.post_title)
+    else:
+        print "Error: Failed to build. This isn't a Rhind working directory."
 
 def do_serve(args):
     server = Server()

rhind/rhind_site/_templates/blog_index.mako

+<%inherit file="base.mako" />
+
+<%def name="head_tags()">
+    <title>Blog</title>
+    <link rel="stylesheet" type="text/css" href="/media/css/master.css"/>
+    <link rel="stylesheet" type="text/css" href="/media/css/pygments/monokai.css" />
+</%def>
+
+<%
+    posts = rd.posts
+    posts.sort()
+    posts.reverse()
+%>
+
+<ul>
+% for p in posts:
+    <li>
+    <a href="/${rd.blog_dir+'/'+p.link if rd.blog_dir else p.link}">${p.title}</a>
+    - ${p.date.numerical()}
+    <p class="post-description">${p.description}</p>
+    </li>
+% endfor
+</ul>
+

rhind/rhind_site/_templates/post.mako

     <small>${post_date}</small>
     <p>${post_description}</p>
 
-
-    <p>
-        <label for="post-categories">Category:</label>
-        <ul id="post-categories">
-        % for link in cat_links:
-            <li>${link}</li>
-        % endfor
-        </ul>
-    </p>
-
     <p>
         <label for="post-tags">Tags:</label>
         <ul id="post-tags">

rhind/rhind_site/_templates/tags.mako

 
     % for tag in tags_dict:
         <ul id="${tag}">
-            <h3>${tag}</h3>
+            <h3>${tag}(${len(tags_dict[tag])})</h3>
             % for p in tags_dict[tag]:
                 <li><a href="/${rd.blog_dir+'/'+p.link if rd.blog_dir else p.link}">${p.title}</a></li>
             % endfor
 
 """ Storage object used throughout the build process """
 rd = Stash()
-
-