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

Add option to attempt splitting metadata using \n\n if metadata delimiters are missing #19

Open
Holzhaus opened this issue Dec 29, 2020 · 3 comments

Comments

@Holzhaus
Copy link
Contributor

This might work for very simple metadata, like:

title: Foo bar
date: 2020-01-01 10:00:00

This is text

If the metadata delimiters are not found and the option is enabled, the plugin could do something like this:

meta, sep, content = text.partition("\n\n")
try:
    metadata = yaml.load(meta, Loader=...)
except yaml.error.YAMLError:
    content = text
    metadata = {}
else:
    # Prevent false-positives if the text does not begin with a metadata block
    if isinstance(metadata, str):
        metadata = {}
        content = text

self.md.Meta = metadata
return content
@sivakov512
Copy link
Owner

I prefer a strict approach, such as with a metadata\yaml separator. This is more obvious and avoids unexpected behavior.

@Holzhaus
Copy link
Contributor Author

Holzhaus commented Jul 18, 2021

I agree that this should generally be preferred. However, sometimes existing data is in the old format. Have you looked at the linked PR #21? It makes this behavior configurable (off by default).

Use case: I migrated @mixxxdj/website to Pelican from cactus and used your module to add support for extra metadata. But most of the old blog posts lack the YAML delimiters and changing them all would be really annoying.

@sivakov512
Copy link
Owner

Okay, use case sounds good.

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 a pull request may close this issue.

2 participants