Przeglądaj źródła

make index size configurable

Oz N Tiram 9 lat temu
rodzic
commit
7bf5fad4e7
3 zmienionych plików z 9 dodań i 8 usunięć
  1. 5 5
      blogit/blogit.py
  2. 2 1
      conf.py
  3. 2 2
      tests/test_all.py

+ 5 - 5
blogit/blogit.py

@@ -209,7 +209,7 @@ class Entry(object):
         try:
             self.prepare()
         except KeyError as E:
-            pass
+            import pdb; pdb.set_trace()
 
     def __str__(self):
         return self.path
@@ -356,12 +356,12 @@ def find_new_posts_and_pages(db):
                     yield e, e.id
 
 
-def _get_last_entries(db):
+def _get_last_entries(db, qty):
     eids = [post.eid for post in db.posts.all()]
-    eids = sorted(eids)[-10:][::-1]
+    eids = sorted(eids, reverse=True)
     entries = [Entry(os.path.join(CONFIG['content_root'],
                      db.posts.get(eid=eid)['filename']), eid) for eid in eids]
-    return entries
+    return entries[:qty]
 
 
 def update_index(entries):
@@ -407,7 +407,7 @@ def build(config):
     # to the index using BeautifulSoup
     # update index
     print("updating index")
-    update_index(_sort_entries(_get_last_entries(DB)))
+    update_index(_sort_entries(_get_last_entries(DB, config['INDEX_SIZE'])))
 
     # update archive
     print("updating archive")

+ 2 - 1
conf.py

@@ -20,7 +20,8 @@ CONFIG = {
     'content_encoding': 'utf-8',
     'author': 'Oz Nahum Tiram',
     'editor': 'editor',
-    'ARCHIVE_SIZE': 10
+    'ARCHIVE_SIZE': 10,
+    'INDEX_SIZE': 10, # How many entries shoud be in the INDEX
     }
 
 GLOBAL_TEMPLATE_CONTEXT = {

+ 2 - 2
tests/test_all.py

@@ -238,7 +238,7 @@ def test_tag_render():
 def test_get_last_entries():
 
     assert len(DB.posts.all()) == 22
-    le = _get_last_entries(DB)
+    le = _get_last_entries(DB, 10)
     assert [e.id for e in le] == range(22, 12, -1)
 
 
@@ -256,7 +256,7 @@ def test_render_archive():
 
 
 def test_render_index():
-    update_index(_get_last_entries(DB))
+    update_index(_get_last_entries(DB, 10))
     with open(os.path.join(CONFIG['output_to'], 'index.html')) as html_index:
         soup = BeautifulSoup(html_index.read(), 'html.parser')
         assert len(soup.find_all(class_='clearfix entry')) == 10