From b245ff75c578463580cbc7a4512b620d997aefff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Fri, 23 Jun 2023 15:11:01 +0200 Subject: [PATCH] option to rename taxonomies --- README.md | 5 +++-- spip2md/config.py | 1 + spip2md/extended_models.py | 14 ++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1601029..069e8fd 100644 --- a/README.md +++ b/README.md @@ -106,8 +106,9 @@ prepend_h1: false # Add title of articles as Markdown h1, looks better on certai # dest: title # repr: "{} _" # (this is the default repr) move_fields: [] -# Some Spip Mots (tags) types to not export, typically specific to Spip functions -ignore_tags_types: ["Gestion du site", "Gestion des articles", "Mise en page"] +# Some taxonomies (Spip Mots types) to not export, typically specific to Spip functions +ignore_taxonomies: ["Gestion du site", "Gestion des articles", "Mise en page"] +rename_taxonomies: { equipes: "tag-equipes" } # Rename taxonomies (prenvent conflict) # Ignored data settings export_drafts: true # Should we export drafts diff --git a/spip2md/config.py b/spip2md/config.py index 61a1262..4202882 100644 --- a/spip2md/config.py +++ b/spip2md/config.py @@ -73,6 +73,7 @@ class Configuration: export_empty: bool = True # Should we export empty articles remove_html: bool = True # Should spip2md remove every HTML tags ignore_taxonomies = ("Gestion du site", "Gestion des articles", "Mise en page") + rename_taxonomies: dict[str, str] = {"equipes": "tag-equipes"} metadata_markup: bool = False # Should spip2md keep the markup in metadata fields title_max_length: int = 40 # Maximum length of a single title for directory names unknown_char_replacement: str = "??" # Replaces unknown characters diff --git a/spip2md/extended_models.py b/spip2md/extended_models.py index b6c23da..77cff85 100644 --- a/spip2md/extended_models.py +++ b/spip2md/extended_models.py @@ -577,18 +577,24 @@ class SpipRedactional(SpipWritable): self._taxonomies = {} for tag in self.taxonomies(): - if tag.type not in CFG.ignore_taxonomies: + taxonomy = str(tag.type) + if taxonomy not in CFG.ignore_taxonomies: LOG.debug( f"Translate taxonomy of `{self._url_title}`: {tag.descriptif}" ) - if str(tag.type) in self._taxonomies: - self._taxonomies[str(tag.type)].append( + if taxonomy in CFG.rename_taxonomies: + LOG.debug( + f"Rename taxonomy {taxonomy}: {CFG.rename_taxonomies[taxonomy]}" + ) + taxonomy = CFG.rename_taxonomies[taxonomy] + if str(taxonomy) in self._taxonomies: + self._taxonomies[taxonomy].append( self.convert_field( self.translate_multi(forcedlang, str(tag.descriptif), False) ) ) else: - self._taxonomies[str(tag.type)] = [ + self._taxonomies[taxonomy] = [ self.convert_field( self.translate_multi(forcedlang, str(tag.descriptif), False) )