File size: 5,492 Bytes
c6af477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Resolve logical asset names to the captured first-party files on disk.

Sitecore serves media under content-hashed filenames. Rather than hard-coding
those hashes across the templates, this module indexes `static/assets/` once at
import and resolves logical names through it. Every path returned points at a
file downloaded from www.insureon.com during the 2026-08-23 capture; nothing is
fetched at runtime.
"""

from __future__ import annotations

from functools import lru_cache
from pathlib import Path

ROOT = Path(__file__).resolve().parent
ASSETS = ROOT / "static" / "assets"

# Preference order matters: SVG first where a vector exists, then PNG.
_PREF = (".svg", ".png", ".webp", ".jpg", ".jpeg", ".gif")


@lru_cache(maxsize=1)
def _index() -> list[tuple[str, str]]:
    """(lowercase relative posix path, url) for every downloaded asset."""
    out: list[tuple[str, str]] = []
    if not ASSETS.is_dir():
        return out
    for p in ASSETS.rglob("*"):
        if p.is_file():
            rel = p.relative_to(ASSETS).as_posix()
            out.append((rel.lower(), f"/static/assets/{rel}"))
    out.sort(key=lambda t: (len(t[0]), t[0]))
    return out


@lru_cache(maxsize=512)
def find(*needles: str, prefer: str = "") -> str:
    """Return the URL of the first asset whose path contains every needle.

    `prefer` biases selection towards paths containing that substring. Returns
    "" when nothing matches so callers can degrade to a text fallback rather
    than emitting a broken image.
    """
    wanted = [n.lower() for n in needles if n]
    hits = [(rel, url) for rel, url in _index() if all(n in rel for n in wanted)]
    if not hits:
        return ""
    if prefer:
        pref = [h for h in hits if prefer.lower() in h[0]]
        if pref:
            hits = pref
    for ext in _PREF:
        for rel, url in hits:
            if rel.endswith(ext):
                return url
    return hits[0][1]


# --- named assets used by the templates --------------------------------------
# The header logo the source actually serves is the Sitecore media copy, not the
# bundled dist one; both were captured, so name the observed one explicitly.
LOGO = find("horizontal/desktop/logo_insureon_royalpurple") or find("insureon-logo")
# The source serves a distinct mobile wordmark and a round white-on-purple call
# button in the mobile header; both were captured.
LOGO_MOBILE = find("horizontal/mobile/logo_insureon_royalpurple_mobile") or LOGO
CALL_ICON = find("icon-circle-whitephone")
MENU_ICON = find("icon_open--menu.")
MENU_CLOSE_ICON = find("icon_close--menu.")
NOT_FOUND_ART = find("illustration_404-error")
# Home-page photography, resolved from the home cell's own captured asset list.
HERO_PHOTO = find("handyman-hero")
EXPERT_PHOTO = find("agent-expert-help")
PROCESS_ILLUSTRATION = find("process-preview-illustration")
OWNER_PHOTO = find("businessowner-coffee")
POLICY_GROUP_PHOTO = find("policy-cards-contractor-cleaning-lawncare-group")
CHECK_ICON = find("icon_check--purple")
NO_COVERAGE_ICON = find("icon_no-coverage--gray")

POLICY_ICONS = {
    "general-liability": find("pricing-showcase/general-liability."),
    "professional-liability": find("pricing-showcase/professional-liability"),
    "workers-compensation": find("pricing-showcase/workers-compensation"),
    "business-owners-policy": find("pricing-showcase/business-owners-policy"),
    "cyber-liability": find("pricing-showcase/cyber-insurance"),
    "errors-omissions": find("pricing-showcase/errors-omissions"),
    "commercial-property": find("policy-icon_commercial-property"),
    "commercial-auto": find("policy-icon_commercial-auto"),
    "umbrella-liability": find("policy-icon_umbrella-excess-liability"),
}

INDUSTRY_ICONS = {
    "Construction": find("industry-showcase/construction"),
    "Retail / E-commerce": find("industry-showcase/retail-ecommerce"),
    "Cleaning": find("industry-showcase/cleaning"),
    "Nonprofits": find("industry-showcase/nonprofit"),
    "IT / Technology": find("industry-showcase/technology"),
    "Healthcare": find("industry-showcase/healthcare"),
    "Installation": find("industry-showcase/installation"),
    "Landscaping": find("industry-showcase/landscaping"),
    "Food & Beverage": find("industry-showcase/food-beverage"),
    "Photo & Video": find("industry-showcase/photo-video"),
}

CARRIER_LOGOS = {
    "The Hartford": find("carrier-logos/the-hartford", prefer="black-and-white"),
    "Liberty Mutual": find("carrier-logos/liberty-mutual", prefer="black-and-white"),
    "Philadelphia Insurance Companies": find("carrier-logos/philadelphia",
                                             prefer="black-and-white"),
    "Acuity": find("carrier-logos/acuity", prefer="black-and-white"),
    "The Hanover Insurance Group": find("carrier-logos/the-hanover",
                                        prefer="black-and-white"),
    "Chubb": find("carrier-logos/chubb", prefer="black-and-white"),
    "Hiscox": find("carrier-logos/hiscox", prefer="black-and-white"),
    "Travelers": find("carrier-logos/travelers", prefer="black-and-white"),
    "Nationwide": find("carrier-logos/nationwide", prefer="black-and-white"),
    "AmTrust": find("carrier-logos/amtrust", prefer="black-and-white"),
    "Guard": find("carrier-logos/guard"),
}


def policy_icon(slug: str) -> str:
    return POLICY_ICONS.get(slug) or ""


def carrier_logo(name: str) -> str:
    return CARRIER_LOGOS.get(name) or ""


def count() -> int:
    return len(_index())