File size: 8,601 Bytes
4420fdb | 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 | """Shared chrome for the Article offline clone.
Header, navigation, announcement bar and footer copy are transcribed from
source-observed captures under materials/article/source-assets/evidence/.
"""
from html import escape
from theme import BASE_CSS
ANNOUNCEMENT_LINK = "Labor Day Sale:"
ANNOUNCEMENT_TEXT = "Shop up to 40% off for a limited time."
MAIN_NAV = [
("Labor Day Sale", "/c/shop-sale", True),
("Rooms", "/c/all-rooms", False),
("Products", "/c/all-products", False),
("Outdoor", "/browse/58/outdoor", False),
("Decor", "/browse/48/decor", False),
("Furniture Collections", "/c/collections", False),
("Best Sellers", "/c/best-sellers", False),
("New Arrivals", "/browse/100/new", False),
("Bundles", "/furniture-bundles", False),
("Ideas & Inspiration", "/c/Ideas-and-Inspiration", False),
("Article Pro", "/c/pro", False),
]
FOOTER_COLS = [
("Support", [
("Help Center", "/help-center"),
("Shipping", "/help-center/delivery"),
("Returns", "/help-center/returns"),
("Product Recalls", "/c/recall-information"),
("Contact Us", "/c/contact-us"),
]),
("Discover", [
("Ideas & Inspiration", "/c/Ideas-and-Inspiration"),
("Gift Cards", "/giftcards/buy"),
("Financing", "/financing"),
("About Us", "/aboutus"),
("Reviews", "/reviews"),
]),
("Account", [
("Login/Register", "/login"),
("My Favourites", "/favorites"),
("My Account & Orders", "/account"),
("Stores", "/c/stores"),
]),
("Business", [
("Article Pro", "/c/pro"),
("Contract Grade", "/c/shop-contract-grade"),
("Industries We Serve", "/c/pro-industries"),
]),
]
FOOTER_LEGAL = [
("Terms of Use", "/tou"),
("Privacy Policy", "/privacy"),
("Do Not Sell My Personal Information", "/do-not-sell-my-personal-information"),
("Accessibility", "/accessibility"),
]
_ICON = ('<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" '
'stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">{}</svg>')
ICON_HELP = _ICON.format('<circle cx="12" cy="12" r="9"/><path d="M9.6 9.2a2.5 2.5 0 1 1 3.3 2.4c-.6.2-.9.8-.9 1.4v.5"/><circle cx="12" cy="17" r=".6" fill="currentColor"/>')
ICON_ACCOUNT = _ICON.format('<circle cx="12" cy="8.4" r="3.6"/><path d="M4.8 20a7.2 7.2 0 0 1 14.4 0"/>')
ICON_HEART = _ICON.format('<path d="M12 20s-7.4-4.6-7.4-9.4A4.1 4.1 0 0 1 12 8.2a4.1 4.1 0 0 1 7.4 2.4C19.4 15.4 12 20 12 20z"/>')
ICON_CART = _ICON.format('<path d="M3.5 5h2l2.2 10.2a1.6 1.6 0 0 0 1.6 1.3h7.9a1.6 1.6 0 0 0 1.6-1.2L20.5 8H6"/><circle cx="10" cy="20" r="1.1"/><circle cx="17.5" cy="20" r="1.1"/>')
ICON_SEARCH = _ICON.format('<circle cx="11" cy="11" r="6.4"/><path d="m20 20-3.6-3.6"/>')
def money(cents: int) -> str:
"""Render USD the way the source does: no cents when the amount is whole."""
if cents % 100 == 0:
return f"${cents // 100:,}".replace(",", "")
return f"${cents / 100:,.2f}".replace(",", "")
def _dropdown(label: str) -> str:
"""Source-observed dropdown: a full-bleed masonry panel for the big
categories, a narrow anchored list for the rest."""
import store # imported lazily so layout stays usable without the catalogue
menu = store.mega_menu(label)
if not menu:
return ""
if menu["kind"] == "mega":
cols = "".join(
'<div class="mm-col">'
f'<a class="mm-head" href="{escape(g["head"]["href"])}">'
f'{escape(g["head"]["text"])}</a>'
+ "".join(f'<a class="mm-item" href="{escape(i["href"])}">{escape(i["text"])}</a>'
for i in g["items"])
+ "</div>"
for g in menu["groups"]
)
return f'<div class="dropdown mega"><div class="mm-masonry">{cols}</div></div>'
items = "".join(
f'<a class="mm-item" href="{escape(i["href"])}">{escape(i["text"])}</a>'
for i in menu["items"]
)
return (f'<div class="dropdown list" style="width:{menu["width"]}px">'
f'<div class="mm-list">{items}</div></div>')
def header(cart_count: int = 0) -> str:
nav = ""
for label, href, sale in MAIN_NAV:
panel = _dropdown(label)
kind = "mega-parent" if 'class="dropdown mega"' in panel else "list-parent"
nav += (f'<div class="nav-item {kind}">'
f'<a class="{"sale" if sale else ""}" href="{escape(href)}">{escape(label)}</a>'
f'{panel}</div>')
badge = f'<span class="cart-count">{cart_count}</span>' if cart_count else ""
return f"""<div class="announcement">
<a href="/c/shop-sale">{ANNOUNCEMENT_LINK}</a> {ANNOUNCEMENT_TEXT}
<button class="close" type="button" aria-label="Dismiss">×</button>
</div>
<header class="page-header">
<div class="header-row">
<a class="logo" href="/">ARTICLE<span class="dot">.</span></a>
<form class="search" action="/search" method="get" role="search">
<input type="search" name="q" placeholder="Search products & help ..." aria-label="Search products and help">
<button type="submit" aria-label="Search">{ICON_SEARCH}</button>
</form>
<div class="header-icons">
<span class="region-flag" title="USA ($ USD)" aria-label="USA ($ USD)"></span>
<a href="/help-center" aria-label="Help Center">{ICON_HELP}</a>
<a href="/account" aria-label="My Account">{ICON_ACCOUNT}</a>
<a href="/favorites" aria-label="My Favourites">{ICON_HEART}</a>
<a href="/cart" aria-label="Cart">{ICON_CART}{badge}</a>
</div>
</div>
<nav class="main-nav">{nav}</nav>
</header>"""
def footer() -> str:
cols = "".join(
f'<div><h4>{escape(title)}</h4><ul>'
+ "".join(f'<li><a href="{escape(h)}">{escape(t)}</a></li>' for t, h in links)
+ "</ul></div>"
for title, links in FOOTER_COLS
)
legal = "".join(f'<a href="{escape(h)}">{escape(t)}</a>' for t, h in FOOTER_LEGAL)
return f"""<footer class="site-footer">
<div class="footer-cols">{cols}</div>
<div class="footer-legal">{legal}</div>
</footer>"""
def page(title: str, body: str, cart_count: int = 0,
description: str | None = None, extra_css: str = "") -> str:
meta = (f'<meta name="description" content="{escape(description)}">'
if description else "")
return f"""<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>{escape(title)}</title>
{meta}
<style>{BASE_CSS}{extra_css}</style>
</head>
<body>
{header(cart_count)}
{body}
{footer()}
</body>
</html>"""
CHECKOUT_CSS = """
body { background: var(--grey-ultra-light); }
.checkout-header { background: var(--white); padding: 22px 0; text-align: center; }
.checkout-header .logo { font-family: var(--font-bold); font-size: 25px; letter-spacing: .18em;
color: var(--grey-medium); }
.checkout-header .logo .dot { color: var(--coral); }
.checkout-footer { background: var(--grey-ultra-dark); padding: 44px 40px; margin-top: 40px; }
.checkout-footer .logo { font-family: var(--font-bold); font-size: 34px; letter-spacing: .18em;
color: var(--white); }
.checkout-footer .logo .dot { color: var(--coral); }
"""
def checkout_page(title: str, body: str, description: str | None = None,
extra_css: str = "") -> str:
"""Checkout uses a reduced chrome: announcement bar, centred logo, dark footer."""
meta = (f'<meta name="description" content="{escape(description)}">'
if description else "")
return f"""<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>{escape(title)}</title>
{meta}
<style>{BASE_CSS}{CHECKOUT_CSS}{extra_css}</style>
</head>
<body>
<div class="announcement">
<a href="/c/shop-sale">{ANNOUNCEMENT_LINK}</a> {ANNOUNCEMENT_TEXT}
<button class="close" type="button" aria-label="Dismiss">×</button>
</div>
<header class="checkout-header">
<a class="logo" href="/">ARTICLE<span class="dot">.</span></a>
</header>
{body}
<footer class="checkout-footer">
<a class="logo" href="/">ARTICLE<span class="dot">.</span></a>
</footer>
</body>
</html>"""
def breadcrumb(trail: list[tuple[str, str | None]]) -> str:
parts = []
for label, href in trail:
if href:
parts.append(f'<a href="{escape(href)}">{escape(label)}</a>')
else:
parts.append(escape(label))
return '<div class="breadcrumb">' + '<span>/</span>'.join(parts) + "</div>"
|