33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
|
|
"""Flag Thumb:/Background: fields whose file did not survive the recovery.
|
||
|
|
|
||
|
|
The recovered articles kept their original image references even where the file
|
||
|
|
is unrecoverable -- deliberately, since the reference records what was there
|
||
|
|
(see IMAGES.md in the working material). 29 of 90 thumbnails and a similar share of heroes point at
|
||
|
|
files that no archive holds.
|
||
|
|
|
||
|
|
Resolving that in the browser via an <img> error handler means a visible flash
|
||
|
|
of broken image on a third of the grid. Checking at build time instead lets the
|
||
|
|
templates render a typographic card from the start, and keeps the metadata
|
||
|
|
intact rather than stripping it.
|
||
|
|
"""
|
||
|
|
import os
|
||
|
|
|
||
|
|
from pelican import signals
|
||
|
|
|
||
|
|
FIELDS = ("thumb", "background")
|
||
|
|
|
||
|
|
|
||
|
|
def _flag(content):
|
||
|
|
base = content.settings.get("PATH", "content")
|
||
|
|
for field in FIELDS:
|
||
|
|
ref = content.metadata.get(field)
|
||
|
|
if not ref:
|
||
|
|
continue
|
||
|
|
path = os.path.join(base, str(ref).lstrip("/"))
|
||
|
|
if not os.path.exists(path):
|
||
|
|
content.metadata[field + "_missing"] = True
|
||
|
|
|
||
|
|
|
||
|
|
def register():
|
||
|
|
signals.content_object_init.connect(_flag)
|