Skip to content

Commit

Permalink
fix: badges in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Oct 3, 2024
1 parent 3abdc81 commit ce1f4c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 10 additions & 1 deletion sphinx_ape/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,16 @@ def quickstart_title(self) -> Optional[str]:
readme = self.base_path / "README.md"
if readme.is_file():
readme_text = readme.read_text()
first_line = readme_text.splitlines()[0].strip().lower()
found = False
for line in readme_text.splitlines():
if line.strip().startswith("# "):
first_line = line
found = True
break

if not found:
return None

else:
return None

Expand Down
8 changes: 5 additions & 3 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ def test_userguide_names(self, temp_path, quickstart_name, quickstart_title):

overview.unlink()


@pytest.mark.parametrize("title", ("Overview", "Quickstart"))
def test_quickstart_name_when_readme(self, temp_path, title):
def test_quickstart_title_when_readme(self, temp_path, title):
builder = DocumentationBuilder(mode=BuildMode.LATEST, base_path=temp_path)
builder.init()
readme = builder.base_path / "README.md"
readme.write_text(f"# {title}\n\nthis is a readme")

# Ensure to include random stuff before the title to show it still works.
readme.write_text(f"[![Pypi.org][pypi-badge]][pypi-url]\n\n# {title}\n\nthis is a readme")

quickstart = builder.userguides_path / "quickstart.md"
quickstart.write_text("```{include} ../../README.md\n```")
actual = builder.quickstart_title
Expand Down

0 comments on commit ce1f4c8

Please sign in to comment.