File size: 23,067 Bytes
bee9bbb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | """Shared, source-grounded desktop presentation for the local Coursera clone."""
from __future__ import annotations
from html import escape
STATIC_REVISION = "20260822-controls-v11"
def header(
*, authenticated: bool, search_value: str = "", language: str = "en", minimal: bool = False
) -> str:
"""Render the two-tier desktop navigation without any remote dependency."""
english = language == "en"
if minimal:
home_label = "Coursera home" if english else "Coursera 首页"
return f"""
<header class="wb-header wb-header-minimal">
<div class="wb-shell wb-header-row">
<a class="wb-wordmark" href="/" aria-label="{home_label}">coursera</a>
</div>
</header>
"""
account_controls = (
'<nav class="wb-account-nav" aria-label="学习者账户">'
'<a href="/my-learning">My Learning</a><a class="wb-notification-link" href="/updates" aria-label="Updates"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9M10 21h4"/></svg></a>'
'<details class="wb-profile-menu"><summary aria-label="Learner profile">L</summary><div><a href="/my-learning">My Learning</a><a href="/my-purchases/transactions">Purchases</a><a href="/account-settings">Account settings</a><a href="/updates">Updates</a><form action="/auth/logout" method="post"><button type="submit">Log out</button></form></div></details></nav>'
if authenticated
else '<nav class="wb-account-nav" aria-label="账户">'
'<button type="button" class="wb-login-trigger" data-control-action="open-login" data-login-open>登录</button><a class="wb-join" href="/signup">免费加入</a>'
"</nav>"
)
if english:
account_controls = (
'<nav class="wb-account-nav" aria-label="Learner account">'
'<a href="/my-learning">My Learning</a><a class="wb-notification-link" href="/updates" aria-label="Updates"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9M10 21h4"/></svg></a>'
'<details class="wb-profile-menu"><summary aria-label="Learner profile">L</summary><div><a href="/my-learning">My Learning</a><a href="/my-purchases/transactions">Purchases</a><a href="/account-settings">Account settings</a><a href="/updates">Updates</a><form action="/auth/logout" method="post"><button type="submit">Log out</button></form></div></details></nav>'
if authenticated
else '<nav class="wb-account-nav" aria-label="Account">'
'<button type="button" class="wb-login-trigger" data-control-action="open-login" data-login-open>Log In</button><a class="wb-join" href="/signup">Join for Free</a>'
"</nav>"
)
rendered_search_value = escape(search_value, quote=True)
audience = (
'<a class="wb-audience-current" href="/">For Individuals</a><a href="/business/teams">For Businesses</a><a href="/degrees">For Universities</a><a href="/government">For Governments</a>'
if english
else '<a class="wb-audience-current" href="/">为个人</a><a href="/about/contact">为商务</a><a href="/browse">为大学</a><a href="/about/contact">为政府</a>'
)
explore = "Explore" if english else "探索"
degrees = "Degrees" if english else "学位"
search_label = "Search courses" if english else "搜索课程"
search_placeholder = "What do you want to learn?" if english else "您想学习什么?"
home_label = "Coursera home" if english else "Coursera 首页"
ai_sparkle = (
'<span class="wb-ai-sparkle" aria-hidden="true">✦</span>' if english else ""
)
return f"""
<div class="wb-audience-bar">
<div class="wb-shell">{audience}</div>
</div>
<header class="wb-header">
<div class="wb-shell wb-header-row">
<a class="wb-wordmark" href="/" aria-label="{home_label}">coursera</a>
<a class="wb-explore" href="/browse">{explore}</a>
<a class="wb-degree-link" href="/degrees">{degrees}</a>
<form class="wb-search" action="/search" method="get" role="search">
<label class="wb-sr-only" for="wb-header-search">{search_label}</label>
<input id="wb-header-search" name="query" value="{rendered_search_value}" placeholder="{search_placeholder}" autocomplete="off">
<button type="submit" aria-label="{search_label}"><svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="10.5" cy="10.5" r="6.5"/><path d="m15.5 15.5 5 5"/></svg></button>
</form>
{ai_sparkle}
{account_controls}
</div>
</header>
"""
def footer(*, language: str = "en", variant: str = "default") -> str:
"""Render the local footer and keep every destination inside this clone."""
if variant == "none":
return ""
if language == "en" and variant == "source-auth":
return """
<footer class="wb-footer source-auth-footer">
<div class="wb-shell wb-footer-grid">
<section><h3>Coursera</h3><a href="/about">About</a><a href="/browse">What We Offer</a><a href="/about/leadership">Leadership</a><a href="/career-academy">Careers</a><a href="/browse">Catalog</a><a href="/courseraplus">Coursera Plus</a><a href="/professional-certificates">Professional Certificates</a><a href="/mastertrack">MasterTrack® Certificates</a><a href="/business">For Enterprise</a><a href="/government">For Government</a><a href="/campus">For Campus</a><a href="/partners">Become a Partner</a><a href="/social-impact">Social Impact</a></section>
<section><h3>Community</h3><a href="/my-learning">Learners</a><a href="/partners">Partners</a><a href="/about/contact">Developers</a><a href="/about/contact">Beta Testers</a><a href="/help">Blog</a><a href="/help">The Coursera Podcast</a><a href="/help">Tech Blog</a></section>
<section><h3>More</h3><a href="/about/contact">Press</a><a href="/about/contact">Investors</a><a href="/terms">Terms</a><a href="/privacy">Privacy</a><a href="/help">Learner help center</a><a href="/help">Help</a><a href="/help">Accessibility</a><a href="/about/contact">Contact</a><a href="/articles">Articles</a><a href="/directory">Directory</a><a href="/about/affiliates">Affiliates</a><a href="/terms">Modern Slavery Statement</a><a href="/about/cookies-manage">Cookies Preference Center</a></section>
<section><h3>Mobile App</h3><a href="/browse">iOS and Android app</a></section>
</div>
<div class="wb-shell wb-footer-legal">© 2026 Coursera Inc. All rights reserved.</div>
</footer>
"""
if language == "en" and variant == "source-browse":
return """
<footer class="wb-footer source-browse-footer" aria-label="Coursera Footer">
<div class="wb-shell source-browse-footer-primary">
<section><h2>Skills</h2>
<a href="/search?q=Accounting">Accounting</a><a href="/search?q=Artificial+Intelligence">Artificial Intelligence (AI)</a><a href="/search?q=Cybersecurity">Cybersecurity</a><a href="/search?q=Data+Analytics">Data Analytics</a><a href="/search?q=Digital+Marketing">Digital Marketing</a><a href="/search?q=Human+Resources">Human Resources (HR)</a><a href="/search?q=Microsoft+Excel">Microsoft Excel</a><a href="/search?q=Project+Management">Project Management</a><a href="/search?q=Python">Python</a><a href="/search?q=SQL">SQL</a>
</section>
<section><h2>Professional Certificates</h2>
<a href="/search?q=Google+AI+Certificate">Google AI Certificate</a><a href="/search?q=Google+Cybersecurity+Certificate">Google Cybersecurity Certificate</a><a href="/search?q=Google+Data+Analytics+Certificate">Google Data Analytics Certificate</a><a href="/search?q=Google+IT+Support+Certificate">Google IT Support Certificate</a><a href="/search?q=Google+Project+Management+Certificate">Google Project Management Certificate</a><a href="/search?q=Google+UX+Design+Certificate">Google UX Design Certificate</a><a href="/search?q=IBM+AI+Engineering+Certificate">IBM AI Engineering Certificate</a><a href="/professional-certificates/ibm-ai-product-manager">IBM AI Product Manager Certificate</a><a href="/search?q=IBM+Data+Science+Certificate">IBM Data Science Certificate</a><a href="/search?q=Intuit+Academy+Bookkeeping+Certificate">Intuit Academy Bookkeeping Certificate</a>
</section>
<section><h2>Courses & Specializations</h2>
<a href="/search?q=AI+Essentials+Specialization">AI Essentials Specialization</a><a href="/search?q=AI+For+Business+Specialization">AI For Business Specialization</a><a href="/search?q=AI+For+Everyone+Course">AI For Everyone Course</a><a href="/search?q=AI+in+Healthcare+Specialization">AI in Healthcare Specialization</a><a href="/specializations/deep-learning">Deep Learning Specialization</a><a href="/search?q=Excel+Skills+for+Business+Specialization">Excel Skills for Business Specialization</a><a href="/search?q=Financial+Markets+Course">Financial Markets Course</a><a href="/search?q=Machine+Learning+Specialization">Machine Learning Specialization</a><a href="/search?q=Prompt+Engineering+for+ChatGPT+Course">Prompt Engineering for ChatGPT Course</a><a href="/search?q=Python+for+Everybody+Specialization">Python for Everybody Specialization</a>
</section>
<section><h2>Career Resources</h2>
<a href="/help">Career Aptitude Test</a><a href="/help">CAPM Certification Requirements</a><a href="/help">CompTIA A+ Certification Requirements</a><a href="/help">CompTIA Security+ Certification Requirements</a><a href="/help">Essential IT Certifications</a><a href="/help">High-Income Skills to Learn</a><a href="/help">How to Learn Artificial Intelligence</a><a href="/help">PMP Certification Requirements</a><a href="/help">Popular Cybersecurity Certifications</a><a href="/help">Share your Coursera learning story</a>
</section>
</div>
<div class="wb-shell source-browse-footer-secondary">
<section><h2>Coursera</h2>
<a href="/about/contact">About</a><a href="/browse">What We Offer</a><a href="/about/contact">Leadership</a><a href="/career-academy">Careers</a><a href="/browse">Catalog</a><a href="/courseraplus">Coursera Plus</a><a href="/professional-certificates">Professional Certificates</a><a href="/mastertrack">MasterTrack® Certificates</a><a href="/degrees">Degrees</a><a href="/business/teams">For Enterprise</a><a href="/government">For Government</a><a href="/campus">For Campus</a><a href="/partners">Become a Partner</a><a href="/social-impact">Social Impact</a><a href="/search?q=Free+Courses">Free Courses</a><a href="/browse">Udemy</a>
</section>
<section><h2>Community</h2>
<a href="/my-learning">Learners</a><a href="/partners">Partners</a><a href="/about/contact">Beta Testers</a><a href="/help">Blog</a><a href="/help">The Coursera Podcast</a><a href="/help">Tech Blog</a>
</section>
<section><h2>More</h2>
<a href="/about/contact">Press</a><a href="/about/contact">Investors</a><a href="/terms">Terms</a><a href="/privacy">Privacy</a><a href="/help">Help</a><a href="/help">Accessibility</a><a href="/about/contact">Contact</a><a href="/help">Articles</a><a href="/browse">Directory</a><a href="/about/contact">Affiliates</a><a href="/terms">Modern Slavery Statement</a><a href="/privacy">Cookies Preference Center</a>
</section>
<aside aria-label="Mobile apps and certification">
<img src="/static/deep-learning/app-store.svg" alt="Download on the App Store">
<img src="/static/deep-learning/google-play.png" alt="Get it on Google Play">
<img class="source-b-corp" src="/static/deep-learning/b-corp.png" alt="Certified B Corporation">
</aside>
</div>
<div class="wb-shell wb-footer-legal source-browse-footer-legal">© 2026 Coursera Inc. All rights reserved.</div>
</footer>
"""
if language == "en" and variant == "source-course":
return """
<footer class="wb-footer source-course-footer">
<div class="wb-shell source-course-footer-primary">
<section><h2>Skills</h2></section>
<section><h2>Professional Certificates</h2></section>
<section><h2>Courses & Specializations</h2></section>
<section><h2>Career Resources</h2></section>
</div>
<div class="wb-shell source-course-footer-secondary">
<section><h2>Coursera</h2></section>
<section><h2>Community</h2></section>
<section><h2>More</h2></section>
<aside aria-label="Mobile apps and certification">
<img src="/static/deep-learning/app-store.svg" alt="Download on the App Store">
<img src="/static/deep-learning/google-play.png" alt="Get it on Google Play">
<img class="source-b-corp" src="/static/deep-learning/b-corp.png" alt="Certified B Corporation">
</aside>
</div>
<div class="wb-shell wb-footer-legal source-course-footer-legal">© 2026 Coursera Inc. All rights reserved.</div>
</footer>
"""
if language == "en":
return """
<footer class="wb-footer">
<div class="wb-shell wb-footer-grid">
<section><h2>Coursera</h2><a href="/browse">Courses</a><a href="/about/contact">About</a><a href="/help">Help Center</a></section>
<section><h2>Community</h2><a href="/my-learning">Learners</a><a href="/browse">Partners</a><a href="/about/contact">Businesses</a></section>
<section><h2>More</h2><a href="/account-recovery">Account access</a><a href="/help">Support</a><a href="/about/contact">Contact</a></section>
<section><h2>Learn anywhere</h2><p>Continue your local learning journey on your schedule.</p></section>
</div>
<div class="wb-shell wb-footer-legal">© 2026 Coursera Inc. All rights reserved.<span>Local WebsiteBench offline clone</span></div>
</footer>
"""
return """
<footer class="wb-footer">
<div class="wb-shell wb-footer-grid">
<section><h2>Coursera</h2><a href="/browse">课程目录</a><a href="/about/contact">关于我们</a><a href="/help">帮助中心</a></section>
<section><h2>社区</h2><a href="/my-learning">学习者</a><a href="/browse">合作伙伴</a><a href="/about/contact">企业</a></section>
<section><h2>更多</h2><a href="/account-recovery">账户访问</a><a href="/help">支持</a><a href="/about/contact">联系我们</a></section>
<section><h2>移动端学习</h2><p>随时随地继续本地学习旅程。</p></section>
</div>
<div class="wb-shell wb-footer-legal">© 2026 Coursera Inc. 保留所有权利。<span>本地 WebsiteBench 离线 clone</span></div>
</footer>
"""
def checkout_header(*, authenticated: bool) -> str:
"""Render the observed checkout-only chrome: logo left, learner avatar right."""
avatar = '<a class="source-checkout-avatar" href="/my-learning" aria-label="My Learning">L</a>'
if not authenticated:
avatar = '<a class="source-checkout-avatar" href="/login" aria-label="Log in">?</a>'
return f"""
<header class="source-checkout-header">
<a class="source-checkout-wordmark" href="/" aria-label="Coursera home">coursera</a>
{avatar}
</header>
"""
def page(
*,
title: str,
body: str,
authenticated: bool,
body_class: str = "",
document_title: str | None = None,
search_value: str = "",
checkout_chrome: bool = False,
language: str = "en",
footer_variant: str = "default",
open_login: bool = False,
open_signup: bool = False,
login_next_path: str = "/my-learning",
real_css: str | None = None,
minimal_header: bool = False,
) -> str:
"""Return one complete local HTML document for a desktop clone route.
`real_css` names an owner-authorized real Coursera stylesheet shipped under
/static/coursera/ (e.g. "front-page.css"). It loads before the local
layers so matching classes pick up the source design system while local
rules continue to cover clone-specific classes.
"""
rendered_title = document_title or f"{title} | Coursera"
classes = " ".join(
part
for part in (
"wb-page",
"checkout-page" if checkout_chrome else "",
body_class,
"coursera-real-css" if real_css else "",
)
if part
)
rendered_header = (
checkout_header(authenticated=authenticated)
if checkout_chrome
else header(
authenticated=authenticated,
search_value=search_value,
language=language,
minimal=minimal_header,
)
)
rendered_footer = (
""
if checkout_chrome
else footer(language=language, variant=footer_variant)
)
login_markup = login_dialog(open_on_load=open_login, next_path=login_next_path) if not checkout_chrome else ""
signup_markup = signup_dialog(open_on_load=True) if open_signup and not checkout_chrome else ""
real_markup = (
f'<link rel="stylesheet" href="/static/coursera/{escape(real_css, quote=True)}?v={STATIC_REVISION}">'
if real_css
else ""
)
stylesheets = (
"site.css",
"components.css",
"auth.css",
"checkout.css",
"desktop-base.css",
"desktop-chrome.css",
"catalog-desktop.css",
"course-desktop.css",
"specialization-prototype.css",
"course-detail-prototype.css",
"browse-prototype.css",
"data-science-category.css",
"category-page.css",
"search-page.css",
"home-prototype.css",
"auth-desktop.css",
"learning-desktop.css",
"enrolled-learning.css",
"checkout-desktop.css",
"real-css-complement.css",
)
stylesheet_markup = (
'<link rel="stylesheet" href="/static/coursera/cds-variables.css?v='
f'{STATIC_REVISION}">'
+ '<link rel="stylesheet" href="/static/coursera/fonts.css?v='
f'{STATIC_REVISION}">'
+ real_markup
+ "".join(
f'<link rel="stylesheet" href="/static/{name}?v={STATIC_REVISION}">'
for name in stylesheets
)
)
script_markup = (
f'<script src="/static/public-interactions.js?v={STATIC_REVISION}" defer></script>'
f'<script src="/static/auth-dialog.js?v={STATIC_REVISION}" defer></script>'
f'<script src="/static/assignment.js?v={STATIC_REVISION}" defer></script>'
if not checkout_chrome
else ""
)
return f"""<!doctype html>
<html lang="{escape(language)}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{escape(rendered_title)}</title>{stylesheet_markup}</head>
<body class="{escape(classes)}"><a class="wb-skip-link" href="#main-content">Skip to main content</a>{rendered_header}<main id="main-content">{body}</main>{rendered_footer}{login_markup}{signup_markup}{script_markup}</body></html>"""
def login_dialog(*, open_on_load: bool = False, next_path: str = "/my-learning") -> str:
"""Shared current Coursera login surface; fields stay local and synthetic."""
return f"""
<dialog class="source-login-dialog" role="dialog" data-login-dialog data-open-on-load="{'true' if open_on_load else 'false'}" aria-labelledby="source-login-title">
<div class="source-login-card">
<button type="button" class="source-login-close" data-control-action="close-login" data-login-close aria-label="Close">×</button>
<h2 id="source-login-title" class="source-login-heading">Log in or create account</h2>
<p class="source-login-intro">Learn on your own time from top universities and businesses.</p>
<form class="source-login-form" action="/auth/login" method="post" data-login-form autocomplete="off">
<input type="hidden" name="next" value="{escape(next_path, quote=True)}">
<label>Email <span aria-hidden="true">* ​</span><input type="email" name="email" placeholder="name@email.com" required data-login-email></label>
<p class="source-login-error" data-login-error role="alert" hidden></p>
<button type="submit" class="source-login-continue" data-login-continue>Continue</button>
</form>
<form class="source-local-learner-form" action="/auth/local-learner" method="post">
<input type="hidden" name="next" value="{escape(next_path, quote=True)}">
<button type="submit">Continue with local learner</button>
</form>
<form class="source-local-learner-form" action="/auth/learning-demo" method="post">
<input type="hidden" name="next" value="{escape(next_path, quote=True)}">
<button type="submit">Continue with learning demo</button>
</form>
<div class="source-login-or" aria-hidden="true"><span>or</span></div>
<div class="source-login-providers"><a href="/auth/provider/google">Continue with Google</a><a href="/auth/provider/facebook">Continue with Facebook</a><a href="/auth/provider/apple">Continue with Apple</a></div>
<a class="source-login-org" href="/about/contact">Sign up with your organization</a>
<p class="source-login-terms">By continuing, you agree to Coursera's <a href="/terms">Terms of Use</a> and acknowledge the <a href="/privacy">Privacy Notice</a>. This site is protected by reCAPTCHA and the Google <a href="/privacy">Privacy Policy</a> and <a href="/terms">Terms of Service</a> apply.</p>
<p class="source-login-help">Having trouble? <a href="/help">Learner help</a></p>
<form hidden action="/auth/registration/start" method="post" aria-hidden="true"></form>
</div>
</dialog>"""
def signup_dialog(*, open_on_load: bool = False) -> str:
"""Render registration over the same current homepage background."""
return f"""
<dialog class="source-login-dialog source-signup-dialog" role="dialog" data-signup-dialog data-open-on-load="{'true' if open_on_load else 'false'}" aria-labelledby="source-signup-title">
<div class="source-login-card">
<button type="button" class="source-login-close" data-control-action="close-signup" data-signup-close aria-label="Close">×</button>
<h1 id="source-signup-title">Log in or create an account</h1>
<p class="source-login-intro">Start a new learning journey with local test data.</p>
<form class="auth-form source-signup-form" action="/auth/registration/start" method="post" autocomplete="off">
<label>Full name <span aria-hidden="true">*</span><input type="text" name="full_name" placeholder="Local learner" required></label>
<label>Email <span aria-hidden="true">*</span><input type="email" name="email" placeholder="learner@coursera.test" required></label>
<label>Create a password <span aria-hidden="true">*</span><input type="password" name="password" placeholder="Create a password" required></label>
<button type="submit" class="source-login-continue">Join for Free</button>
</form>
<div class="source-login-providers"><a href="/auth/provider/google">Continue with Google</a><a href="/auth/provider/facebook">Continue with Facebook</a><a href="/auth/provider/apple">Continue with Apple</a></div>
<p class="source-login-terms">Verification guidance: verification guidance stays in the local inbox; no real email is sent. By continuing, you agree to Coursera's <a href="/terms">Terms of Use</a> and acknowledge the <a href="/privacy">Privacy Notice</a>.</p>
<p class="source-login-help">Already have an account? <a href="/login">Log in</a></p>
</div>
</dialog>"""
|