spip2md/metadata.py
2023-04-21 08:29:43 +00:00

20 lines
558 B
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import yaml
from slugify import slugify
class metadata:
# row is an array containing at positions:
# 0: id
# 2: title (titre)
# 7: body (texte)
# 9: date
def __init__(self, row):
self.id = row[0]
self.title = row[2]
self.date = row[9]
def get_title(self):
return "# {}\n".format(self.title)
def get_slug(self):
return slugify("{}-{}".format(self.id, self.title))
def get_frontmatter(self):
return "---\n{}---".format(yaml.dump({"title": self.title, "date": self.date}))