getpelican/pelican — pull request #1491 by foresto (2014-10-06 03:22:22+00:00)
Title: Ignore empty metadata. Fixes #1469. Fixes #1398.

Some metadata values cause problems when empty. For example, a markdown file containing a `Slug:` line with no additional text causing Pelican to produce a file named `.html` instead of generating a proper file name. Others, like those created by a `PATH_METADATA` regex, must be preserved even if empty, so things like `PAGE_URL="filename{customvalue}.html"` will always work. Essentially, we want to discard empty metadata that we know will be useless or problematic. This is better than raising an exception because (a) it allows users to deliberately keep empty metadata in their source files for filling in later, and (b) users shouldn't be forced to fix empty metadata created by blog migration tools (see #1398).

The metadata processors are the ideal place to do this, because they know the type of data they are handling and whether an empty value is wanted. Unfortunately, they can't discard items, and neither can `process_metadata()`, because their return values are always saved by calling code. We can't safely change the calling code, because some of it lives in custom reader classes out in the field, and we don't want to break those working systems. Discarding empty values at the time of use isn't good enough, because that still allows useless empty values in a source file to override configured defaults.

My solution:
- When processing a list of values, a metadata processor will omit any unwanted empty ones from the list it returns.
- When processing an entirely unwanted value, it will return something easily identifiable that will pass through the reader code.
- When collecting the processed metadata, read_file() will filter out items identified as unwanted.

These metadata are affected by this change:
- author
- authors
- category
- slug
- status
- tags

I also removed a bit of now-superfluous code from generators.py that was discarding empty authors at the time of use.