Skip to content

Commit

Permalink
minor commit (automatic message)
Browse files Browse the repository at this point in the history
  • Loading branch information
queirozfcom committed Mar 19, 2019
1 parent a1df413 commit e4f6407
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
15 changes: 12 additions & 3 deletions jekyllutils/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,24 @@ def _get_contents_paper_summary():
> <span style="font-weight:bold">Please note</span> This post is mainly intended for my **personal use**. It is not peer-reviewed work and should not be taken as such.
## WHAT
## WHY
## HOW
## CLAIMS
## NOTES
## QUOTES
## NOTES
## MY 2¢
-----
Expand Down Expand Up @@ -228,4 +237,4 @@ def _get_contents_crypto_asset_overview():
### References
"""
"""
10 changes: 7 additions & 3 deletions jekyllutils/helpers/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ def list_filenames_by_tag(absolute_directory, tags):
return matches


def list_unpublished_filenames(absolute_directory):
def list_unpublished_filenames(absolute_directory, include_wip):
"""
Returns all filenames under absolute_directory that are unpublished.
(i.e. files where published: false in front-matter)
:param absolute_directory:
:return: a list of the filenames,
:param include_wip: if true, also return files that contain "wip alert"
:return: a list of the filenames
"""
matches = []

Expand All @@ -81,7 +82,10 @@ def list_unpublished_filenames(absolute_directory):
for line in f:
if line.strip().startswith("published:"):
if _match_all(line, ("false",)):
matches.append(filename)
matches.append("[UNP]" + filename)
break
if include_wip and ("wip alert" in line.lower()):
matches.append("[WIP]" + filename)
break

return matches
Expand Down
16 changes: 16 additions & 0 deletions jekyllutils/helpers/sorting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import re


def sort_ignoring_brackets(list_of_filenames, reverse=None):
"""
need a custom function because we don't want strings starting with [...] before everything else
:param list_of_filenames:
:param reverse:
:return:
"""

if reverse is None:
reverse = False

return sorted(list_of_filenames, key=lambda a: re.sub("(?i)^\[\w+\]\s*", "", a), reverse=reverse)
12 changes: 8 additions & 4 deletions jekyllutils/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from jekyllutils.helpers.configs import get_path_to_posts_dir, get_editor_name
from jekyllutils.helpers.editors import get_executable_from_name
from jekyllutils.helpers.files import list_files, list_filenames_by_tag, list_unpublished_filenames, resolve_path
from jekyllutils.helpers.sorting import sort_ignoring_brackets


@click.command()
Expand Down Expand Up @@ -59,14 +60,17 @@ def list_by_tag(tags, reverse):
@click.command()
@click.option('--reverse/--no-reverse', default=True,
help="Default is to list files in reverse chronological order, just like git log")
def list_unpublished(reverse):
@click.option('--include-wip-alerts/--no-include-wip-alerts', default=True,
help="Whether to consider WIP posts as unpublished even though they be published")
def list_unpublished(reverse, include_wip_alerts):
path_to_posts_directory = resolve_path(get_path_to_posts_dir())
filenames = list_unpublished_filenames(path_to_posts_directory)
filenames = list_unpublished_filenames(path_to_posts_directory, include_wip_alerts)

if len(filenames) == 0:
raise click.UsageError('No files found. Well done!')
else:

if reverse:
click.echo_via_pager('\n'.join(sorted(filenames, reverse=True)))
click.echo_via_pager('\n'.join(sort_ignoring_brackets(filenames, reverse=True)))
else:
click.echo_via_pager('\n'.join(sorted(filenames)))
click.echo_via_pager('\n'.join(sort_ignoring_brackets(filenames)))

0 comments on commit e4f6407

Please sign in to comment.