spip specific meta optional

This commit is contained in:
Guilhem Fauré 2023-06-16 10:42:43 +02:00
parent dc80f32df5
commit 548dc36875
2 changed files with 21 additions and 15 deletions

View File

@ -51,6 +51,7 @@ class Configuration:
loglevel: str = "WARNING" # Minimum criticity of logs written in logfile loglevel: str = "WARNING" # Minimum criticity of logs written in logfile
logname: str = "spip2md" # Labelling of logs logname: str = "spip2md" # Labelling of logs
export_filetype: str = "md" # Extension of exported text files 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_articles_export: int = 1000 # TODO reimplement
# max_sections_export: int = 500 # TODO reimplement # max_sections_export: int = 500 # TODO reimplement

View File

@ -583,9 +583,12 @@ class SpipRedactional(SpipWritable):
"lastmod": self.maj, "lastmod": self.maj,
"draft": self._draft, "draft": self._draft,
"description": self._description, "description": self._description,
# Debugging }
"spip_id_secteur": self.id_secteur, # Add debugging meta if needed
if CFG.debug_meta:
meta = meta | {
"spip_id": self._id, "spip_id": self._id,
"spip_id_secteur": self.id_secteur,
} }
# Add url if different of directory # Add url if different of directory
if self.url() not in self.dest_directory(): if self.url() not in self.dest_directory():
@ -723,9 +726,10 @@ class Article(SpipRedactional, SpipArticles):
"subtitle": self.soustitre, "subtitle": self.soustitre,
"date": self.date_redac, "date": self.date_redac,
"authors": [author.nom for author in self.authors()], "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: if append is not None:
return super().frontmatter(meta | append) return super().frontmatter(meta | append)
else: else:
@ -781,15 +785,16 @@ class Section(SpipRedactional, SpipRubriques):
class Meta: class Meta:
table_name: str = "spip_rubriques" table_name: str = "spip_rubriques"
def frontmatter(self, append: Optional[dict[str, Any]] = None) -> str: def frontmatter(self, add: Optional[dict[str, Any]] = None) -> str:
meta: dict[str, Any] = { meta: dict[str, Any] = {}
# Debugging # Add debugging meta if needed
if CFG.debug_meta:
meta = meta | {
"spip_id_parent": self.id_parent, "spip_id_parent": self.id_parent,
"spip_profondeur": self.profondeur, "spip_profondeur": self.profondeur,
} }
if append is not None: if add is not None:
return super().frontmatter(meta | append) meta = meta | add
else:
return super().frontmatter(meta) return super().frontmatter(meta)
# Get articles of this section # Get articles of this section