fix: Improve testimonial parsing for different dash formats

This commit is contained in:
Paul Gauthier (aider) 2025-03-31 11:42:40 +13:00
parent 2d3162a90b
commit fc6a05ced6

View file

@ -459,20 +459,38 @@ def get_testimonials_js():
link = "" link = ""
# Try to extract author and link if they exist # Try to extract author and link if they exist
# Check for the em dash format first: "— [author](link)"
if "— [" in full_line and "](" in full_line: if "— [" in full_line and "](" in full_line:
author_parts = full_line.split("— [") author_parts = full_line.split("— [")
if len(author_parts) > 1: if len(author_parts) > 1:
author = author_parts[1].split("]")[0].strip() author = author_parts[1].split("]")[0].strip()
# Extract the link if it exists # Extract the link if it exists
link_parts = full_line.split("](") link_parts = full_line.split("](")
if len(link_parts) > 1: if len(link_parts) > 1:
link = link_parts[1].split(")")[0].strip() link = link_parts[1].split(")")[0].strip()
# Check for regular dash format: "- [author](link)"
elif " - [" in full_line and "](" in full_line:
author_parts = full_line.split(" - [")
if len(author_parts) > 1:
author = author_parts[1].split("]")[0].strip()
# Extract the link if it exists
link_parts = full_line.split("](")
if len(link_parts) > 1:
link = link_parts[1].split(")")[0].strip()
# Check for em dash without link: "— author"
elif "" in full_line: elif "" in full_line:
# Format without a link, just plain text author # Format without a link, just plain text author
author_parts = full_line.split("") author_parts = full_line.split("")
if len(author_parts) > 1: if len(author_parts) > 1:
author = author_parts[1].strip() author = author_parts[1].strip()
# Check for regular dash without link: "- author"
elif " - " in full_line:
# Format without a link, just plain text author
author_parts = full_line.split(" - ")
if len(author_parts) > 1:
author = author_parts[1].strip()
testimonials.append( testimonials.append(
{"text": quote_text, "author": author, "link": link} {"text": quote_text, "author": author, "link": link}