()
| 345 | |
| 346 | |
| 347 | def generate_readme_content() -> str: |
| 348 | en_index = en_docs_path / "docs" / "index.md" |
| 349 | content = en_index.read_text("utf-8") |
| 350 | content = remove_header_permalinks(content) # remove permalinks from headers |
| 351 | match_pre = re.search(r"</style>\n\n", content) |
| 352 | match_start = re.search(r"<!-- sponsors -->", content) |
| 353 | match_end = re.search(r"<!-- /sponsors -->", content) |
| 354 | sponsors_data_path = en_docs_path / "data" / "sponsors.yml" |
| 355 | sponsors = yaml.safe_load(sponsors_data_path.read_text(encoding="utf-8")) |
| 356 | if not (match_start and match_end): |
| 357 | raise RuntimeError("Couldn't auto-generate sponsors section") |
| 358 | if not match_pre: |
| 359 | raise RuntimeError("Couldn't find pre section (<style>) in index.md") |
| 360 | frontmatter_end = match_pre.end() |
| 361 | pre_end = match_start.end() |
| 362 | post_start = match_end.start() |
| 363 | template = Template(index_sponsors_template) |
| 364 | message = template.render(sponsors=sponsors, sponsor_img_url=sponsor_img_url) |
| 365 | pre_content = content[frontmatter_end:pre_end] |
| 366 | post_content = content[post_start:] |
| 367 | new_content = pre_content + message + post_content |
| 368 | # Remove content between <!-- only-mkdocs --> and <!-- /only-mkdocs --> |
| 369 | new_content = re.sub( |
| 370 | r"<!-- only-mkdocs -->.*?<!-- /only-mkdocs -->", |
| 371 | "", |
| 372 | new_content, |
| 373 | flags=re.DOTALL, |
| 374 | ) |
| 375 | return new_content |
| 376 | |
| 377 | |
| 378 | @app.command() |
no test coverage detected
searching dependent graphs…