Repository navigation
Settings support for pathlib - #2758
Conversation
when settings could be pathlib.Path
justinmayer
left a comment
There was a problem hiding this comment.
Thanks to @minchinweb for the enhancement (and the patience) and also to @avaris for reviewing. 👏
|
Delighted to see it merged (and useful) after all this time! |
|
I believe this change breaks the Dynamic Pelican Settings workaround that I also relied on. I also had the use case of preserving old link structures from before switching to Pelican to the best extent possible. Especially this change seems to be the culprit as it now returns Indeed, changing the logic to |
|
@adnia from a brief glance, for that to work you also need to define what class DynamicSetting(str):
def __init__(self, f):
self.f = f
def format(self, **metadata):
return self.f(metadata).format(**metadata)
def __str__(self):
return selfBut, I have to emphasize that this method of monkey-patching, although neat, still relies on certain structure for things that are "internal" to EDIT: However, "proper" way to handle this would be a plugin. You just need to connect to from pelican import signals
def update_save_as_url(content):
# logic can be extended to differentiate pages and articles based on content class
if "cleanurl" in content.metadata:
content.override_save_as = '...'
content.override_url = '...'
def register():
signals.content_object_init.connect(update_save_as_url) |
This doesn't work, as the logic needs to work on both The plugin idea is probably a good way to go; if you get stuck, ask here, I've written a number of plugins over the years. :) |
|
Just as a quick, yet belated update: I finally came around adjusting my Pelican setup. I noticed that I had unsuccessfully tried to incorporate the handling of this corner case in my larger plugin. However, with the the pointers provided by @avaris, I was able to adjust my code and succeed, ditching the workaround. :) |
Further to the work I did in PR #2738 (moving all settings to
pathlib.Path).It was decided that it was better to keep the default settings as strings, but this is the code that allows Path's to provided for any of these settings.
Perhaps it makes sense to add this support (since the work is done already), so I've extracted the support code.