in plugins/gfm.py [0:0]
def read_source(self, source_path):
"Read metadata and content from the source."
# Prepare the "slug", which is the target file name. It will be the
# same as the source file, minus the leading ".../content/(articles|pages)"
# and with the extension removed (Pelican will add .html)
relpath = os.path.relpath(source_path, self.settings['PATH'])
parts = relpath.split(os.sep)
parts[-1] = os.path.splitext(parts[-1])[0] # split off ext, keep base
slug = os.sep.join(parts[1:])
metadata = {
'slug': slug,
}
# Fetch the source content, with a few appropriate tweaks
with pelican.utils.pelican_open(source_path) as text:
# Extract the metadata from the header of the text
lines = text.splitlines()
i = 0 # See https://github.com/apache/infrastructure-pelican/issues/70
for i in range(len(lines)):
line = lines[i]
match = GFMReader.RE_METADATA.match(line)
if match:
name = match.group(1).strip().lower()
if name != 'slug':
value = match.group(2).strip()
if name == 'date':
value = pelican.utils.get_date(value)
metadata[name] = value
#if name != 'title':
# print 'META:', name, value
elif not line.strip():
# blank line
continue
else:
# reached actual content
break
# Redo the slug for articles.
# depending on pelicanconf.py this will change the output filename
if parts[0] == 'articles' and 'title' in metadata:
metadata['slug'] = pelican.utils.slugify(
metadata['title'],
self.settings.get('SLUG_SUBSTITUTIONS', ()))
# Reassemble content, minus the metadata
text = '\n'.join(lines[i:])
return text, metadata