use pelican_open in order to read the file
This commit is contained in:
parent
f907f764c9
commit
ebb2fdf663
@ -1,25 +1,26 @@
|
|||||||
import os
|
import os
|
||||||
from datetime import datetime
|
|
||||||
from pelican import signals
|
from pelican import signals
|
||||||
from pelican.readers import BaseReader
|
from pelican.readers import BaseReader
|
||||||
|
from pelican.utils import pelican_open
|
||||||
import pypandoc
|
import pypandoc
|
||||||
|
|
||||||
class NewReader(BaseReader):
|
class NewReader(BaseReader):
|
||||||
enabled = True
|
enabled = True
|
||||||
file_extensions = ['md', 'markdown', 'mkd', 'mdown']
|
file_extensions = ['md', 'markdown', 'mkd', 'mdown']
|
||||||
|
|
||||||
|
|
||||||
def read(self, filename):
|
def read(self, filename):
|
||||||
with open(filename) as file:
|
with pelican_open(filename) as text:
|
||||||
metadata_items = []
|
metadata_items = []
|
||||||
in_content = False
|
in_content = False
|
||||||
MD = ''
|
MD = ''
|
||||||
for line in file.readlines():
|
for line in text.splitlines():
|
||||||
splitted = line.split(':', 1)
|
splitted = line.split(':', 1)
|
||||||
if len(splitted) == 2 and not in_content:
|
if len(splitted) == 2 and not in_content:
|
||||||
metadata_items.append(splitted)
|
metadata_items.append(splitted)
|
||||||
else:
|
else:
|
||||||
in_content = True
|
in_content = True
|
||||||
MD += line
|
MD += line + '\n'
|
||||||
|
|
||||||
metadata = {}
|
metadata = {}
|
||||||
for item in metadata_items:
|
for item in metadata_items:
|
||||||
|
Loading…
Reference in New Issue
Block a user