Add project common publication tags
This commit is contained in:
@@ -23,8 +23,24 @@ def strip_trailing_hashtag_line(text: str) -> str:
|
||||
return "\n".join(lines).rstrip()
|
||||
|
||||
|
||||
def publication_hashtags(category_tag: str, source_tag: str) -> str:
|
||||
def parse_hash_tags(value: object) -> list[str]:
|
||||
if isinstance(value, list):
|
||||
raw_items = [str(item) for item in value]
|
||||
else:
|
||||
raw_items = re.split(r"[\s,|]+", str(value or ""))
|
||||
tags: list[str] = []
|
||||
seen: set[str] = set()
|
||||
for item in raw_items:
|
||||
tag = normalize_hash_tag(item, "")
|
||||
if tag and tag not in seen:
|
||||
tags.append(tag)
|
||||
seen.add(tag)
|
||||
return tags
|
||||
|
||||
|
||||
def publication_hashtags(category_tag: str, source_tag: str, common_tags: object = "") -> str:
|
||||
tags = [
|
||||
*parse_hash_tags(common_tags),
|
||||
normalize_hash_tag(category_tag, "category"),
|
||||
normalize_hash_tag(source_tag, "source"),
|
||||
]
|
||||
@@ -38,6 +54,7 @@ def build_publication_text(
|
||||
text: str,
|
||||
category_tag: str,
|
||||
source_tag: str,
|
||||
common_tags: object = "",
|
||||
format_title: bool = False,
|
||||
parse_mode: str | None = None,
|
||||
) -> str:
|
||||
@@ -59,7 +76,7 @@ def build_publication_text(
|
||||
break
|
||||
|
||||
if title_idx is None:
|
||||
return publication_hashtags(category_tag, source_tag)
|
||||
return publication_hashtags(category_tag, source_tag, common_tags)
|
||||
|
||||
formatted_lines = []
|
||||
for idx, line in enumerate(cleaned_lines):
|
||||
@@ -84,7 +101,7 @@ def build_publication_text(
|
||||
raw_body = "\n".join(formatted_lines)
|
||||
# Collapse multiple consecutive blank lines to at most two newlines (\n\n)
|
||||
normalized_body = re.sub(r"\n{3,}", "\n\n", raw_body).strip()
|
||||
hashtags = publication_hashtags(category_tag, source_tag)
|
||||
hashtags = publication_hashtags(category_tag, source_tag, common_tags)
|
||||
if hashtags:
|
||||
return f"{normalized_body}\n\n{hashtags}" if normalized_body else hashtags
|
||||
return normalized_body
|
||||
|
||||
Reference in New Issue
Block a user