Warn user in case of missing title. Fixes #440.

When a WP XML file is imported, items with missing title are generated with a
title which is probably not the good one (instead of being dropped), and a
warning is displayed to the user.
This commit is contained in:
Rogdham 2013-04-13 20:37:26 +01:00
commit a4c16e1b53

View file

@ -14,10 +14,14 @@ import re
import subprocess import subprocess
import sys import sys
import time import time
import logging
from codecs import open from codecs import open
from pelican.utils import slugify from pelican.utils import slugify
from pelican.log import init
logger = logging.getLogger(__name__)
def decode_wp_content(content, br=True): def decode_wp_content(content, br=True):
@ -114,7 +118,8 @@ def wp2fields(xml):
# Use HTMLParser due to issues with BeautifulSoup 3 # Use HTMLParser due to issues with BeautifulSoup 3
title = HTMLParser().unescape(item.title.contents[0]) title = HTMLParser().unescape(item.title.contents[0])
except IndexError: except IndexError:
continue title = 'No title [%s]' % item.find('post_name').string
logger.warn('Post "%s" is lacking a proper title' % title)
content = item.find('encoded').string content = item.find('encoded').string
filename = item.find('post_name').string filename = item.find('post_name').string
@ -492,6 +497,8 @@ def main():
elif input_type == 'feed': elif input_type == 'feed':
fields = feed2fields(args.input) fields = feed2fields(args.input)
init() # init logging
fields2pelican(fields, args.markup, args.output, fields2pelican(fields, args.markup, args.output,
dircat=args.dircat or False, dircat=args.dircat or False,
strip_raw=args.strip_raw or False, strip_raw=args.strip_raw or False,