This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Add latest 5 blog posts to homepage.

  • Loading branch information...
jwage committed Jan 22, 2012
1 parent 42606e6 commit 7f4e7838e714281ca5e3474c133baf819ba425f8
@@ -45,6 +45,7 @@ class Latest(Directive):
final_argument_whitespace = False
option_spec = {
'maxdepth': int,
+ 'limit': int,
'glob': directives.flag,
'hidden': directives.flag,
'numbered': int_or_nothing,
@@ -55,6 +56,7 @@ def run(self):
env = self.state.document.settings.env
suffix = env.config.source_suffix
glob = 'glob' in self.options
+ limit = 'limit' in self.options
ret = []
# (title, ref) pairs, where ref may be a document, or an external link,
@@ -128,6 +130,9 @@ def run(self):
for date in ordered_keys:
subnode['entries'].append(sorted_entries[date])
+ if limit:
+ del subnode['entries'][self.options.get('limit'):len(subnode['entries'])]
+
# includefiles only entries that are documents
subnode['includefiles'] = includefiles
subnode['maxdepth'] = self.options.get('maxdepth', -1)
@@ -29,7 +29,7 @@
from __future__ import generators
-import sys, warnings, os, fnmatch, glob, shutil, codecs, hashlib
+import sys, warnings, os, fnmatch, glob, shutil, codecs, md5
__version__ = '2.2'
__all__ = ['path']
Binary file not shown.
@@ -45,6 +45,7 @@ class Latest(Directive):
final_argument_whitespace = False
option_spec = {
'maxdepth': int,
+ 'limit': int,
'glob': directives.flag,
'hidden': directives.flag,
'numbered': int_or_nothing,
@@ -55,6 +56,7 @@ def run(self):
env = self.state.document.settings.env
suffix = env.config.source_suffix
glob = 'glob' in self.options
+ limit = 'limit' in self.options
ret = []
# (title, ref) pairs, where ref may be a document, or an external link,
@@ -128,6 +130,9 @@ def run(self):
for date in ordered_keys:
subnode['entries'].append(sorted_entries[date])
+ if limit:
+ del subnode['entries'][self.options.get('limit'):len(subnode['entries'])]
+
# includefiles only entries that are documents
subnode['includefiles'] = includefiles
subnode['maxdepth'] = self.options.get('maxdepth', -1)
View
@@ -12,6 +12,18 @@ You can read more about the projects below or view a list of all projects.
* :doc:`Contribute <contribute>`
* :doc:`Community <community>`
+Latest Blog Posts
+=================
+
+.. latest::
+ :maxdepth: 3
+ :glob:
+ :limit: 5
+
+ blog/*
+
+:doc:`Read older blog posts <blog/index>`
+
.. doctrine-projects::
:file: projects.yml
:type: top

0 comments on commit 7f4e783

Please sign in to comment.