proper taxonomy management, no more tags only
This commit is contained in:
parent
164a1e8228
commit
8769185b8d
@ -72,7 +72,7 @@ class Configuration:
|
|||||||
export_drafts: bool = True # Should we export drafts as draft:true articles
|
export_drafts: bool = True # Should we export drafts as draft:true articles
|
||||||
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_tags_types = ("Gestion du site", "Gestion des articles", "Mise en page")
|
ignore_taxonomies = ("Gestion du site", "Gestion des articles", "Mise en page")
|
||||||
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
|
||||||
|
@ -354,7 +354,7 @@ class SpipRedactional(SpipWritable):
|
|||||||
langue_choisie: str
|
langue_choisie: str
|
||||||
# Converted
|
# Converted
|
||||||
_text: str
|
_text: str
|
||||||
_tags: list[str] = []
|
_taxonomies: dict[str, list[str]] = {}
|
||||||
_url_title: str # Title in metadata of articles
|
_url_title: str # Title in metadata of articles
|
||||||
_parenturl: str # URL relative to lang to direct parent
|
_parenturl: str # URL relative to lang to direct parent
|
||||||
_static_img_path: Optional[str] = None # Path to the static img of this article
|
_static_img_path: Optional[str] = None # Path to the static img of this article
|
||||||
@ -573,17 +573,30 @@ class SpipRedactional(SpipWritable):
|
|||||||
LOG.debug(f"Apply conversions to {self.lang} `{self._url_title}` extra")
|
LOG.debug(f"Apply conversions to {self.lang} `{self._url_title}` extra")
|
||||||
self._extra = self.convert_field(self._extra, CFG.metadata_markup)
|
self._extra = self.convert_field(self._extra, CFG.metadata_markup)
|
||||||
|
|
||||||
def convert_tags(self, forcedlang: str) -> None:
|
def convert_taxonomies(self, forcedlang: str) -> None:
|
||||||
def out_tag(tag: SpipMots) -> str:
|
self._taxonomies = {}
|
||||||
LOG.debug(f"Translate tag of `{self._url_title}`: {tag.descriptif}")
|
|
||||||
return self.convert_field(
|
for tag in self.taxonomies():
|
||||||
|
if tag.type 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(
|
||||||
|
self.convert_field(
|
||||||
|
self.translate_multi(forcedlang, str(tag.descriptif), False)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._taxonomies[str(tag.type)] = [
|
||||||
|
self.convert_field(
|
||||||
self.translate_multi(forcedlang, str(tag.descriptif), False)
|
self.translate_multi(forcedlang, str(tag.descriptif), False)
|
||||||
)
|
)
|
||||||
|
|
||||||
self._tags = [
|
|
||||||
out_tag(tag) for tag in self.tags() if tag.type not in CFG.ignore_tags_types
|
|
||||||
]
|
]
|
||||||
LOG.debug(f"After translation, tags of `{self._url_title}` are {self._tags}")
|
|
||||||
|
LOG.debug(
|
||||||
|
f"After translation, taxonomies of `{self._url_title}`: {self._taxonomies}"
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@ -659,8 +672,8 @@ class SpipRedactional(SpipWritable):
|
|||||||
.where(SpipAuteursLiens.id_objet == self._id)
|
.where(SpipAuteursLiens.id_objet == self._id)
|
||||||
)
|
)
|
||||||
|
|
||||||
def tags(self) -> tuple[SpipMots, ...]:
|
def taxonomies(self) -> tuple[SpipMots, ...]:
|
||||||
LOG.debug(f"Initialize tags of `{self._url_title}`")
|
LOG.debug(f"Initialize taxonomies of `{self._url_title}`")
|
||||||
return (
|
return (
|
||||||
SpipMots.select()
|
SpipMots.select()
|
||||||
.join(
|
.join(
|
||||||
@ -767,7 +780,7 @@ class SpipRedactional(SpipWritable):
|
|||||||
self.convert_title(forced_lang)
|
self.convert_title(forced_lang)
|
||||||
self.convert_text(forced_lang)
|
self.convert_text(forced_lang)
|
||||||
self.convert_extra()
|
self.convert_extra()
|
||||||
self.convert_tags(forced_lang)
|
self.convert_taxonomies(forced_lang)
|
||||||
if self.lang != forced_lang:
|
if self.lang != forced_lang:
|
||||||
raise LangNotFoundError(
|
raise LangNotFoundError(
|
||||||
f"`{self._url_title}` lang is {self.lang} instead of the wanted"
|
f"`{self._url_title}` lang is {self.lang} instead of the wanted"
|
||||||
@ -803,11 +816,12 @@ 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()],
|
||||||
"tags": self._tags,
|
|
||||||
}
|
}
|
||||||
# Add debugging meta if needed
|
# Add debugging meta if needed
|
||||||
if CFG.debug_meta:
|
if CFG.debug_meta:
|
||||||
meta = meta | {"spip_id_rubrique": self.id_rubrique}
|
meta |= {"spip_id_rubrique": self.id_rubrique}
|
||||||
|
if self._taxonomies:
|
||||||
|
meta |= self._taxonomies
|
||||||
if append is not None:
|
if append is not None:
|
||||||
return super().frontmatter(meta | append)
|
return super().frontmatter(meta | append)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user