feat: dynamically load testimonials from README using cog

This commit is contained in:
Paul Gauthier (aider) 2025-03-28 15:48:39 -10:00
parent 424b43b3d3
commit 04b3ada7f7
2 changed files with 175 additions and 103 deletions

View file

@ -238,8 +238,13 @@ aider --model o3-mini --api-key openai=&lt;key&gt;</code></pre>
</section>
<script>
// All testimonials from the README
const testimonials = [
// Testimonials dynamically loaded from README
<!--[[[cog
from scripts.badges import get_testimonials_js
text = get_testimonials_js()
cog.out(text)
]]]-->
const testimonials = [
{
text: "The best free open source AI coding assistant.",
author: "IndyDevDan",
@ -340,7 +345,8 @@ aider --model o3-mini --api-key openai=&lt;key&gt;</code></pre>
author: "Nick Dobos",
link: "https://twitter.com/NickADobos/status/1690408967963652097?s=20"
}
];
];
<!--[[[end]]]-->
// Function to shuffle array
function shuffleArray(array) {

View file

@ -410,6 +410,72 @@ def get_badges_html():
return html
def get_testimonials_js():
"""
Extract testimonials from README.md and format them as JavaScript array
"""
# Path to README.md, relative to this script
readme_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
"README.md"
)
testimonials = []
in_testimonials_section = False
try:
with open(readme_path, "r", encoding="utf-8") as f:
for line in f:
# Check if we're entering the testimonials section
if line.strip() == "## Kind Words From Users":
in_testimonials_section = True
continue
# If we've hit another section after testimonials, stop
if in_testimonials_section and line.startswith("##"):
break
# Process testimonial lines
if in_testimonials_section and line.strip().startswith("- *\""):
# Extract the quote text: between *" and "*
quote_match = line.split("*\"")[1].split("\"*")[0].strip()
# Extract the author: between "— [" and "]"
author_match = line.split("— [")[1].split("]")[0].strip()
# Extract the link: between "(" and ")"
link_match = line.split("](")[1].split(")")[0].strip()
testimonials.append({
"text": quote_match,
"author": author_match,
"link": link_match
})
# Format as JavaScript array
if not testimonials:
return "const testimonials = [];"
js_array = "const testimonials = [\n"
for i, t in enumerate(testimonials):
js_array += f" {{\n"
js_array += f" text: \"{t['text']}\",\n"
js_array += f" author: \"{t['author']}\",\n"
js_array += f" link: \"{t['link']}\"\n"
js_array += " }"
if i < len(testimonials) - 1:
js_array += ","
js_array += "\n"
js_array += "];"
return js_array
except Exception as e:
print(f"Error reading testimonials from README: {e}", file=sys.stderr)
# Return empty array as fallback
return "const testimonials = [];"
def main():
# Load environment variables from .env file
load_dotenv()