From a45a67b30b341f99f37fd17deac5f0ed9d87b851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Fri, 21 Apr 2023 16:49:09 +0200 Subject: [PATCH] =?UTF-8?q?handle=20every=20non-cryptic=20metadata=20that?= =?UTF-8?q?=20doesn=E2=80=99t=20need=20joins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spip2md/metadata.py | 52 ++++++++++++++++++++++++++++++++++++++++----- spip2md/spip2md.py | 9 +++++--- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/spip2md/metadata.py b/spip2md/metadata.py index f0c1218..8493c84 100644 --- a/spip2md/metadata.py +++ b/spip2md/metadata.py @@ -5,14 +5,56 @@ from slugify import slugify class metadata: def __init__(self, article): self.id = article.id_article + # self.surtitle = article.surtitre # Probably unused self.title = article.titre - self.date = article.date - - def get_title(self): - return "# {}\n".format(self.title) + self.subtitle = article.soustitre # Probably unused + # self.section = article.id_rubrique # TODO join + self.caption = article.chapo # Probably unused + self.ps = article.ps # Probably unused + self.publicationDate = article.date + self.status = article.statut + # self.sector = article.id_secteur # TODO join + self.update = article.maj + # self.export = article.export # USELESS + self.creationDate = article.date_redac + # self.views = article.visites # USELESS in static + self.referers = article.referers # TODO Why ? + # self.popularity = article.popularite # USELESS in static + self.acceptForum = article.accepter_forum # TODO Why ? + self.contentUpdate = article.date_modif # Probably unused + self.lang = article.lang + self.choosenLang = article.langue_choisie # TODO Why ? + # self.translation = article.id_trad # TODO join + self.extra = article.extra # Probably unused + # self.version = article.id_version # USELESS + self.sitename = article.nom_site # Probably useless + self.virtual = article.virtuel # TODO Why ? + self.microblog = article.microblog # Probably unused 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})) + return "---\n{}---".format( + yaml.dump( + { + "lang": self.lang, + "title": self.title, + "subtitle": self.subtitle, + "creation": self.creationDate, + "date": self.publicationDate, + "update": self.update, + "status": self.status, + } + ) + ) + + # Contains things before the article like caption & titles + def get_starting(self): + return "{}\n\n# {}\n".format(self.caption, self.title) + + # Contains things after the article like ps & extra + def get_ending(self): + return "# EXTRA\n\n{}\n\n# POST-SCRIPTUM\n\n{}\n\n# MICROBLOGGING\n\n{}".format( + self.extra, self.ps, self.microblog + ) diff --git a/spip2md/spip2md.py b/spip2md/spip2md.py index df99396..a0e9612 100755 --- a/spip2md/spip2md.py +++ b/spip2md/spip2md.py @@ -2,7 +2,7 @@ import os import shutil import sys -from datetime import * +from datetime import date, time, datetime # Modules from config import CONFIG @@ -45,8 +45,11 @@ for article in articles: os.mkdir(articleDir) with open("{}/index.md".format(articleDir), "w") as f: f.write( - "{}\n{}\n{}".format( - meta.get_frontmatter(), meta.get_title(), body.get_markdown() + "{}\n{}\n{}\n{}".format( + meta.get_frontmatter(), + meta.get_starting(), + body.get_markdown(), + meta.get_ending(), ) ) # End export if no more to export