mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Move the "find image with an empty alt" block in a function.
This commit is contained in:
parent
85ea737a98
commit
bab8d0b26a
1 changed files with 43 additions and 36 deletions
|
|
@ -416,10 +416,33 @@ class Readers(object):
|
|||
content, reader_metadata = reader.read(path)
|
||||
metadata.update(reader_metadata)
|
||||
|
||||
# create warnings for all images with empty alt (up to a certain
|
||||
# number) # as they are really likely to be accessibility flaws
|
||||
if content:
|
||||
# find images with empty alt
|
||||
find_empty_alt(content, path)
|
||||
|
||||
# eventually filter the content with typogrify if asked so
|
||||
if content and self.settings['TYPOGRIFY']:
|
||||
from typogrify.filters import typogrify
|
||||
content = typogrify(content)
|
||||
metadata['title'] = typogrify(metadata['title'])
|
||||
|
||||
if context_signal:
|
||||
logger.debug('signal {}.send({}, <metadata>)'.format(
|
||||
context_signal, context_sender))
|
||||
context_signal.send(context_sender, metadata=metadata)
|
||||
|
||||
return content_class(content=content, metadata=metadata,
|
||||
settings=self.settings, source_path=path,
|
||||
context=context)
|
||||
|
||||
|
||||
def find_empty_alt(content, path):
|
||||
"""Find images with empty alt
|
||||
|
||||
Create warnings for all images with empty alt (up to a certain number),
|
||||
as they are really likely to be accessibility flaws.
|
||||
|
||||
"""
|
||||
imgs = re.compile(r"""
|
||||
(?:
|
||||
# src before alt
|
||||
|
|
@ -451,21 +474,6 @@ class Readers(object):
|
|||
logger.warning('{} other images with empty alt attributes'
|
||||
.format(len(matches) - nb_warnings))
|
||||
|
||||
# eventually filter the content with typogrify if asked so
|
||||
if content and self.settings['TYPOGRIFY']:
|
||||
from typogrify.filters import typogrify
|
||||
content = typogrify(content)
|
||||
metadata['title'] = typogrify(metadata['title'])
|
||||
|
||||
if context_signal:
|
||||
logger.debug('signal {}.send({}, <metadata>)'.format(
|
||||
context_signal, context_sender))
|
||||
context_signal.send(context_sender, metadata=metadata)
|
||||
|
||||
return content_class(content=content, metadata=metadata,
|
||||
settings=self.settings, source_path=path,
|
||||
context=context)
|
||||
|
||||
|
||||
def default_metadata(settings=None, process=None):
|
||||
metadata = {}
|
||||
|
|
@ -516,13 +524,12 @@ def parse_path_metadata(source_path, settings=None, process=None):
|
|||
subdir = os.path.basename(dirname)
|
||||
if settings:
|
||||
checks = []
|
||||
for key,data in [('FILENAME_METADATA', base),
|
||||
('PATH_METADATA', source_path),
|
||||
]:
|
||||
for key, data in [('FILENAME_METADATA', base),
|
||||
('PATH_METADATA', source_path)]:
|
||||
checks.append((settings.get(key, None), data))
|
||||
if settings.get('USE_FOLDER_AS_CATEGORY', None):
|
||||
checks.insert(0, ('(?P<category>.*)', subdir))
|
||||
for regexp,data in checks:
|
||||
for regexp, data in checks:
|
||||
if regexp and data:
|
||||
match = re.match(regexp, data)
|
||||
if match:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue