Closed wsw70 closed 3 years ago
You can use frontmatter.Post
directly, if you want. You can also use any object that has content
and metadata
properties, where content
is a string and metadata
is a dictionary.
import frontmatter
p = frontmatter.Post("This is some content", title="My post")
frontmatter.dumps(p)
More here: https://python-frontmatter.readthedocs.io/en/latest/api.html#post-objects
Thank you @eyeseast .
I tried exactly this but for a reason it failed. Thinkng that it cannot be done, I ended up with a workaround (below is a shortened version to highlight the workaround):
def create():
# read template
f = io.StringIO("---\n---")
note = frontmatter.load(f)
filename = f"{uuid.uuid4().hex}.note"
with open(filename, 'wb') as f:
frontmatter.dump(note, f)
I will therefore try again, thanks!
I have successfully read and parsed files with front matter and content.
I now would like to create one from scratch (provide entries for the frontmatter and a content. Is this possible?
I see it is possible to write back a file read with
frontmatter
, but I did not see the "from scratch" version in the docs.