Fix explicit anchor text to randomize term selection

Randomize anchor text list before trying terms so all explicit terms
are used across articles instead of always using the first term.
main
PeninsulaInd 2025-12-20 10:01:38 -06:00
parent de21a22b72
commit 56d7e4f642
1 changed files with 4 additions and 0 deletions

View File

@ -336,6 +336,10 @@ def _try_inject_link(html: str, anchor_texts: List[str], target_url: str) -> Tup
Try to inject a link with anchor text into HTML Try to inject a link with anchor text into HTML
Returns (updated_html, link_injected, anchor_text_used) Returns (updated_html, link_injected, anchor_text_used)
""" """
# Randomize order to use different terms across articles
if anchor_texts and len(anchor_texts) > 1:
anchor_texts = random.sample(anchor_texts, len(anchor_texts))
for anchor_text in anchor_texts: for anchor_text in anchor_texts:
# Try to find and wrap anchor text in content # Try to find and wrap anchor text in content
updated_html, found = _find_and_wrap_anchor_text(html, anchor_text, target_url) updated_html, found = _find_and_wrap_anchor_text(html, anchor_text, target_url)