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)
|
content, reader_metadata = reader.read(path)
|
||||||
metadata.update(reader_metadata)
|
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:
|
if content:
|
||||||
# find images with empty alt
|
# 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"""
|
imgs = re.compile(r"""
|
||||||
(?:
|
(?:
|
||||||
# src before alt
|
# src before alt
|
||||||
|
|
@ -451,21 +474,6 @@ class Readers(object):
|
||||||
logger.warning('{} other images with empty alt attributes'
|
logger.warning('{} other images with empty alt attributes'
|
||||||
.format(len(matches) - nb_warnings))
|
.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):
|
def default_metadata(settings=None, process=None):
|
||||||
metadata = {}
|
metadata = {}
|
||||||
|
|
@ -517,8 +525,7 @@ def parse_path_metadata(source_path, settings=None, process=None):
|
||||||
if settings:
|
if settings:
|
||||||
checks = []
|
checks = []
|
||||||
for key, data in [('FILENAME_METADATA', base),
|
for key, data in [('FILENAME_METADATA', base),
|
||||||
('PATH_METADATA', source_path),
|
('PATH_METADATA', source_path)]:
|
||||||
]:
|
|
||||||
checks.append((settings.get(key, None), data))
|
checks.append((settings.get(key, None), data))
|
||||||
if settings.get('USE_FOLDER_AS_CATEGORY', None):
|
if settings.get('USE_FOLDER_AS_CATEGORY', None):
|
||||||
checks.insert(0, ('(?P<category>.*)', subdir))
|
checks.insert(0, ('(?P<category>.*)', subdir))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue