option to rename taxonomies

This commit is contained in:
Guilhem Fauré 2023-06-23 15:11:01 +02:00
parent 8769185b8d
commit b245ff75c5
3 changed files with 14 additions and 6 deletions

View File

@ -106,8 +106,9 @@ prepend_h1: false # Add title of articles as Markdown h1, looks better on certai
# dest: title # dest: title
# repr: "{} _" # (this is the default repr) # repr: "{} _" # (this is the default repr)
move_fields: [] move_fields: []
# Some Spip Mots (tags) types to not export, typically specific to Spip functions # Some taxonomies (Spip Mots types) to not export, typically specific to Spip functions
ignore_tags_types: ["Gestion du site", "Gestion des articles", "Mise en page"] ignore_taxonomies: ["Gestion du site", "Gestion des articles", "Mise en page"]
rename_taxonomies: { equipes: "tag-equipes" } # Rename taxonomies (prenvent conflict)
# Ignored data settings # Ignored data settings
export_drafts: true # Should we export drafts export_drafts: true # Should we export drafts

View File

@ -73,6 +73,7 @@ class Configuration:
export_empty: bool = True # Should we export empty articles export_empty: bool = True # Should we export empty articles
remove_html: bool = True # Should spip2md remove every HTML tags remove_html: bool = True # Should spip2md remove every HTML tags
ignore_taxonomies = ("Gestion du site", "Gestion des articles", "Mise en page") 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 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 title_max_length: int = 40 # Maximum length of a single title for directory names
unknown_char_replacement: str = "??" # Replaces unknown characters unknown_char_replacement: str = "??" # Replaces unknown characters

View File

@ -577,18 +577,24 @@ class SpipRedactional(SpipWritable):
self._taxonomies = {} self._taxonomies = {}
for tag in 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( LOG.debug(
f"Translate taxonomy of `{self._url_title}`:{tag.descriptif}" f"Translate taxonomy of `{self._url_title}`:{tag.descriptif}"
) )
if str(tag.type) in self._taxonomies: if taxonomy in CFG.rename_taxonomies:
self._taxonomies[str(tag.type)].append( 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.convert_field(
self.translate_multi(forcedlang, str(tag.descriptif), False) self.translate_multi(forcedlang, str(tag.descriptif), False)
) )
) )
else: else:
self._taxonomies[str(tag.type)] = [ self._taxonomies[taxonomy] = [
self.convert_field( self.convert_field(
self.translate_multi(forcedlang, str(tag.descriptif), False) self.translate_multi(forcedlang, str(tag.descriptif), False)
) )