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

[WIP] Change draft, private and mathjax to own metadata (#2761) #3066

Merged
merged 14 commits into from May 1, 2018

Conversation

felixfontein
Copy link
Contributor

Fixes #2761.

First try. Hacked together on a train ride. More will follow during the next days :)

@felixfontein felixfontein added this to the v8.0.0 milestone Apr 26, 2018
@felixfontein felixfontein self-assigned this Apr 26, 2018
@getnikola getnikola deleted a comment Apr 26, 2018
@getnikola getnikola deleted a comment Apr 27, 2018
Copy link
Member

@Kwpolska Kwpolska left a 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 at least deprecate the tags feature and convince users to convert their input files, and definitely don’t mention the old tags as much in the docs.


# If set to True, the tags 'draft', 'mathjax' and 'private' have special
# meaning. If set to False, these tags are handled like regular tags.
# USE_TAG_METADATA = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn’t mind deprecating the tags in v8, conf.py-defaulting this to False, and providing a plugin that can upgrade posts from the old format to the new.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give the plugin a shot tomorrow.

if status == 'trash':
LOGGER.warn('Trashed post "{0}" will not be imported.'.format(title))
return False
elif status == 'private':
tags.append('private')
if self.site.config['USE_TAG_METADATA']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t bother.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gone.

nikola/post.py Outdated
self._tags[lang].remove('private')
status = self.meta[lang].get('status')
if status:
if status == 'published':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrite this, make it shorter (three lines above, one line in each if block)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote this, but not completely: I don't want to update post_status in case status has an invalid value. (Of course, we could turn this into an error. But it might screw up existing blogs which for whatever reason used status metadata already...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be me and the projectpages plugin (I guess I’ll make it devstatus from now on.)

nikola/post.py Outdated
@@ -312,14 +343,28 @@ def _has_pretty_url(self, lang):

@property
def is_mathjax(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be renamed to has_math for consistency and neatness.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep a is_mathjax dummy which logs that an update needs to be done to the theme, and returns the new has_math value? Otherwise, we might break some custom themes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is v8, feel free to break themes. (They should switch to math_helper.tmpl anyways.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@felixfontein
Copy link
Contributor Author

I've now taken a look at your upgrade_metadata plugin. A plugin for this case will be much more complicated: we have two-file posts and one-file posts, we have various metadata extraction plugins, and various metadata formats. Are you sure we want to support everything? Or should I restrict myself to classic ReST-style metadata?

@Kwpolska
Copy link
Member

Re upgrader plugin: this should be doable, as metadata extractors can also write to files. If posts don’t know what extractor data comes from, that could be changed — or we could just let users modify their post themselves.

@Kwpolska
Copy link
Member

Bonus feature request: support .. status: featured in a similar way. Will come in handy for the planned extensions to bootblog4.

@felixfontein
Copy link
Contributor Author

I've added featured as a valid state. I'll take a look at the converter plugin again soon (definitely not today though).

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Copy link
Member

@Kwpolska Kwpolska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (with very minor fixes I applied)

nikola/post.py Outdated
show_warning = True
if show_warning:
LOGGER.warn('It is suggested that you convert special tags to metadata and set ' +
'USE_TAG_METADATA to False. You can use the XXX command plugin for ' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove that sentence about this plugin for the time being so we can merge this more quickly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus code style hint: you do not need + to join two strings literals separated by whitespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

CHANGES.txt Outdated
@@ -20,8 +20,8 @@ Features
--------

* Tags ``draft``, ``private`` and ``mathjax`` are no longer treated
special if ``USE_TAG_METADATA`` is set to ``True`` (default for
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Thanks :)

nikola/post.py Outdated
@@ -359,13 +359,13 @@ def has_math(self):
return True
lang = nikola.utils.LocaleBorg().current_lang
if self.is_translation_available(lang):
if self.meta[lang].get('has_math') in ('true', 'True', 'yes'):
if self.meta[lang].get('has_math') in ('true', 'True', 'yes', '1', 1, True):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

@felixfontein
Copy link
Contributor Author

Ok. I guess we can merge this for now; I'll open a new PR for the plugin then.

@Kwpolska Kwpolska merged commit af3c6a1 into master May 1, 2018
@Kwpolska Kwpolska deleted the implement-2761 branch May 1, 2018 20:38
@Kwpolska
Copy link
Member

Kwpolska commented May 1, 2018

Thanks for getting this done!

@felixfontein
Copy link
Contributor Author

Thanks for reviewing and merging!

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

Successfully merging this pull request may close these issues.

None yet

2 participants