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

ralsina added 6 commits Jun 5, 2017
@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.

@ralsina
Copy link
Member Author

@ralsina ralsina commented Jun 5, 2017

@felixfontein it all gets converted to lowercase.

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

This comment has been minimized.

@felixfontein

felixfontein Jun 5, 2017
Contributor

Here it isn't converted to lowercase.

This comment has been minimized.

@ralsina

ralsina Jun 6, 2017
Author Member

Good catch! Fixed.

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

This comment has been minimized.

@felixfontein

felixfontein Jun 5, 2017
Contributor

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

This comment has been minimized.

@felixfontein

felixfontein Jun 5, 2017
Contributor

Here also not.

ralsina added 2 commits Jun 5, 2017
Copy link
Member

@Kwpolska Kwpolska left a comment

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)

This comment has been minimized.

@Kwpolska

Kwpolska Jun 6, 2017
Member

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

This comment has been minimized.

@ralsina

ralsina Jun 6, 2017
Author Member

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

This comment has been minimized.

@felixfontein

felixfontein Jun 6, 2017
Contributor

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

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

This comment has been minimized.

@Kwpolska

Kwpolska Jun 6, 2017
Member

No need to do fallback with 'nikola' here

@@ -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', []):

This comment has been minimized.

@Kwpolska

Kwpolska Jun 6, 2017
Member

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

This comment has been minimized.

@ralsina

ralsina Jun 6, 2017
Author Member

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] == '---':

This comment has been minimized.

@Kwpolska

Kwpolska Jun 6, 2017
Member

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

This comment has been minimized.

@ralsina

ralsina Jun 6, 2017
Author Member

+++ 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())

This comment has been minimized.

@Kwpolska

Kwpolska Jun 6, 2017
Member

pass data here!

This comment has been minimized.

@ralsina

ralsina Jun 6, 2017
Author Member

Doh

ralsina added 2 commits Jun 6, 2017
@ralsina ralsina merged commit b106682 into master Jun 6, 2017
0 of 4 checks passed
0 of 4 checks passed
continuous-integration/appveyor/branch Waiting for AppVeyor build to complete
Details
continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details
@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