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
Choose metadata format #2823
Conversation
In the code, you sometimes use lower-case and sometimes title-case variants of the values for |
@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': |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here also not.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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': |
There was a problem hiding this comment.
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', []): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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] == '---': |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass data
here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh
New METADATA_FORMAT setting, lets you choose how metadata will look on nikola new_post. Part of #2801