Skip to content
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

Add/send a metadata signal. #3567

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

vsajip
Copy link

@vsajip vsajip commented Aug 9, 2021

Pull Request Checklist

  • I’ve read the guidelines for contributing.
  • I updated AUTHORS.txt and CHANGES.txt (if the change is non-trivial) and documentation (if applicable).
  • I tested my changes.

Description

Send a "metadata" signal to allow interested parties to make additions/changes to the metadata. One example use of this would be to set the "updated" time of a post to the actual modification time of the source file for the post.

@Kwpolska
Copy link
Member

Kwpolska commented Aug 9, 2021

I don’t like the approach of mutating the meta dictionary in a signal. Perhaps a MetadataExtractor plugin would suit your needs better?

In any case, this should be documented in at least extending.rst

@vsajip
Copy link
Author

vsajip commented Aug 9, 2021

I don’t like the approach of mutating the meta dictionary in a signal. Perhaps a MetadataExtractor plugin would suit your needs better?

I looked at that approach first. For my specific use case (setting the "updated" metadata for any post to the modification time of the source file) I couldn't see a way of doing it using MetadataExtractor, because extract_filename() is only called with filenames for paths which match FILE_METADATA_REGEXP. Since you can only have one such regexp, using it to match all posts would mean it couldn't be used with e.g. an actual regexp.

nikola/nikola/post.py

Lines 1196 to 1201 in 650b954

if config.get('FILE_METADATA_REGEXP'):
extractors = metadata_extractors_by['source'].get(metadata_extractors.MetaSource.filename, [])
for extractor in extractors:
if not metadata_extractors.check_conditions(post, post.source_path, extractor.conditions, config, None):
continue
meta.update(extractor.extract_filename(post.source_path, lang))

@vsajip
Copy link
Author

vsajip commented Aug 9, 2021

In any case, this should be documented in at least extending.rst

If this functionality is going to be merged, I will happily update the documentation to cover it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants