From 548dc368754f2b4d52fca4435c9e675eae3f6507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Fri, 16 Jun 2023 10:42:43 +0200 Subject: [PATCH] spip specific meta optional --- spip2md/config.py | 1 + spip2md/extended_models.py | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/spip2md/config.py b/spip2md/config.py index 079dcd3..d00a4f6 100644 --- a/spip2md/config.py +++ b/spip2md/config.py @@ -51,6 +51,7 @@ class Configuration: loglevel: str = "WARNING" # Minimum criticity of logs written in logfile logname: str = "spip2md" # Labelling of logs export_filetype: str = "md" # Extension of exported text files + debug_meta: bool = False # Include more metadata from SPIP DB in frontmatters # max_articles_export: int = 1000 # TODO reimplement # max_sections_export: int = 500 # TODO reimplement diff --git a/spip2md/extended_models.py b/spip2md/extended_models.py index c0442ab..6335d25 100644 --- a/spip2md/extended_models.py +++ b/spip2md/extended_models.py @@ -583,10 +583,13 @@ class SpipRedactional(SpipWritable): "lastmod": self.maj, "draft": self._draft, "description": self._description, - # Debugging - "spip_id_secteur": self.id_secteur, - "spip_id": self._id, } + # Add debugging meta if needed + if CFG.debug_meta: + meta = meta | { + "spip_id": self._id, + "spip_id_secteur": self.id_secteur, + } # Add url if different of directory if self.url() not in self.dest_directory(): meta = meta | {"url": self.url()} @@ -723,9 +726,10 @@ class Article(SpipRedactional, SpipArticles): "subtitle": self.soustitre, "date": self.date_redac, "authors": [author.nom for author in self.authors()], - # Debugging - "spip_id_rubrique": self.id_rubrique, } + # Add debugging meta if needed + if CFG.debug_meta: + meta = meta | {"spip_id_rubrique": self.id_rubrique} if append is not None: return super().frontmatter(meta | append) else: @@ -781,16 +785,17 @@ class Section(SpipRedactional, SpipRubriques): class Meta: table_name: str = "spip_rubriques" - def frontmatter(self, append: Optional[dict[str, Any]] = None) -> str: - meta: dict[str, Any] = { - # Debugging - "spip_id_parent": self.id_parent, - "spip_profondeur": self.profondeur, - } - if append is not None: - return super().frontmatter(meta | append) - else: - return super().frontmatter(meta) + def frontmatter(self, add: Optional[dict[str, Any]] = None) -> str: + meta: dict[str, Any] = {} + # Add debugging meta if needed + if CFG.debug_meta: + meta = meta | { + "spip_id_parent": self.id_parent, + "spip_profondeur": self.profondeur, + } + if add is not None: + meta = meta | add + return super().frontmatter(meta) # Get articles of this section def articles(self, limit: int = 10**6) -> tuple[Article]: