"""Server-rendered HTML for company detail pages (SEO-friendly).""" import os from html import escape SITE_URL = os.environ.get("SITE_URL", "https://amanydv2112-suggest-orgs.hf.space").rstrip("/") SOURCE_LABELS = { "yc": "Y Combinator", "a16z": "a16z", "spc": "South Park Commons", "sequoia": "Sequoia", } def _esc(v) -> str: return escape(str(v)) if v else "" def _truncate(text: str, n: int) -> str: text = (text or "").strip() return text if len(text) <= n else text[: n - 1].rstrip() + "…" def company_path(c: dict) -> str: return f"/company/{c['source']}/{c['slug']}" def company_url(c: dict) -> str: return SITE_URL + company_path(c) # ── section builders (each returns "" when there's nothing to show) ───────── def _pills(c: dict) -> str: parts = [] label = SOURCE_LABELS.get(c.get("source"), c.get("source") or "") parts.append(f'{_esc(label)}') if c.get("batch"): parts.append(f'{_esc(c["batch"])}') if c.get("status"): parts.append(f'{_esc(c["status"])}') for ind in (c.get("industries") or [])[:3]: parts.append(f'{_esc(ind)}') for tag in (c.get("tags") or [])[:4]: parts.append(f'{_esc(tag)}') return "".join(parts) def _socials(c: dict) -> str: s = c.get("_socials") or {} links = [] if c.get("website"): links.append(f'Visit website ↗') for key, label in [("linkedin", "LinkedIn"), ("twitter", "X"), ("github", "GitHub"), ("crunchbase", "Crunchbase")]: if s.get(key): links.append(f'{label} ↗') return f'
{"".join(links)}
' if links else "" def _narrative(c: dict) -> str: rows = [] for label, key in [("Problem", "_problem"), ("Solution", "_solution"), ("Who it's for", "_customer")]: if c.get(key): rows.append(f'
{label}

{_esc(c[key])}

') if not rows and c.get("long_description"): rows.append(f'

{_esc(c["long_description"])}

') return f'

What they do

{"".join(rows)}
' if rows else "" def _timeline(c: dict) -> str: events = [] if c.get("_year_founded"): events.append(("Founded", str(c["_year_founded"]))) if c.get("batch") and c.get("source") == "yc": events.append(("YC batch", str(c["batch"]))) if c.get("acquirer"): events.append(("Acquired", f'by {c["acquirer"]}')) if c.get("status"): events.append(("Status", str(c["status"]))) if c.get("team_size"): events.append(("Team size", f'{c["team_size"]} people')) if c.get("location"): events.append(("Location", str(c["location"]))) if not events: return "" items = "".join( f'
  • {_esc(l)}{_esc(v)}
  • ' for l, v in events ) return f'

    Company timeline

    ' def _founders(c: dict) -> str: founders = c.get("_founders") or [] if not founders: return "" cards = [] for f in founders: avatar = ( f'' if f.get("avatar_url") else '
    ' ) socials = [] if f.get("linkedin"): socials.append(f'LinkedIn') if f.get("twitter"): socials.append(f'X') if f.get("profile_url"): socials.append(f'Profile') social_html = f'
    {" · ".join(socials)}
    ' if socials else "" title = f'
    {_esc(f["title"])}
    ' if f.get("title") else "" bio = f'

    {_esc(f["bio"])}

    ' if f.get("bio") else "" cards.append( f'
    {avatar}
    ' f'
    {_esc(f.get("name"))}
    {title}{bio}{social_html}' f'
    ' ) return f'

    Founders

    {"".join(cards)}
    ' def _jobs(c: dict) -> str: jobs = c.get("_jobs") or [] if not jobs: return "" rows = [] for j in jobs: meta = " · ".join( _esc(x) for x in [j.get("location"), j.get("type"), j.get("salary"), j.get("equity")] if x ) apply = j.get("apply_url") or j.get("url") btn = f'Apply ↗' if apply else "" rows.append( f'
    {_esc(j.get("title"))}
    ' f'{f"
    {meta}
    " if meta else ""}
    {btn}
    ' ) return ( f'

    Open roles {len(jobs)}

    ' f'
    {"".join(rows)}
    ' ) def _similar(similar: list[dict]) -> str: if not similar: return "" cards = [] for s in similar: logo = ( f'' if s.get("logo_url") else '' ) cards.append( f'{logo}' f'
    {_esc(s.get("name"))}
    ' f'
    {_esc(_truncate(s.get("one_liner") or "", 70))}
    ' ) return f'

    Similar startups

    {"".join(cards)}
    ' # ── page shell ─────────────────────────────────────────────────────────────── def render_company_page(company: dict, similar: list[dict], git_rev: str = "1") -> str: c = company name = c.get("name") or "Company" one_liner = c.get("one_liner") or "" source_label = SOURCE_LABELS.get(c.get("source"), c.get("source") or "") desc = _truncate(c.get("_problem") or one_liner or c.get("long_description") or "", 155) tagline = _truncate(one_liner, 60) title = f"{name} — {tagline} | NicheFind" if tagline else f"{name} | NicheFind" canonical = company_url(c) og_image = c.get("logo_url") or f"{SITE_URL}/static/og-image.png" logo = ( f'' if c.get("logo_url") else '' ) body = "".join([ _narrative(c), _founders(c), _jobs(c), _timeline(c), _similar(similar), ]) return f""" {_esc(title)}
    ← Back to search
    {logo}

    {_esc(name)}

    {_esc(one_liner)}

    {_pills(c)}
    {_socials(c)} {body}
    """