mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Allow directories in EXTRA_PATH_METADATA
Metadata applied to a directory will apply to all files under it. In case of conflicts, child paths beat parent paths, so metadata applied to `dir/subdir/file.md` will take precedence over that applied to `dir/subdir`, which will take precedence over just `dir`.
This commit is contained in:
parent
e967988eff
commit
ce9f3d55a3
3 changed files with 48 additions and 3 deletions
|
|
@ -698,8 +698,20 @@ def path_metadata(full_path, source_path, settings=None):
|
|||
if settings.get('DEFAULT_DATE', None) == 'fs':
|
||||
metadata['date'] = SafeDatetime.fromtimestamp(
|
||||
os.stat(full_path).st_mtime)
|
||||
metadata.update(settings.get('EXTRA_PATH_METADATA', {}).get(
|
||||
source_path, {}))
|
||||
|
||||
# Apply EXTRA_PATH_METADATA for the source path and the paths of any
|
||||
# parent directories. Sorting EPM first ensures that the most specific
|
||||
# path wins conflicts.
|
||||
|
||||
epm = settings.get('EXTRA_PATH_METADATA', {})
|
||||
for path, meta in sorted(epm.items()):
|
||||
# Enforce a trailing slash when checking for parent directories.
|
||||
# This prevents false positives when one file or directory's name
|
||||
# is a prefix of another's.
|
||||
dirpath = os.path.join(path, '')
|
||||
if source_path == path or source_path.startswith(dirpath):
|
||||
metadata.update(meta)
|
||||
|
||||
return metadata
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue