improve result output of a pelican run

*  display count of hidden pages
*  pluralize only if necessary
*  add maybe_pluralize to utils
*  add tests for maybe_pluralize
This commit is contained in:
derwinlu 2015-06-03 08:58:59 +02:00
commit 39fd4936b5
3 changed files with 50 additions and 7 deletions

View file

@ -767,3 +767,19 @@ def path_to_file_url(path):
'''Convert file-system path to file:// URL'''
return six.moves.urllib_parse.urljoin(
"file://", six.moves.urllib.request.pathname2url(path))
def maybe_pluralize(count, singular, plural):
'''
Returns a formatted string containing count and plural if count is not 1
Returns count and singular if count is 1
maybe_pluralize(0, 'Article', 'Articles') -> '0 Articles'
maybe_pluralize(1, 'Article', 'Articles') -> '1 Article'
maybe_pluralize(2, 'Article', 'Articles') -> '2 Articles'
'''
selection = plural
if count == 1:
selection = singular
return '{} {}'.format(count, selection)