Skip to content

Commit

Permalink
Adding traces to debug issue pelican-plugins#69
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickfournier committed Jan 6, 2023
1 parent 4fb41a8 commit db6eb2d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pelican/plugins/image_process/image_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,12 @@ def harvest_images_in_fragment(fragment, settings):
except KeyError:
raise RuntimeError("Derivative %s undefined." % derivative)

logger.debug("%s Found setting %s for image %s." %
(LOG_PREFIX, derivative, img["src"]))

if isinstance(d, list):
# Single source image specification.
logger.debug("%s Implicit Image type." % LOG_PREFIX)
process_img_tag(img, settings, derivative)

elif not isinstance(d, dict):
Expand All @@ -349,13 +353,16 @@ def harvest_images_in_fragment(fragment, settings):

elif d["type"] == "image":
# Single source image specification.
logger.debug("%s Image type." % LOG_PREFIX)
process_img_tag(img, settings, derivative)

elif d["type"] == "responsive-image" and "srcset" not in img.attrs:
# srcset image specification.
logger.debug("%s SrcSet type." % LOG_PREFIX)
build_srcset(img, settings, derivative)

elif d["type"] == "picture":
logger.debug("%s Picture type." % LOG_PREFIX)
# Multiple source (picture) specification.
group = img.find_parent()
if group.name == "div":
Expand Down Expand Up @@ -419,6 +426,8 @@ def process_img_tag(img, settings, derivative):
path = compute_paths(img, settings, derivative)
process = settings["IMAGE_PROCESS"][derivative]

logger.debug("process_img_tag.")

img["src"] = posixpath.join(path.base_url, path.filename)
destination = os.path.join(path.base_path, path.filename)

Expand All @@ -430,6 +439,9 @@ def process_img_tag(img, settings, derivative):

def build_srcset(img, settings, derivative):
path = compute_paths(img, settings, derivative)

logger.debug("%s Using setting 'settings[\"IMAGE_PROCESS\"][%s]'." %
(LOG_PREFIX, derivative))
process = settings["IMAGE_PROCESS"][derivative]

default = process["default"]
Expand All @@ -449,9 +461,13 @@ def build_srcset(img, settings, derivative):
destination = os.path.join(path.base_path, default_name, path.filename)
process_image((path.source, destination, default), settings)

logger.debug("%s Setting src to %s /// %s /// %s." %
(LOG_PREFIX, path.base_url, default_name, path.filename))
img["src"] = posixpath.join(path.base_url, default_name, path.filename)

if "sizes" in process:
logger.debug("%s Setting sizes to %s." %
(LOG_PREFIX, process["sizes"]))
img["sizes"] = process["sizes"]

srcset = []
Expand All @@ -462,6 +478,9 @@ def build_srcset(img, settings, derivative):
process_image((path.source, destination, src[1]), settings)

if len(srcset) > 0:
logger.debug("%s Setting srcset to %s." %
(LOG_PREFIX, ", ".join(srcset)))

img["srcset"] = ", ".join(srcset)


Expand Down

0 comments on commit db6eb2d

Please sign in to comment.