Skip to content

Commit

Permalink
A target to list categories for posts
Browse files Browse the repository at this point in the history
  • Loading branch information
gvwilson committed Jul 25, 2013
1 parent 0e22f2b commit 40b46c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -10,6 +10,10 @@ all : commands
commands :
@grep -E '^##' Makefile | sed -e 's/## //g'

## categories : show known categories
categories :
@python bin/categories.py $(POSTS)

## check : build locally into _site directory for checking
check :
make OUT=$(PWD)/_site build
Expand Down
20 changes: 20 additions & 0 deletions bin/categories.py
@@ -0,0 +1,20 @@
#!/usr/bin/env python

"""
Display all the categories used in blog posts.
"""

import sys
import re

cat_p = re.compile('categories:\s*\[(.+)\]')

categories = set()
for filename in sys.argv[1:]:
with open(filename, 'r') as reader:
data = reader.read()
m = cat_p.search(data)
assert m, "No categories match for %s" % filename
categories.update([x.strip() for x in m.group(1).split(',')])
for c in sorted(categories):
print c

0 comments on commit 40b46c0

Please sign in to comment.