eyeseast / python-frontmatter

Parse and manage posts with YAML (or other) frontmatter
http://python-frontmatter.rtfd.io
MIT License
333 stars 42 forks source link

No metadata is read #69

Closed Atulin closed 4 years ago

Atulin commented 4 years ago
fm = frontmatter.load(os.path.join(path + file), encoding='utf-8')
if len(fm.keys()) < 6:
    print(str(len(fm.keys())))
    print(fm.content)

For each and every file the first print prints 0, and the second print prints the entire content of the file, including the frontmatter block and all.

All files look more-or-less like so:

---
Title: "\"Guest Speaker\" Sub-Lecture: Collaborations and learning from the best."
Author: Flint Sparks
Date: "Sat, 16 Nov 2013 04:22:00 "
Category: 
Tags:
---
Ever wanted to write...
Atulin commented 4 years ago

I thought that me generating the files with

''.join([
  '---\n',
  f'Author: {author}',
  ...,
  '---\n'
])

might've been at fault, so I went with

post: Post = Post(data['Body'].strip())
post['Title'] = data['Title']
post['Author'] = data['Author']
post['Date'] = data['Date']
post['Category'] = data['Category']
post['Tags'] = data['Tags']

and frontmatter.dumps() instead, hoping that it'll create correct and valid files.

Alas, the problem still persists. Files generated in this way still seem to contain no metadata, and their entirety is treated as the content.

Atulin commented 4 years ago

When encoding on read isn't set to utf-8, the first character in the file is , only then followed by three dashes. Could be the culprit.

Edit: yes, it was. Seems to be fixed by creating the files with utf-8 encoding instead of utf-8-sig