-
-
Notifications
You must be signed in to change notification settings - Fork 22
Process metadata #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Process metadata #99
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request introduces metadata image processing functionality to the Image Process plugin, allowing users to process images referenced in metadata fields (such as og_image) in addition to images in HTML content. The implementation adds a new configuration setting, updates documentation, and includes comprehensive tests.
- Adds
IMAGE_PROCESS_METADATAsetting to specify which metadata fields should be processed and which transformations to apply - Supports per-instance transformation overrides using
{transform-name}prefix syntax - Refactors
compute_pathsfunction to accept image URL strings instead of dictionary objects
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| pelican/plugins/image_process/image_process.py | Implements metadata processing logic with the new process_metadata function, refactors compute_paths signature to accept strings, and registers the new signal handler |
| pelican/plugins/image_process/test_image_process.py | Adds parameterized tests for metadata processing covering default behavior, transformation application, and override mechanisms; updates tests to use refactored compute_paths signature |
| README.md | Documents the new metadata processing feature with usage examples and configuration details |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
In Python 3.14, `urllib.parse.urljoin` handles `//` differently than in previous versions.
justinmayer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a small suggestion for the README, but otherwise this looks good to me. Any thoughts, @minchinweb?
minchinweb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple thoughts on how to make the documentation a little clearer. The plugin is hugely powerful, but annoying complex to get set up from scratch, so the easier we can make that, they better.
And a request to guard against reusing "special" "keys", already is use elsewhere.
| IMAGE_PROCESS_METADATA = { | ||
| "og_image": "og-image-transform", | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you provide an example IMAGE_PROCESS here, showing the listed transformation (maybe scale to the proper dimensions??)?
| It is possible to override the transformation applied to a specific instance of a metadata field by prefixing | ||
| the metadata value with `{transform-name}`. For example, if you have defined | ||
| `IMAGE_PROCESS_METADATA` as above, you can override the transformation for a specific article | ||
| by setting its `og_image` metadata value to `{other-transform}/path/to/image.jpg`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a (simple) sample file (i.e. a Markdown post) showing this in the metadata of the post in the actual format?
| metadata field names to transformation names. For example: | ||
|
|
||
| ```python | ||
| IMAGE_PROCESS_METADATA = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment here noting this the the pelicanconf.py file. E.g.
# pelicanconf.py
IMAGE_PROCESS_METADATA = {
# ...the rest| if isinstance(value, str) and key in metadata_to_process: | ||
| derivative = generator.context["IMAGE_PROCESS_METADATA"][key] | ||
| # If value starts with {some-other-derivative}, override derivative | ||
| if value.startswith("{") and "}" in value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should we add a guard against using "keys" such as {attach} or {static} that have special meaning already to Pelican. I think the list can be imported from pelican, which would be ideal rather than maintaining such a list here manually.
Probably best to throw a warning if one of the disallowed keys is encountered.
|
Also, which is prefer? For me to make suggestions like this for documentation, or just write it myself and push it to the PR and ask for your review? |
|
@minchinweb Thanks for the comments. Unless it is something very minor, I prefer suggestions than additional commits, because we can discuss them (if there is a need for discussion) and I feel it is less work for the reviewer (no need to setup a dev environment, no need to test the suggestions, no need to lint the files, ...). |
This pull request adds support for processing image paths found in metadata fields (such as
og_image) in addition to images in HTML content. It introduces a new configuration option to specify which metadata fields should be processed and which transformations to apply. The implementation includes the new processing logic, updates to the documentation, and corresponding tests.New feature: Process images in metadata fields
IMAGE_PROCESS_METADATAsetting. This allows users to specify which metadata fields should be processed and which image transformation to apply. The processing supports per-instance overrides and saves original metadata values for reference. (README.md,pelican/plugins/image_process/image_process.py) [1] [2]Documentation updates
IMAGE_PROCESS_METADATAsetting, including examples and override mechanisms. (README.md) [1] [2]Testing
pelican/plugins/image_process/test_image_process.py)