def get_filename_for_visual_context()

in src/wagtail_localize_smartling/utils.py [0:0]


def get_filename_for_visual_context(url: str, max_length: int = 256) -> str:
    """
    Turn the given url into a long sluglike HTML filename, based
    on the hostname and the path
    """
    if not url:
        return url

    _parsed = urlparse(url)

    _hostname = _parsed.hostname or ""
    _path = _parsed.path or ""

    head = "-".join(_hostname.split(".")).rstrip("-").lower()
    tail = "-".join(_path.split("/")).rstrip("-").lower()
    body = f"{head}{tail}"[: max_length - 5]

    return f"{body}.html"