fix: Improve testimonial parsing from README

This commit is contained in:
Paul Gauthier (aider) 2025-03-31 11:41:44 +13:00
parent c7f1671d5a
commit 83c599e741

View file

@ -424,33 +424,68 @@ def get_testimonials_js():
try: try:
with open(readme_path, "r", encoding="utf-8") as f: with open(readme_path, "r", encoding="utf-8") as f:
for line in f: lines = f.readlines()
# Check if we're entering the testimonials section
# Find the testimonials section
for i, line in enumerate(lines):
if line.strip() == "## Kind Words From Users": if line.strip() == "## Kind Words From Users":
in_testimonials_section = True in_testimonials_section = True
continue # Start processing from the next line
start_idx = i + 1
# If we've hit another section after testimonials, stop
if in_testimonials_section and line.startswith("##"):
break break
# Process testimonial lines # If we found the section
if in_testimonials_section and line.strip().startswith('- *"'): if in_testimonials_section:
# Extract the quote text: between *" and "* for i in range(start_idx, len(lines)):
quote_match = line.split('*"')[1].split('"*')[0].strip() line = lines[i]
# If we've hit another section, stop
# Extract the author: between "— [" and "]" if line.startswith("##"):
author_match = line.split("— [")[1].split("]")[0].strip() break
# Extract the link: between "(" and ")" # Process testimonial lines
link_match = line.split("](")[1].split(")")[0].strip() if line.strip().startswith('- *"'):
try:
testimonials.append( # Get the full line
{"text": quote_match, "author": author_match, "link": link_match} full_line = line.strip()
)
# Extract the quote text between *" and "*
if '*"' in full_line and '"*' in full_line:
quote_parts = full_line.split('*"')
if len(quote_parts) > 1:
quote_text = quote_parts[1].split('"*')[0].strip()
# Default values
author = "Anonymous"
link = ""
# Try to extract author and link if they exist
if "— [" 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()
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({
"text": quote_text,
"author": author,
"link": link
})
except Exception as e:
print(f"Error parsing testimonial line: {line}. Error: {e}", file=sys.stderr)
continue
# Format as JavaScript array with script tags # Format as JavaScript array with script tags
if not testimonials: if not testimonials:
print("No testimonials found in README.md", file=sys.stderr)
return "<script>\nconst testimonials = [];\n</script>" return "<script>\nconst testimonials = [];\n</script>"
js_array = "<script>\nconst testimonials = [\n" js_array = "<script>\nconst testimonials = [\n"