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

@felixfontein felixfontein commented Jun 5, 2017

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

Loading

@ralsina
Copy link
Member Author

@ralsina ralsina commented Jun 5, 2017

@felixfontein it all gets converted to lowercase.

Loading

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

@felixfontein felixfontein Jun 5, 2017

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.

Loading

Copy link
Member Author

@ralsina ralsina Jun 6, 2017

Choose a reason for hiding this comment

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

Good catch! Fixed.

Loading

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

@felixfontein felixfontein Jun 5, 2017

Choose a reason for hiding this comment

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

Here neither.

Loading

@@ -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

@felixfontein felixfontein Jun 5, 2017

Choose a reason for hiding this comment

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

Here also not.

Loading

Copy link
Member

@Kwpolska Kwpolska left a comment

Pretty good, except for one breaking bug.

Loading

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

@Kwpolska Kwpolska Jun 6, 2017

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

Loading

Copy link
Member Author

@ralsina ralsina Jun 6, 2017

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 :-)

Loading

Copy link
Contributor

@felixfontein felixfontein Jun 6, 2017

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 :)

Loading

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

@Kwpolska Kwpolska Jun 6, 2017

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

Loading

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

@Kwpolska Kwpolska Jun 6, 2017

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

Loading

Copy link
Member Author

@ralsina ralsina Jun 6, 2017

Choose a reason for hiding this comment

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

Done.

Loading

# 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

@Kwpolska Kwpolska Jun 6, 2017

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)

Loading

Copy link
Member Author

@ralsina ralsina Jun 6, 2017

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

Loading

# 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

@Kwpolska Kwpolska Jun 6, 2017

Choose a reason for hiding this comment

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

pass data here!

Loading

Copy link
Member Author

@ralsina ralsina Jun 6, 2017

Choose a reason for hiding this comment

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

Doh

Loading

@ralsina ralsina merged commit b106682 into master Jun 6, 2017
0 of 4 checks passed
Loading
@ralsina ralsina deleted the choose-metadata-format branch Jun 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants