getnikola / plugins

Extra plugins for Nikola
https://plugins.getnikola.com/
MIT License
56 stars 92 forks source link

Surprising behaviour of plugin Medium and Devto (pseudo-boolean post options) #404

Open JesperDramsch opened 2 years ago

JesperDramsch commented 2 years ago

I was a bit confused with the medium and devto plugins (not sure other plugins have this problem).

The documentation says:

At that point your posts with the "devto" metadata set to "yes" or "true" should be published.

But I have a hard time remembering all the keywords, so I set the standard keywords to

medium: False
devto: False

This will lead medium and devto to publish all articles, due to something that I'd say is unintuitive and should be changed to improve usability.

The code says: https://github.com/getnikola/plugins/blob/c9305572359263c719b19dc17bb6770521e08dee/v8/devto/devto_plugin.py#L67 https://github.com/getnikola/plugins/blob/c9305572359263c719b19dc17bb6770521e08dee/v8/medium/medium_plugin.py#L69

since post.meta('devto') is text, it will always be true, regardless of the value it was set. (Pseudo-)Boolean keywords like this should probably have an "off" switch.

Locally, I changed mine to:

to_post = [post for post in posts if post.title() not in devto_titles and (post.meta('devto').lower() in ["yes", "true"])]

I don't know if that's the best way to handle it. Happy to discuss solutions and make a pull request.

ralsina commented 2 years ago

Yeah, basically if it's set to anything it will be "True" ...

That change you made makes sense. Since there are not all that many users of these plugins I think it would be an acceptable thing.

JesperDramsch commented 2 years ago

I could negate the command as

to_post = [post for post in posts if post.title() not in devto_titles and (post.meta('devto').lower() not in ["no", "false"])]

which would minimize surprising behaviour to anyone using it. I'll make a quick PR.