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

Choose metadata format #2823

Merged
merged 14 commits into from Jun 6, 2017
Merged

Choose metadata format #2823

merged 14 commits into from Jun 6, 2017

Conversation

ralsina
Copy link
Member

@ralsina ralsina commented Jun 5, 2017

New METADATA_FORMAT setting, lets you choose how metadata will look on nikola new_post. Part of #2801

@felixfontein
Copy link
Contributor

In the code, you sometimes use lower-case and sometimes title-case variants of the values for METADATA_FORMAT.

@ralsina
Copy link
Member Author

ralsina commented Jun 5, 2017

@felixfontein it all gets converted to lowercase.

nikola/nikola.py Outdated
@@ -960,6 +961,11 @@ def __init__(self, **config):
self._GLOBAL_CONTEXT['subtheme'] = config.get('THEME_REVEAL_CONFIG_SUBTHEME', 'sky')
self._GLOBAL_CONTEXT['transition'] = config.get('THEME_REVEAL_CONFIG_TRANSITION', 'cube')

# The pelican metadata format requires a markdown extension
if config.get('METADATA_FORMAT', 'nikola') == 'pelican':
Copy link
Contributor

Choose a reason for hiding this comment

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

Here it isn't converted to lowercase.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Fixed.

fd.write('<!-- \n')
fd.write(write_metadata(metadata))
fd.write('-->\n\n')
_format = self.site.config.get('METADATA_FORMAT', 'nikola')
Copy link
Contributor

Choose a reason for hiding this comment

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

Here neither.

@@ -177,7 +177,10 @@ def create_post(self, path, **kw):
content += '\n'
with io.open(path, "w+", encoding="utf8") as fd:
if onefile:
fd.write(write_metadata(metadata))
_format = self.site.config.get('METADATA_FORMAT', 'nikola')
Copy link
Contributor

Choose a reason for hiding this comment

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

Here also not.

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.

Pretty good, except for one breaking bug.

When you create new posts, by default the metadata will be created as reST style comments.
If you prefer a different format, you can set the ``METADATA_FORMAT`` to one of these values:

* ``"Nikola"``: reSt comments wrapped in a comment if needed (default)
Copy link
Member

Choose a reason for hiding this comment

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

reST* — here, below, in conf.py.in

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, we also use it for a dozen other formats, and noone else uses it, so I say it's ours :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think Chris means that you typed reSt instead of reST (note the last T), not that you should rename the format :)

nikola/nikola.py Outdated
@@ -960,6 +961,11 @@ def __init__(self, **config):
self._GLOBAL_CONTEXT['subtheme'] = config.get('THEME_REVEAL_CONFIG_SUBTHEME', 'sky')
self._GLOBAL_CONTEXT['transition'] = config.get('THEME_REVEAL_CONFIG_TRANSITION', 'cube')

# The pelican metadata format requires a markdown extension
if config.get('METADATA_FORMAT', 'nikola').lower() == 'pelican':
Copy link
Member

Choose a reason for hiding this comment

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

No need to do fallback with 'nikola' here

nikola/nikola.py Outdated
@@ -960,6 +961,11 @@ def __init__(self, **config):
self._GLOBAL_CONTEXT['subtheme'] = config.get('THEME_REVEAL_CONFIG_SUBTHEME', 'sky')
self._GLOBAL_CONTEXT['transition'] = config.get('THEME_REVEAL_CONFIG_TRANSITION', 'cube')

# The pelican metadata format requires a markdown extension
if config.get('METADATA_FORMAT', 'nikola').lower() == 'pelican':
if 'markdown.extensions.meta' not in config.get('MARKDOWN_EXTENSIONS', []):
Copy link
Member

Choose a reason for hiding this comment

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

if markdown enabled: show warning, without may
else: ignore that

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

# If the metadata starts with "---" it's actually YAML and
# we should not let markdown parse it, because it will do
# bad things like setting empty tags to "''"
if data.splitlines()[0] == '---':
Copy link
Member

Choose a reason for hiding this comment

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

What’s the behavior with +++ ? also, you can just check if data.startswith('---\n'): (Windows-proof because of r mode)

Copy link
Member Author

Choose a reason for hiding this comment

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

+++ means TOML (foo = bar) and that means it's not valid markdown metadata, so nothing bad happens. The problem was that YAML sometimes looks like valid markdown metadata :-P

# we should not let markdown parse it, because it will do
# bad things like setting empty tags to "''"
if data.splitlines()[0] == '---':
return {}
_, meta = self.converter.convert(inf.read())
Copy link
Member

Choose a reason for hiding this comment

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

pass data here!

Copy link
Member Author

Choose a reason for hiding this comment

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

Doh

@ralsina ralsina merged commit b106682 into master Jun 6, 2017
@ralsina ralsina deleted the choose-metadata-format branch June 6, 2017 15:27
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.

None yet

3 participants