Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions app/routers/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def indie_page(game_id: int = Path(ge=1, le=2_000_000_000), db: Session = Depend
# home view in startng-fe (src/App.tsx, and the About and questions in src/home-copy.ts).
HANGOUT = "hangout" # start.ng's own game has its own card, so it isn't in the community list
HOME_GAMES = 8 # cards the homepage shows before "See all" (HOME_GAMES in src/App.tsx)
HOME_GAMES_LISTED = 200 # games listed by name, A to Z (AZ_GAMES in src/App.tsx)
HOME_ABOUT = [
"start.ng is Nigeria's home for browser games, built by the HNG community. Every game is free to play in your "
"browser with no download, and many are made in Naija: danfo rush hour, jollof catching, Lagos markets and more.",
Expand Down Expand Up @@ -255,13 +254,7 @@ def _visible_games(db: Session) -> list[Game]:


def _home_body(games: list[Game]) -> str:
listed = sorted(games, key=lambda g: _title(g.name).lower())[:HOME_GAMES_LISTED]
total = len(games)
links = "".join(
f'<li><a href="/games/{_esc(g.name)}">{_esc(_title(g.name))}</a> <span>by {_esc(_player_name(g.owner, "A builder"))}</span></li>'
for g in listed
)
az = f'<details class="az-games"><summary>Every game on start.ng, A to Z ({total})</summary><ul>{links}</ul></details>' if games else ""
see_all = f'<div class="see-all"><a class="btn" href="/games">See all {total} games →</a></div>' if total > HOME_GAMES else ""
steps = "".join(f"<li><b>{_esc(t)}</b><span>{text}</span></li>" for t, text in HOW_STEPS)
about = "".join(f"<p>{_esc(p)}</p>" for p in HOME_ABOUT) + '<p><a href="/about">More about start.ng →</a></p>'
Expand All @@ -273,7 +266,7 @@ def _home_body(games: list[Game]) -> str:
'<p class="lead">Games made by builders in the community. Each one lives at its own start.ng address. '
"Pick one and play right in your browser.</p>"
'<div class="actions"><a class="btn" href="#games">Play now</a></div></section>'
f'<section id="games" class="container"><div class="section-head"><div><h2>Games from the community</h2></div></div>{see_all}{az}</section>'
f'<section id="games" class="container"><div class="section-head"><div><h2>Games from the community</h2></div></div>{see_all}</section>'
f'<section id="how" class="container how"><h2>Got a game? Put it on start.ng</h2><ol>{steps}</ol>'
'<div class="how-actions"><a class="btn" href="/docs">Read the docs</a>'
'<a class="btn ghost" href="/docs.md">Docs for your AI (.md)</a></div></section>'
Expand Down
28 changes: 8 additions & 20 deletions tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def test_one_indie_game_as_json_and_in_the_sitemap(env):
assert f"<loc>https://start.ng/creators/{game_id}-moon-garden</loc>" in client.get("/pages/sitemap.xml").text


def test_homepage_text_lists_every_game_a_to_z(env):
def test_homepage_text_has_no_a_to_z_list_of_games(env):
client, *_ = env
add_game(env, "moon-garden")
add_game(env, "lane-dash")
Expand All @@ -192,14 +192,11 @@ def test_homepage_text_lists_every_game_a_to_z(env):
text = res.text
assert not text.startswith("<!doctype") and "<html" not in text # only what goes inside #root
assert "<h1>Good vibes.<br><mark>Good games.</mark></h1>" in text
assert "Every game on start.ng, A to Z (2)" in text
lane, moon = text.index('<a href="/games/lane-dash">Lane Dash</a>'), text.index('<a href="/games/moon-garden">Moon Garden</a>')
assert lane < moon # A to Z
assert "<span>by Ada</span>" in text
assert "A to Z" not in text and "/games/lane-dash" not in text # removed from the homepage; /games and the sitemap list them
assert "See all" not in text # only past the 8 cards the homepage shows


def test_homepage_text_leaves_out_hidden_games_and_the_hangout(env):
def test_homepage_see_all_leaves_out_hidden_games_and_the_hangout(env):
from app.db import get_db
from app.main import app

Expand All @@ -209,24 +206,15 @@ def test_homepage_text_leaves_out_hidden_games_and_the_hangout(env):
db = next(app.dependency_overrides[get_db]())
db.add(Game(name="copy-cat", owner_id=1, repo_url="https://github.com/ada/copy-cat", hidden="reported"))
db.commit()
text = client.get("/pages/home").text
assert "/games/lane-dash" in text
assert "/games/hangout" not in text and "/games/copy-cat" not in text
assert "A to Z (1)" in text
for i in range(8):
add_game(env, f"game-{i}")
assert '<a class="btn" href="/games">See all 9 games →</a>' in client.get("/pages/home").text # lane-dash and 8 more


def test_homepage_text_has_the_about_and_questions_and_escapes_names(env):
from app.db import get_db
from app.main import app
from app.models import User

def test_homepage_text_has_the_about_and_questions(env):
client, *_ = env
db = next(app.dependency_overrides[get_db]())
db.get(User, 1).character = {"name": "Ada <b>Bold</b>"}
db.commit()
add_game(env, "lane-dash")
text = client.get("/pages/home").text
assert "by Ada &lt;b&gt;Bold&lt;/b&gt;" in text and "<b>Bold</b>" not in text
assert "Nigeria&#x27;s home for browser games" in text # escaped like every other text
assert "<summary>Is it free?</summary>" in text
assert '<a class="btn" href="/docs">Read the docs</a>' in text
Expand All @@ -235,7 +223,7 @@ def test_homepage_text_has_the_about_and_questions_and_escapes_names(env):

def test_homepage_with_no_games_and_with_many(env):
client, *_ = env
assert "A to Z" not in client.get("/pages/home").text # nothing to list yet
assert "See all" not in client.get("/pages/home").text # nothing to list yet
for i in range(9):
add_game(env, f"game-{i}")
assert '<a class="btn" href="/games">See all 9 games →</a>' in client.get("/pages/home").text
Expand Down
Loading