Browse Source

rename find_new_posts to find_new_items

Oz N Tiram 9 years ago
parent
commit
be47cbf50b
4 changed files with 18 additions and 65 deletions
  1. 10 51
      blogit/blogit.py
  2. 2 2
      tests/test_blogit.py
  3. 3 6
      tests/test_post.py
  4. 3 6
      tests/test_tag.py

+ 10 - 51
blogit/blogit.py

@@ -217,7 +217,7 @@ class Entry(object):
 
 
     @property
     @property
     def summary_html(self):
     def summary_html(self):
-        return "%s" % markdown2.markdown(self.header['summary'].strip())
+        return "%s" % markdown2.markdown(self.header.get('summary', "").strip())
 
 
     @property
     @property
     def credits_html(self):
     def credits_html(self):
@@ -225,14 +225,15 @@ class Entry(object):
 
 
     @property
     @property
     def summary_atom(self):
     def summary_atom(self):
-        summarya = markdown2.markdown(self.header['summary'].strip())
+        summarya = markdown2.markdown(self.header.get('summary', "").strip())
         summarya = re.sub("<p>|</p>", "", summarya)
         summarya = re.sub("<p>|</p>", "", summarya)
         more = '<a href="%s"> continue reading...</a>' % (self.permalink)
         more = '<a href="%s"> continue reading...</a>' % (self.permalink)
         return summarya+more
         return summarya+more
 
 
     @property
     @property
     def publish_date(self):
     def publish_date(self):
-        return self.header['published'].strftime("%B %d, %Y")
+        d = self.header.get('published', datetime.date.today())
+        return d.strftime("%B %d, %Y")
 
 
     @property
     @property
     def published_atom(self):
     def published_atom(self):
@@ -265,7 +266,10 @@ class Entry(object):
 
 
     @property
     @property
     def tags(self):
     def tags(self):
-        return [Tag(t) for t in self.header['tags']]
+        try:
+            return [Tag(t) for t in self.header['tags']]
+        except KeyError:
+            return []
 
 
     def _read_header(self, file):
     def _read_header(self, file):
         header = ['---']
         header = ['---']
@@ -358,7 +362,7 @@ def render_archive(entries):
     destination.close()
     destination.close()
 
 
 
 
-def find_new_posts(posts_table):
+def find_new_items(posts_table):
     """
     """
     Walk content dir, put each post in the database
     Walk content dir, put each post in the database
     """
     """
@@ -401,52 +405,7 @@ def update_index():
 
 
 
 
 def new_build():
 def new_build():
-    """
-
-        a. For each new post:
-        1. render html
-        2. find post tags
-        3. update atom feeds for old tags
-        4. create new atom feeds for new tags
-
-    b. update index page
-    c. update archive page
-
-    """
-    print
-    print "Rendering website now..."
-    print
-    print " entries:"
-    entries = list()
-    tags = dict()
-    root = CONFIG['content_root']
-    for post_id, post in find_new_posts(DB.posts):
-        try:
-            entry = Entry(post)
-            if entry.render():
-                entries.append(entry)
-                for tag in entry.tags:
-                    tag.posts = [post_id]
-                    tags[tag.name] = tag
-            print "     %s" % entry.path
-        except Exception as e:
-            print "Found some problem in: ", post
-            print e
-            print "Please correct this problem ..."
-            sys.exit(1)
-
-    for name, to in tags.iteritems():
-        print "updating tag %s" % name
-        to.render()
-
-    # update index
-    print "updating index"
-    update_index()
-
-    # update archive
-    print "updating archive"
-    render_archive(_sort_entries([Entry(p['filename'])
-                                  for p in DB.posts.all()]))
+find_new_items
 
 
 
 
 
 

+ 2 - 2
tests/test_blogit.py

@@ -1,7 +1,7 @@
 import os
 import os
 import shutil
 import shutil
 from tinydb import Query
 from tinydb import Query
-from blogit.blogit import find_new_posts, DataBase, Entry, Tag
+from blogit.blogit import find_new_items, DataBase, Entry, Tag
 from blogit.blogit import CONFIG, new_build
 from blogit.blogit import CONFIG, new_build
 
 
 
 
@@ -66,7 +66,7 @@ def test_find_new_posts():
     DB = DataBase(os.path.join(CONFIG['content_root'], 'blogit.db'))
     DB = DataBase(os.path.join(CONFIG['content_root'], 'blogit.db'))
     DB._db.purge_tables()
     DB._db.purge_tables()
     insert_single(DB)
     insert_single(DB)
-    new =  list(find_new_posts(DB.posts))
+    new =  list(find_new_items(DB.posts))
     assert len(DB.posts.all()) == 4
     assert len(DB.posts.all()) == 4
     assert len(new) == 3
     assert len(new) == 3
 
 

+ 3 - 6
tests/test_post.py

@@ -1,7 +1,7 @@
 import os
 import os
 import shutil
 import shutil
 from tinydb import Query
 from tinydb import Query
-from blogit.blogit import find_new_posts, DB, Entry, Tag
+from blogit.blogit import find_new_items, DB, Entry, Tag
 from blogit.blogit import CONFIG, new_build
 from blogit.blogit import CONFIG, new_build
 
 
 
 
@@ -16,7 +16,7 @@ summary: |
     This is a summry of post {}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus
     This is a summry of post {}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus
     ...
     ...
 
 
-This is the body of post {}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. 
+This is the body of post {}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
 
 
 This is a snippet in bash
 This is a snippet in bash
 
 
@@ -52,10 +52,7 @@ def create_posts():
 
 
 
 
 def test_tag():
 def test_tag():
-    new =  list(find_new_posts(DB.posts))
-    t = Tag('python')
-    t.posts = [1,2,3]
-    t.render()
+find_new_items
 
 
 import pytest
 import pytest
 
 

+ 3 - 6
tests/test_tag.py

@@ -1,7 +1,7 @@
 import os
 import os
 import shutil
 import shutil
 from tinydb import Query
 from tinydb import Query
-from blogit.blogit import find_new_posts, DB, Entry, Tag
+from blogit.blogit import find_new_items, DB, Entry, Tag
 from blogit.blogit import CONFIG, new_build
 from blogit.blogit import CONFIG, new_build
 
 
 
 
@@ -16,7 +16,7 @@ summary: |
     This is a summry of post {}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus
     This is a summry of post {}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus
     ...
     ...
 
 
-This is the body of post {}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. 
+This is the body of post {}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
 
 
 This is a snippet in bash
 This is a snippet in bash
 
 
@@ -52,10 +52,7 @@ def create_posts():
 
 
 
 
 def test_tag():
 def test_tag():
-    new =  list(find_new_posts(DB.posts))
-    t = Tag('python')
-    t.posts = [1,2,3]
-    t.render()
+find_new_items
 
 
 import pytest
 import pytest